Package org.apache.ivy.osgi.util

Examples of org.apache.ivy.osgi.util.Version


        handler.startElement("", CapabilityHandler.CAPABILITY, CapabilityHandler.CAPABILITY, atts);
        if (type.equals(BundleInfo.BUNDLE_TYPE)) {
            // nothing to do, already handled with the resource tag
        } else if (type.equals(BundleInfo.PACKAGE_TYPE)) {
            saxCapabilityProperty("package", capability.getName(), handler);
            Version v = capability.getRawVersion();
            if (v != null) {
                saxCapabilityProperty("version", v.toString(), handler);
            }
            Set<String> uses = ((ExportPackage) capability).getUses();
            if (uses != null && !uses.isEmpty()) {
                StringBuffer builder = new StringBuffer();
                for (String use : uses) {
                    if (builder.length() != 0) {
                        builder.append(',');
                    }
                    builder.append(use);
                }
                saxCapabilityProperty("uses", builder.toString(), handler);
            }
        } else if (type.equals(BundleInfo.SERVICE_TYPE)) {
            saxCapabilityProperty("service", capability.getName(), handler);
            Version v = capability.getRawVersion();
            if (v != null) {
                saxCapabilityProperty("version", v.toString(), handler);
            }
        } else {
            // oups
        }
        handler.endElement("", CapabilityHandler.CAPABILITY, CapabilityHandler.CAPABILITY);
View Full Code Here


        return filter.toString();
    }

    private static void appendVersion(StringBuffer filter, VersionRange v) {
        filter.append("(&");
        Version start = v.getStartVersion();
        if (start != null) {
            if (!v.isStartExclusive()) {
                filter.append("(version>=");
                filter.append(start.toString());
                filter.append(')');
            } else {
                filter.append("(!");
                filter.append("(version<=");
                filter.append(start.toString());
                filter.append("))");
            }
        }
        Version end = v.getEndVersion();
        if (end != null) {
            if (!v.isEndExclusive()) {
                filter.append("(version<=");
                filter.append(end.toString());
                filter.append(')');
            } else {
                filter.append("(!");
                filter.append("(version>=");
                filter.append(end.toString());
                filter.append("))");
            }
        }
    }
View Full Code Here

                    .getSingleValue();
        }

        String vBundle = new ManifestHeaderValue(mainAttributes.getValue(BUNDLE_VERSION))
                .getSingleValue();
        Version version;
        try {
            version = versionOf(vBundle);
        } catch (NumberFormatException e) {
            throw new ParseException("The " + BUNDLE_VERSION + " has an incorrect version: "
                    + vBundle + " (" + e.getMessage() + ")", 0);
        }

        BundleInfo bundleInfo = new BundleInfo(symbolicName, version);

        bundleInfo.setDescription(description);

        List<String> environments = new ManifestHeaderValue(
                mainAttributes.getValue(BUNDLE_REQUIRED_EXECUTION_ENVIRONMENT)).getValues();
        bundleInfo.setExecutionEnvironments(environments);

        parseRequirement(bundleInfo, mainAttributes, REQUIRE_BUNDLE, BundleInfo.BUNDLE_TYPE,
            ATTR_BUNDLE_VERSION);
        parseRequirement(bundleInfo, mainAttributes, IMPORT_PACKAGE, BundleInfo.PACKAGE_TYPE,
            ATTR_VERSION);
        parseRequirement(bundleInfo, mainAttributes, IMPORT_SERVICE, BundleInfo.SERVICE_TYPE,
            ATTR_VERSION);

        ManifestHeaderValue exportElements = new ManifestHeaderValue(
                mainAttributes.getValue(EXPORT_PACKAGE));
        for (ManifestHeaderElement exportElement : exportElements.getElements()) {
            String vExport = exportElement.getAttributes().get(ATTR_VERSION);
            Version v = null;
            try {
                v = versionOf(vExport);
            } catch (NumberFormatException e) {
                throw new ParseException("The " + EXPORT_PACKAGE + " has an incorrect version: "
                        + vExport + " (" + e.getMessage() + ")", 0);
            }

            for (String name : exportElement.getValues()) {
                ExportPackage export = new ExportPackage(name, v);
                String uses = exportElement.getDirectives().get(ATTR_USE);
                if (uses != null) {
                    String[] split = uses.trim().split(",");
                    for (int i = 0; i < split.length; i++) {
                        export.addUse(split[i].trim());
                    }
                }
                bundleInfo.addCapability(export);
            }
        }

        parseCapability(bundleInfo, mainAttributes, EXPORT_SERVICE, BundleInfo.SERVICE_TYPE);

        // handle Eclipse specific source attachement
        String eclipseSourceBundle = mainAttributes.getValue(ECLIPSE_SOURCE_BUNDLE);
        if (eclipseSourceBundle != null) {
            bundleInfo.setSource(true);
            ManifestHeaderValue eclipseSourceBundleValue = new ManifestHeaderValue(
                    eclipseSourceBundle);
            ManifestHeaderElement element = eclipseSourceBundleValue.getElements().iterator()
                    .next();
            String symbolicNameTarget = element.getValues().iterator().next();
            bundleInfo.setSymbolicNameTarget(symbolicNameTarget);
            String v = element.getAttributes().get(ATTR_VERSION);
            if (v != null) {
                bundleInfo.setVersionTarget(new Version(v));
            }
        }

        String bundleClasspath = mainAttributes.getValue(BUNDLE_CLASSPATH);
        if (bundleClasspath != null) {
View Full Code Here

    private static void parseCapability(BundleInfo bundleInfo, Attributes mainAttributes,
            String headerName, String type) throws ParseException {
        ManifestHeaderValue elements = new ManifestHeaderValue(mainAttributes.getValue(headerName));
        for (ManifestHeaderElement element : elements.getElements()) {
            String attVersion = element.getAttributes().get(ATTR_VERSION);
            Version version = null;
            try {
                version = versionOf(attVersion);
            } catch (NumberFormatException e) {
                throw new ParseException("The " + headerName + " has an incorrect version: "
                        + attVersion + " (" + e.getMessage() + ")", 0);
View Full Code Here

    private static Version versionOf(String v) throws ParseException {
        if (v == null) {
            return null;
        }
        return new Version(v);
    }
View Full Code Here

                        "Filtering is only supported with the operator '='");
            }
            name = compareFilter.getRightValue();
        } else if ("version".equals(att)) {
            String v = compareFilter.getRightValue();
            Version version;
            try {
                version = new Version(v);
            } catch (ParseException e) {
                throw new ParseException("Ill formed version: " + v, 0);
            }
            Operator operator = compareFilter.getOperator();
            if (not) {
View Full Code Here

    }

    private static ExportPackage getExportPackage(BundleInfo bundleInfo, Capability capability)
            throws ParseException {
        String pkgName = null;
        Version version = null;
        String uses = null;
        for (CapabilityProperty property : capability.getProperties()) {
            String propName = property.getName();
            if ("package".equals(propName)) {
                pkgName = property.getValue();
            } else if ("version".equals(propName)) {
                version = new Version(property.getValue());
            } else if ("uses".equals(propName)) {
                uses = property.getValue();
            } else {
                Message.warn("Unsupported property '" + propName
                        + "' on the 'package' capability of the bundle '"
View Full Code Here

    }

    private static BundleCapability getOSGiService(BundleInfo bundleInfo, Capability capability)
            throws ParseException {
        String name = null;
        Version version = null;

        for (CapabilityProperty property : capability.getProperties()) {
            String propName = property.getName();
            if ("service".equals(propName)) {
                name = property.getValue();
            } else if ("version".equals(propName)) {
                version = new Version(property.getValue());
            } else {
                Message.warn("Unsupported property '" + propName
                        + "' on the 'package' capability of the bundle '"
                        + bundleInfo.getSymbolicName() + "'");
            }
View Full Code Here

                skip();
                return;
            }

            String v = getOptionalAttribute(atts, VERSION, DEFAULT_VERSION);
            Version version;
            try {
                version = new Version(v);
            } catch (ParseException e) {
                log(Message.MSG_ERR, "Incorrect resource version: " + v + ". The resource "
                        + symbolicname + " is then ignored.");
                skip();
                return;
View Full Code Here

public class OsgiLatestStrategy extends ComparatorLatestStrategy {

    final class MridComparator implements Comparator<ModuleRevisionId> {

        public int compare(ModuleRevisionId o1, ModuleRevisionId o2) {
            Version v1;
            Version v2;
            try {
                v1 = new Version(o1.getRevision());
                v2 = new Version(o2.getRevision());
            } catch (ParseException e) {
                throw new RuntimeException("Uncomparable versions:" + o1.getRevision() + " and "
                        + o2.getRevision() + " (" + e.getMessage() + ")");
            }
            try {
View Full Code Here

TOP

Related Classes of org.apache.ivy.osgi.util.Version

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.