Search in sources :

Example 21 with ImportedPackage

use of org.apache.aries.application.modelling.ImportedPackage in project aries by apache.

the class PackageRequirementMergerTest method testMergeOptionalResolution.

@Test
public void testMergeOptionalResolution() throws Exception {
    Collection<ImportedPackage> reqs = new ArrayList<ImportedPackage>();
    reqs.add(newImportedPackage("a", "1.0.0", true));
    reqs.add(newImportedPackage("a", "2.0.0", true));
    PackageRequirementMerger merger = new PackageRequirementMerger(reqs);
    Assert.assertTrue(merger.isMergeSuccessful());
    Assert.assertTrue(merger.getInvalidRequirements().isEmpty());
    Collection<ImportedPackage> result = merger.getMergedRequirements();
    Collection<ImportedPackage> expected = new ArrayList<ImportedPackage>();
    expected.add(newImportedPackage("a", "2.0.0", true));
    Assert.assertTrue(result.toString(), isEqual(result, expected));
}
Also used : ArrayList(java.util.ArrayList) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) PackageRequirementMerger(org.apache.aries.application.modelling.internal.PackageRequirementMerger) Test(org.junit.Test)

Example 22 with ImportedPackage

use of org.apache.aries.application.modelling.ImportedPackage in project aries by apache.

the class DeployedBundlesImpl method getImportPackage.

/**
   * Get the value corresponding to the Import-Package header in the deployment.mf. 
   * @return a manifest entry, or an empty string if there is no content.
   * @throws ResolverException if the requirements could not be resolved.
   */
public String getImportPackage() throws ResolverException {
    logger.debug(LOG_ENTRY, "getImportPackage");
    String result = cachedImportPackage;
    if (result == null) {
        Collection<ImportedPackage> externalReqs = new ArrayList<ImportedPackage>(getExternalPackageRequirements());
        //Validate that we don't have attributes that will break until RFC138 is used
        validateOtherImports(externalReqs);
        // Find the matching capabilities from bundles in use bundle, and prune
        // matched requirements out of the external requirements collection.
        Map<ImportedPackage, ExportedPackage> useBundlePkgs = new HashMap<ImportedPackage, ExportedPackage>();
        for (Iterator<ImportedPackage> iter = externalReqs.iterator(); iter.hasNext(); ) {
            ImportedPackage req = iter.next();
            ExportedPackage match = getPackageMatch(req, deployedUseBundle);
            if (match != null) {
                useBundlePkgs.put(req, match);
                iter.remove();
            }
        }
        StringBuilder useBundleImports = new StringBuilder();
        for (Map.Entry<ImportedPackage, ExportedPackage> entry : useBundlePkgs.entrySet()) {
            useBundleImports.append(entry.getValue().toDeploymentString());
            ImportedPackage key = entry.getKey();
            if (key.isOptional())
                useBundleImports.append(";" + Constants.RESOLUTION_DIRECTIVE + ":=" + Constants.RESOLUTION_OPTIONAL);
            useBundleImports.append(",");
        }
        result = useBundleImports.toString() + createManifestString(externalReqs);
        if (result.endsWith(","))
            result = result.substring(0, result.length() - 1);
        cachedImportPackage = result;
    }
    logger.debug(LOG_EXIT, "getImportPackage", result);
    return result;
}
Also used : HashMap(java.util.HashMap) ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) ArrayList(java.util.ArrayList) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with ImportedPackage

use of org.apache.aries.application.modelling.ImportedPackage in project aries by apache.

the class ImportedPackageTest method testEqualsForEqualTrivialPackages.

@Test
public void testEqualsForEqualTrivialPackages() throws InvalidAttributeException {
    String packageName = "package.name";
    String version = "1.0.0";
    ImportedPackage package1 = instantiatePackage(packageName, version);
    ImportedPackage package2 = instantiatePackage(packageName, version);
    assertEquals(package1, package2);
}
Also used : ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) Test(org.junit.Test)

Aggregations

ImportedPackage (org.apache.aries.application.modelling.ImportedPackage)23 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)9 PackageRequirementMerger (org.apache.aries.application.modelling.internal.PackageRequirementMerger)7 ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)6 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)3 ResolverException (org.apache.aries.application.management.ResolverException)3 ModelledResource (org.apache.aries.application.modelling.ModelledResource)3 Map (java.util.Map)2 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)2 ImportedBundle (org.apache.aries.application.modelling.ImportedBundle)2 ImportedService (org.apache.aries.application.modelling.ImportedService)2 VersionRange (org.apache.aries.util.VersionRange)2 List (java.util.List)1 Content (org.apache.aries.application.Content)1 PreResolveHook (org.apache.aries.application.management.spi.resolve.PreResolveHook)1 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)1 ExportedService (org.apache.aries.application.modelling.ExportedService)1 ImportedPackageImpl (org.apache.aries.application.modelling.impl.ImportedPackageImpl)1