Search in sources :

Example 1 with VersionRange

use of org.apache.aries.util.VersionRange in project aries by apache.

the class DeploymentContentImplTest method testDeploymentContent003.

@Test
public void testDeploymentContent003() throws Exception {
    DeploymentContentImpl dc = new DeploymentContentImpl("com.travel.reservation.data;deployed-version=2.1.1");
    assertEquals("2.1.1", dc.getAttribute("deployed-version"));
    VersionRange vi = dc.getVersion();
    assertTrue(vi.isExactVersion());
    assertEquals(new Version("2.1.1"), dc.getExactVersion());
    assertEquals("com.travel.reservation.data", dc.getContentName());
    assertEquals("{deployed-version=2.1.1}", dc.getNameValueMap().toString());
}
Also used : Version(org.osgi.framework.Version) VersionRange(org.apache.aries.util.VersionRange) Test(org.junit.Test)

Example 2 with VersionRange

use of org.apache.aries.util.VersionRange in project aries by apache.

the class ModellingHelperImpl method intersectPackage_.

public static ImportedPackage intersectPackage_(ImportedPackage p1, ImportedPackage p2) {
    logger.debug(LOG_ENTRY, "intersectPackage_", new Object[] { p1, p2 });
    ImportedPackage result = null;
    if (p1.getPackageName().equals(p2.getPackageName())) {
        Map<String, String> att1 = new HashMap<String, String>(p1.getAttributes());
        Map<String, String> att2 = new HashMap<String, String>(p2.getAttributes());
        // Get the versions, we remove them so that the remaining attributes can be matched.
        String rangeStr1 = att1.remove(Constants.VERSION_ATTRIBUTE);
        String rangeStr2 = att2.remove(Constants.VERSION_ATTRIBUTE);
        //Also remove the optional directive as we don't care about that either
        att1.remove(OPTIONAL_KEY);
        att2.remove(OPTIONAL_KEY);
        //If identical take either, otherwise null!
        Map<String, String> mergedAttribs = (att1.equals(att2) ? att1 : null);
        if (mergedAttribs == null) {
            // Cannot intersect requirements if attributes are not identical.
            result = null;
        } else {
            boolean isIntersectSuccessful = true;
            if (rangeStr1 != null && rangeStr2 != null) {
                // Both requirements have a version constraint so check for an intersection between them.
                VersionRange range1 = ManifestHeaderProcessor.parseVersionRange(rangeStr1);
                VersionRange range2 = ManifestHeaderProcessor.parseVersionRange(rangeStr2);
                VersionRange intersectRange = range1.intersect(range2);
                if (intersectRange == null) {
                    // No intersection possible.
                    isIntersectSuccessful = false;
                } else {
                    // Use the intersected version range.
                    mergedAttribs.put(Constants.VERSION_ATTRIBUTE, intersectRange.toString());
                }
            } else if (rangeStr1 != null) {
                mergedAttribs.put(Constants.VERSION_ATTRIBUTE, rangeStr1);
            } else if (rangeStr2 != null) {
                mergedAttribs.put(Constants.VERSION_ATTRIBUTE, rangeStr2);
            }
            //If both optional, we are optional, otherwise use the default
            if (p1.isOptional() && p2.isOptional()) {
                mergedAttribs.put(OPTIONAL_KEY, Constants.RESOLUTION_OPTIONAL);
            }
            try {
                result = (isIntersectSuccessful ? new ImportedPackageImpl(p1.getPackageName(), mergedAttribs) : null);
            } catch (InvalidAttributeException iax) {
                logger.error(iax.getMessage());
            }
        }
    }
    logger.debug(LOG_EXIT, "intersectPackage_", result);
    return result;
}
Also used : ImportedPackageImpl(org.apache.aries.application.modelling.impl.ImportedPackageImpl) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException) HashMap(java.util.HashMap) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) VersionRange(org.apache.aries.util.VersionRange)

Example 3 with VersionRange

use of org.apache.aries.util.VersionRange in project aries by apache.

the class OBRAriesResolver method extractConsumableMessageInfo.

/**
   * Turn a requirement into a human readable String for debug.
   * @param filter The filter that is failing
   * @param bundlesFailing For problems with a bundle, the set of bundles that have a problem
   * @return human readable form
   */
private Map<String, String> extractConsumableMessageInfo(Map<String, Set<String>> refinedReqs) {
    log.debug(LOG_ENTRY, "extractConsumableMessageInfo", refinedReqs);
    Map<String, String> unsatisfiedRequirements = new HashMap<String, String>();
    for (Map.Entry<String, Set<String>> filterEntry : refinedReqs.entrySet()) {
        String filter = filterEntry.getKey();
        Set<String> bundlesFailing = filterEntry.getValue();
        log.debug("unable to satisfy the filter , filter = " + filter + "required by " + Arrays.toString(bundlesFailing.toArray()));
        Map<String, String> attrs = ManifestHeaderProcessor.parseFilter(filter);
        Map<String, String> customAttrs = new HashMap<String, String>();
        for (Map.Entry<String, String> e : attrs.entrySet()) {
            if (!SPECIAL_FILTER_ATTRS.contains(e.getKey())) {
                customAttrs.put(e.getKey(), e.getValue());
            }
        }
        StringBuilder msgKey = new StringBuilder();
        List<Object> inserts = new ArrayList<Object>();
        final String type;
        boolean unknownType = false;
        if (attrs.containsKey(ModellingConstants.OBR_PACKAGE)) {
            type = ModellingConstants.OBR_PACKAGE;
            msgKey.append("RESOLVER_UNABLE_TO_RESOLVE_PACKAGE");
            inserts.add(attrs.get(ModellingConstants.OBR_PACKAGE));
        } else if (attrs.containsKey(ModellingConstants.OBR_SYMBOLIC_NAME)) {
            type = ModellingConstants.OBR_SYMBOLIC_NAME;
            msgKey.append("RESOLVER_UNABLE_TO_RESOLVE_BUNDLE");
            inserts.add(attrs.get(ModellingConstants.OBR_SYMBOLIC_NAME));
        } else if (attrs.containsKey(ModellingConstants.OBR_SERVICE)) {
            type = ModellingConstants.OBR_SERVICE;
            msgKey.append("RESOLVER_UNABLE_TO_RESOLVE_SERVICE");
        // No insert for service name as the name must be "*" to match any
        // Service capability
        } else {
            type = ModellingConstants.OBR_UNKNOWN;
            unknownType = true;
            msgKey.append("RESOLVER_UNABLE_TO_RESOLVE_FILTER");
            inserts.add(filter);
        }
        if (bundlesFailing != null && bundlesFailing.size() != 0) {
            msgKey.append("_REQUIRED_BY_BUNDLE");
            if (bundlesFailing.size() == 1)
                // Just take the string
                inserts.add(bundlesFailing.iterator().next());
            else
                // if there's only one
                // of them
                // Add the whole set if there
                inserts.add(bundlesFailing.toString());
        // isn't exactly one
        }
        if (!unknownType && !customAttrs.isEmpty()) {
            msgKey.append("_WITH_ATTRS");
            inserts.add(customAttrs);
        }
        if (!unknownType && attrs.containsKey(Constants.VERSION_ATTRIBUTE)) {
            msgKey.append("_WITH_VERSION");
            VersionRange vr = ManifestHeaderProcessor.parseVersionRange(attrs.get(Constants.VERSION_ATTRIBUTE));
            inserts.add(vr.getMinimumVersion());
            if (!!!vr.isExactVersion()) {
                msgKey.append(vr.isMinimumExclusive() ? "_LOWEX" : "_LOW");
                if (vr.getMaximumVersion() != null) {
                    msgKey.append(vr.isMaximumExclusive() ? "_UPEX" : "_UP");
                    inserts.add(vr.getMaximumVersion());
                }
            }
        }
        String msgKeyStr = msgKey.toString();
        String msg = MessageUtil.getMessage(msgKeyStr, inserts.toArray());
        unsatisfiedRequirements.put(msg, type);
    }
    log.debug(LOG_EXIT, "extractConsumableMessageInfo", unsatisfiedRequirements);
    return unsatisfiedRequirements;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VersionRange(org.apache.aries.util.VersionRange) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with VersionRange

use of org.apache.aries.util.VersionRange in project aries by apache.

the class EquinoxFrameworkUtils method existInExports.

/**
   * check if the value in nvm already exist in the exports
   * @param key
   * @param nvm
   * @param exports
   * @return boolean whether the value in nvm already exist in the exports
   */
private static boolean existInExports(String key, Map<String, String> nvm, final Collection<Content> exports) {
    boolean value = false;
    for (Content nvp : exports) {
        if (nvp.getContentName().trim().equals(key.trim())) {
            // ok key equal.  let's check the version
            // if version is higher, we still want to import, for example javax.transaction;version=1.1
            String vi = nvm.get(Constants.VERSION_ATTRIBUTE);
            String ve = nvp.getNameValueMap().get(Constants.VERSION_ATTRIBUTE);
            if (vi == null || vi.length() == 0) {
                vi = "0.0.0";
            }
            if (ve == null || ve.length() == 0) {
                ve = "0.0.0";
            }
            if (vi.indexOf(",") == -1) {
                if (new Version(vi).compareTo(new Version(ve)) <= 0) {
                    // we got it covered in our exports
                    value = true;
                }
            } else {
                // parse vi into version range.
                VersionRange vri = ManifestHeaderProcessor.parseVersionRange(vi);
                Version minV = vri.getMinimumVersion();
                Version maxV = vri.getMaximumVersion();
                if (minV.compareTo(new Version(ve)) < 0 && maxV.compareTo(new Version(ve)) > 0) {
                    value = true;
                } else if (minV.compareTo(new Version(ve)) == 0 && !!!vri.isMinimumExclusive()) {
                    value = true;
                } else if (maxV.compareTo(new Version(ve)) == 0 && !!!vri.isMaximumExclusive()) {
                    value = true;
                }
            }
        }
    }
    return value;
}
Also used : Version(org.osgi.framework.Version) Content(org.apache.aries.application.Content) VersionRange(org.apache.aries.util.VersionRange)

Example 5 with VersionRange

use of org.apache.aries.util.VersionRange in project aries by apache.

the class IsolatedRuntimeTest method testAppWithGlobalRepositoryBundle.

@Test
@Ignore
public void testAppWithGlobalRepositoryBundle() throws Exception {
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test2.eba")));
    IsolationTestUtils.prepareSampleBundleV2(bundleContext, context().getService(RepositoryGenerator.class), context().getService(RepositoryAdmin.class), context().getService(ModellingManager.class));
    AriesApplication newApp = manager.resolve(app, new ResolveConstraint() {

        @Override
        public String getBundleName() {
            return "org.apache.aries.isolated.sample";
        }

        @Override
        public VersionRange getVersionRange() {
            return ManifestHeaderProcessor.parseVersionRange("[2.0.0,2.0.0]", true);
        }
    });
    AriesApplicationContext ctx = manager.install(newApp);
    ctx.start();
    assertHelloWorldService("org.apache.aries.sample2", "hello brave new world");
    manager.uninstall(ctx);
}
Also used : RepositoryGenerator(org.apache.aries.application.management.spi.repository.RepositoryGenerator) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) ResolveConstraint(org.apache.aries.application.management.ResolveConstraint) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) ModellingManager(org.apache.aries.application.modelling.ModellingManager) VersionRange(org.apache.aries.util.VersionRange) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Aggregations

VersionRange (org.apache.aries.util.VersionRange)16 Test (org.junit.Test)8 Version (org.osgi.framework.Version)6 HashMap (java.util.HashMap)4 Content (org.apache.aries.application.Content)4 InputStream (java.io.InputStream)2 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)2 ApplicationMetadataFactoryImpl (org.apache.aries.application.impl.ApplicationMetadataFactoryImpl)2 AriesApplication (org.apache.aries.application.management.AriesApplication)2 ResolveConstraint (org.apache.aries.application.management.ResolveConstraint)2 RepositoryGenerator (org.apache.aries.application.management.spi.repository.RepositoryGenerator)2 ImportedPackage (org.apache.aries.application.modelling.ImportedPackage)2 ModellingManager (org.apache.aries.application.modelling.ModellingManager)2 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)1