Search in sources :

Example 6 with VersionRange

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

the class ManifestHeaderProcessorTest method testVersionRange.

/**
     * Test the version range created correctly
     * @throws Exception
     */
@Test
public void testVersionRange() throws Exception {
    String version1 = "[1.2.3, 4.5.6]";
    String version2 = "(1, 2]";
    String version3 = "[2,4)";
    String version4 = "(1,2)";
    String version5 = "2";
    String version6 = "2.3";
    String version7 = "[1.2.3.q, 2.3.4.p)";
    String version8 = "1.2.2.5";
    String version9 = "a.b.c";
    String version10 = null;
    String version11 = "";
    String version12 = "\"[1.2.3, 4.5.6]\"";
    VersionRange vr = ManifestHeaderProcessor.parseVersionRange(version1);
    assertEquals("The value is wrong", "1.2.3", vr.getMinimumVersion().toString());
    assertFalse("The value is wrong", vr.isMinimumExclusive());
    assertEquals("The value is wrong", "4.5.6", vr.getMaximumVersion().toString());
    assertFalse("The value is wrong", vr.isMaximumExclusive());
    vr = ManifestHeaderProcessor.parseVersionRange(version2);
    assertEquals("The value is wrong", "1.0.0", vr.getMinimumVersion().toString());
    assertTrue("The value is wrong", vr.isMinimumExclusive());
    assertEquals("The value is wrong", "2.0.0", vr.getMaximumVersion().toString());
    assertFalse("The value is wrong", vr.isMaximumExclusive());
    vr = ManifestHeaderProcessor.parseVersionRange(version3);
    assertEquals("The value is wrong", "2.0.0", vr.getMinimumVersion().toString());
    assertFalse("The value is wrong", vr.isMinimumExclusive());
    assertEquals("The value is wrong", "4.0.0", vr.getMaximumVersion().toString());
    assertTrue("The value is wrong", vr.isMaximumExclusive());
    vr = ManifestHeaderProcessor.parseVersionRange(version4);
    assertEquals("The value is wrong", "1.0.0", vr.getMinimumVersion().toString());
    assertTrue("The value is wrong", vr.isMinimumExclusive());
    assertEquals("The value is wrong", "2.0.0", vr.getMaximumVersion().toString());
    assertTrue("The value is wrong", vr.isMaximumExclusive());
    vr = ManifestHeaderProcessor.parseVersionRange(version5);
    assertEquals("The value is wrong", "2.0.0", vr.getMinimumVersion().toString());
    assertFalse("The value is wrong", vr.isMinimumExclusive());
    assertNull("The value is wrong", vr.getMaximumVersion());
    assertFalse("The value is wrong", vr.isMaximumExclusive());
    vr = ManifestHeaderProcessor.parseVersionRange(version6);
    assertEquals("The value is wrong", "2.3.0", vr.getMinimumVersion().toString());
    assertFalse("The value is wrong", vr.isMinimumExclusive());
    assertNull("The value is wrong", vr.getMaximumVersion());
    assertFalse("The value is wrong", vr.isMaximumExclusive());
    vr = ManifestHeaderProcessor.parseVersionRange(version7);
    assertEquals("The value is wrong", "1.2.3.q", vr.getMinimumVersion().toString());
    assertFalse("The value is wrong", vr.isMinimumExclusive());
    assertEquals("The value is wrong", "2.3.4.p", vr.getMaximumVersion().toString());
    assertTrue("The value is wrong", vr.isMaximumExclusive());
    vr = ManifestHeaderProcessor.parseVersionRange(version8);
    assertEquals("The value is wrong", "1.2.2.5", vr.getMinimumVersion().toString());
    assertFalse("The value is wrong", vr.isMinimumExclusive());
    assertNull("The value is wrong", vr.getMaximumVersion());
    assertFalse("The value is wrong", vr.isMaximumExclusive());
    boolean exception = false;
    try {
        vr = ManifestHeaderProcessor.parseVersionRange(version9);
    } catch (Exception e) {
        exception = true;
    }
    assertTrue("The value is wrong", exception);
    boolean exceptionNull = false;
    try {
        vr = ManifestHeaderProcessor.parseVersionRange(version10);
    } catch (Exception e) {
        exceptionNull = true;
    }
    assertTrue("The value is wrong", exceptionNull);
    // empty version should be defaulted to >=0.0.0
    vr = ManifestHeaderProcessor.parseVersionRange(version11);
    assertEquals("The value is wrong", "0.0.0", vr.getMinimumVersion().toString());
    assertFalse("The value is wrong", vr.isMinimumExclusive());
    assertNull("The value is wrong", vr.getMaximumVersion());
    assertFalse("The value is wrong", vr.isMaximumExclusive());
    vr = ManifestHeaderProcessor.parseVersionRange(version12);
    assertEquals("The value is wrong", "1.2.3", vr.getMinimumVersion().toString());
    assertFalse("The value is wrong", vr.isMinimumExclusive());
    assertEquals("The value is wrong", "4.5.6", vr.getMaximumVersion().toString());
    assertFalse("The value is wrong", vr.isMaximumExclusive());
}
Also used : VersionRange(org.apache.aries.util.VersionRange) Test(org.junit.Test)

Example 7 with VersionRange

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

the class ManifestHeaderProcessorTest method testExactVersion.

@Test
public void testExactVersion() throws Exception {
    VersionRange vr;
    try {
        vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 2.0.0]", true);
        fail("should not get here 1");
    } catch (IllegalArgumentException e) {
    // expected
    }
    vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 1.0.0]", true);
    assertTrue(vr.isExactVersion());
    try {
        vr = ManifestHeaderProcessor.parseVersionRange("(1.0.0, 1.0.0]", true);
        fail("should not get here 2");
    } catch (IllegalArgumentException e) {
    // expected
    }
    try {
        vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 1.0.0)", true);
        fail("should not get here 3");
    } catch (IllegalArgumentException e) {
    // expected
    }
    vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 2.0.0]");
    assertFalse(vr.isExactVersion());
    vr = ManifestHeaderProcessor.parseVersionRange("[1.0.0, 1.0.0]");
    assertTrue(vr.isExactVersion());
}
Also used : VersionRange(org.apache.aries.util.VersionRange) Test(org.junit.Test)

Example 8 with VersionRange

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

the class UpdateAppTest method updateApp.

private AriesApplicationContext updateApp(AriesApplicationManager manager, AriesApplication app) throws Exception {
    IsolationTestUtils.prepareSampleBundleV2(bundleContext, context().getService(RepositoryGenerator.class), context().getService(RepositoryAdmin.class), context().getService(ModellingManager.class));
    AriesApplication newApp = manager.resolve(app, new ResolveConstraint() {

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

        public VersionRange getVersionRange() {
            return ManifestHeaderProcessor.parseVersionRange("[2.0.0,2.0.0]", true);
        }
    });
    return manager.update(app, newApp.getDeploymentMetadata());
}
Also used : RepositoryGenerator(org.apache.aries.application.management.spi.repository.RepositoryGenerator) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) ResolveConstraint(org.apache.aries.application.management.ResolveConstraint) ModellingManager(org.apache.aries.application.modelling.ModellingManager) AriesApplication(org.apache.aries.application.management.AriesApplication) VersionRange(org.apache.aries.util.VersionRange)

Example 9 with VersionRange

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

the class OBRAriesResolver method getBundleInfo.

@Override
public BundleInfo getBundleInfo(String bundleSymbolicName, Version bundleVersion) {
    Map<String, String> attribs = new HashMap<String, String>();
    // bundleVersion is an exact version - so ensure right version filter is generated
    VersionRange range = ManifestHeaderProcessor.parseVersionRange(bundleVersion.toString(), true);
    attribs.put(Resource.VERSION, range.toString());
    String filterString = ManifestHeaderProcessor.generateFilter(Resource.SYMBOLIC_NAME, bundleSymbolicName, attribs);
    Resource[] resources;
    try {
        resources = repositoryAdmin.discoverResources(filterString);
        if (resources != null && resources.length > 0) {
            return toBundleInfo(resources[0], false);
        } else {
            return null;
        }
    } catch (InvalidSyntaxException e) {
        log.error("Invalid filter", e);
        return null;
    }
}
Also used : HashMap(java.util.HashMap) ModelledBundleResource(org.apache.aries.application.resolver.obr.ext.ModelledBundleResource) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Resource(org.apache.felix.bundlerepository.Resource) VersionRange(org.apache.aries.util.VersionRange) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException)

Example 10 with VersionRange

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

the class DeploymentGeneratorTest method mockContent.

private Content mockContent(String symbolicName, String version) {
    Content bundle = Skeleton.newMock(Content.class);
    VersionRange vr = new VersionRange(version);
    Skeleton.getSkeleton(bundle).setReturnValue(new MethodCall(Content.class, "getContentName"), symbolicName);
    Skeleton.getSkeleton(bundle).setReturnValue(new MethodCall(Content.class, "getVersion"), vr);
    return bundle;
}
Also used : Content(org.apache.aries.application.Content) VersionRange(org.apache.aries.util.VersionRange) MethodCall(org.apache.aries.unittest.mocks.MethodCall)

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