Search in sources :

Example 11 with VersionRange

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

the class PackageRequirementMergerTest method isEqual.

private static boolean isEqual(Collection<ImportedPackage> reqs1, Collection<ImportedPackage> reqs2) {
    boolean result = true;
    if (reqs1.size() != reqs2.size()) {
        result = false;
    } else {
        for (ImportedPackage r1 : reqs1) {
            boolean foundMatch = false;
            for (ImportedPackage r2 : reqs2) {
                if (!r1.getPackageName().equals(r2.getPackageName())) {
                    continue;
                }
                if (r1.isOptional() != r2.isOptional()) {
                    continue;
                }
                Map<String, String> attribs1 = new HashMap<String, String>(r1.getAttributes());
                Map<String, String> attribs2 = new HashMap<String, String>(r2.getAttributes());
                VersionRange v1 = ManifestHeaderProcessor.parseVersionRange(attribs1.remove(Constants.VERSION_ATTRIBUTE));
                VersionRange v2 = ManifestHeaderProcessor.parseVersionRange(attribs2.remove(Constants.VERSION_ATTRIBUTE));
                if (!v1.equals(v2)) {
                    continue;
                }
                if (!attribs1.equals(attribs2)) {
                    continue;
                }
                foundMatch = true;
                break;
            }
            if (!foundMatch) {
                result = false;
                break;
            }
        }
    }
    return result;
}
Also used : HashMap(java.util.HashMap) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) VersionRange(org.apache.aries.util.VersionRange)

Example 12 with VersionRange

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

the class ManifestProcessorTest method testManifestMetadataWithMultiLineEntries.

/**
   * Check metadata can be extracted from a manifest that uses multiple lines
   * for a single manifest attribute.
   */
@Test
public void testManifestMetadataWithMultiLineEntries() throws Exception {
    ApplicationMetadataFactoryImpl manager = new ApplicationMetadataFactoryImpl();
    InputStream in = getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION2.MF");
    ApplicationMetadata am = manager.parseApplicationMetadata(in);
    assertNotNull(am);
    assertEquals(am.getApplicationName(), appName);
    //"com.travel.reservation.web;version=\"[1.1.0,1.2.0)\",com.travel.reservation.business",
    List<Content> contents = am.getApplicationContents();
    for (Content content : contents) {
        if ("com.travel.reservation.web".equals(content.getContentName())) {
            VersionRange vr = content.getVersion();
            assertEquals(vr.getMinimumVersion(), new Version("1.1.0"));
            assertEquals(vr.getMaximumVersion(), new Version("1.2.0"));
        } else if ("com.travel.reservation.business".equals(content.getContentName())) {
            VersionRange vr = content.getVersion();
            assertEquals(new Version(0, 0, 0), vr.getMinimumVersion());
        } else
            fail("Unexepcted content name " + content.getContentName());
    }
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) Version(org.osgi.framework.Version) InputStream(java.io.InputStream) Content(org.apache.aries.application.Content) VersionRange(org.apache.aries.util.VersionRange) ApplicationMetadataFactoryImpl(org.apache.aries.application.impl.ApplicationMetadataFactoryImpl) Test(org.junit.Test)

Example 13 with VersionRange

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

the class ManifestProcessorTest method testManifestMetadata.

/**
   * Check metadata can be extracted from a simple manifest.
   */
@Test
public void testManifestMetadata() throws Exception {
    ApplicationMetadataFactoryImpl manager = new ApplicationMetadataFactoryImpl();
    InputStream in = getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION.MF");
    ApplicationMetadata am = manager.parseApplicationMetadata(in);
    assertNotNull(am);
    assertEquals(am.getApplicationName(), appName);
    //"com.travel.reservation.web;version=\"[1.1.0,1.2.0)\",com.travel.reservation.business",
    List<Content> contents = am.getApplicationContents();
    for (Content content : contents) {
        if ("com.travel.reservation.web".equals(content.getContentName())) {
            VersionRange vr = content.getVersion();
            assertEquals(vr.getMinimumVersion(), new Version("1.1.0"));
            assertEquals(vr.getMaximumVersion(), new Version("1.2.0"));
        } else if ("com.travel.reservation.business".equals(content.getContentName())) {
            VersionRange vr = content.getVersion();
            assertEquals(new Version(0, 0, 0), vr.getMinimumVersion());
        } else
            fail("Unexepcted content name " + content.getContentName());
    }
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) Version(org.osgi.framework.Version) InputStream(java.io.InputStream) Content(org.apache.aries.application.Content) VersionRange(org.apache.aries.util.VersionRange) ApplicationMetadataFactoryImpl(org.apache.aries.application.impl.ApplicationMetadataFactoryImpl) Test(org.junit.Test)

Example 14 with VersionRange

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

the class DeploymentContentImpl method getVersion.

public VersionRange getVersion() {
    String deployedVersion = _content.getAttribute(AppConstants.DEPLOYMENT_BUNDLE_VERSION);
    VersionRange vr = null;
    if (deployedVersion != null && deployedVersion.length() > 0) {
        vr = ManifestHeaderProcessor.parseVersionRange(deployedVersion, true);
    }
    return vr;
}
Also used : VersionRange(org.apache.aries.util.VersionRange)

Example 15 with VersionRange

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

the class DeploymentContentImplTest method testDeploymentContent001.

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

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