Search in sources :

Example 1 with PackageRequirementMerger

use of org.apache.aries.application.modelling.internal.PackageRequirementMerger in project aries by apache.

the class PackageRequirementMergerTest method testMergeInvalid.

@Test
public void testMergeInvalid() throws Exception {
    Collection<ImportedPackage> reqs = new ArrayList<ImportedPackage>();
    reqs.add(newImportedPackage("a", "[1.0.0,2.0.0]"));
    reqs.add(newImportedPackage("a", "[3.0.0,3.0.0]"));
    reqs.add(newImportedPackage("b", "1.0.0"));
    reqs.add(newImportedPackage("b", "2.0.0"));
    reqs.add(newImportedPackage("c", "[1.0.0,2.0.0)"));
    reqs.add(newImportedPackage("c", "2.0.0"));
    PackageRequirementMerger merger = new PackageRequirementMerger(reqs);
    Assert.assertFalse(merger.isMergeSuccessful());
    try {
        merger.getMergedRequirements();
        Assert.fail("getMergedRequirements should throw IllegalStateException.");
    } catch (IllegalStateException e) {
    }
    Set<String> result = merger.getInvalidRequirements();
    Set<String> expected = new HashSet<String>();
    expected.add("a");
    expected.add("c");
    Assert.assertEquals(expected, result);
}
Also used : ArrayList(java.util.ArrayList) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) PackageRequirementMerger(org.apache.aries.application.modelling.internal.PackageRequirementMerger) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with PackageRequirementMerger

use of org.apache.aries.application.modelling.internal.PackageRequirementMerger in project aries by apache.

the class DeployedBundlesImpl method getExternalPackageRequirements.

/**
   * Get all the requirements of bundles in deployed content that are not satisfied
   * by other bundles in deployed content.
   * @return a collection of package requirements.
   * @throws ResolverException if the requirements could not be resolved.
   */
private Collection<ImportedPackage> getExternalPackageRequirements() throws ResolverException {
    logger.debug(LOG_ENTRY, "getExternalPackageRequirements");
    Collection<ImportedPackage> result = cachedExternalRequirements;
    if (result == null) {
        // Get all the internal requirements.
        Collection<ImportedPackage> requirements = new ArrayList<ImportedPackage>();
        Collection<ExportedPackage> internalExports = new ArrayList<ExportedPackage>();
        for (ModelledResource bundle : deployedContent) {
            requirements.addAll(bundle.getImportedPackages());
            internalExports.addAll(bundle.getExportedPackages());
        }
        // Filter out requirements satisfied by internal capabilities.
        result = new ArrayList<ImportedPackage>();
        for (ImportedPackage req : requirements) {
            boolean satisfied = false;
            for (ExportedPackage export : internalExports) {
                if (req.isSatisfied(export)) {
                    satisfied = true;
                    break;
                }
            }
            //If we didn't find a match then it must come from outside
            if (!satisfied)
                result.add(req);
        }
        PackageRequirementMerger merger = new PackageRequirementMerger(result);
        if (!merger.isMergeSuccessful()) {
            List<String> pkgNames = new ArrayList<String>(merger.getInvalidRequirements());
            StringBuilder buff = new StringBuilder();
            for (String pkgName : merger.getInvalidRequirements()) {
                buff.append(pkgName).append(", ");
            }
            int buffLen = buff.length();
            String pkgString = (buffLen > 0 ? buff.substring(0, buffLen - 2) : "");
            ResolverException re = new ResolverException(MessageUtil.getMessage("INCOMPATIBLE_PACKAGE_VERSION_REQUIREMENTS", new Object[] { assetName, pkgString }));
            re.setUnsatisfiedRequirements(pkgNames);
            logger.debug(LOG_EXIT, "getExternalPackageRequirements", re);
            throw re;
        }
        result = merger.getMergedRequirements();
        cachedExternalRequirements = result;
    }
    logger.debug(LOG_EXIT, "getExternalPackageRequirements", result);
    return result;
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) PackageRequirementMerger(org.apache.aries.application.modelling.internal.PackageRequirementMerger) ModelledResource(org.apache.aries.application.modelling.ModelledResource) ExportedPackage(org.apache.aries.application.modelling.ExportedPackage)

Example 3 with PackageRequirementMerger

use of org.apache.aries.application.modelling.internal.PackageRequirementMerger in project aries by apache.

the class PackageRequirementMergerTest method testMergeValid.

@Test
public void testMergeValid() throws Exception {
    Collection<ImportedPackage> reqs = new ArrayList<ImportedPackage>();
    reqs.add(newImportedPackage("a", "1.0.0"));
    reqs.add(newImportedPackage("a", "2.0.0"));
    reqs.add(newImportedPackage("a", "3.0.0"));
    reqs.add(newImportedPackage("b", "1.0.0"));
    reqs.add(newImportedPackage("b", "2.0.0"));
    reqs.add(newImportedPackage("c", "1.0.0"));
    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", "3.0.0"));
    expected.add(newImportedPackage("b", "2.0.0"));
    expected.add(newImportedPackage("c", "1.0.0"));
    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 4 with PackageRequirementMerger

use of org.apache.aries.application.modelling.internal.PackageRequirementMerger in project aries by apache.

the class PackageRequirementMergerTest method testMergeValidAdditionalAttributes.

@Test
public void testMergeValidAdditionalAttributes() throws Exception {
    Collection<ImportedPackage> reqs = new ArrayList<ImportedPackage>();
    reqs.add(newImportedPackage("a", "1.0.0", "foo=bar"));
    reqs.add(newImportedPackage("a", "2.0.0", "foo=bar"));
    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", "foo=bar"));
    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 5 with PackageRequirementMerger

use of org.apache.aries.application.modelling.internal.PackageRequirementMerger in project aries by apache.

the class PackageRequirementMergerTest method testMergeMandatoryResolution.

@Test
public void testMergeMandatoryResolution() throws Exception {
    Collection<ImportedPackage> reqs = new ArrayList<ImportedPackage>();
    reqs.add(newImportedPackage("a", "1.0.0", true));
    reqs.add(newImportedPackage("a", "2.0.0", false));
    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"));
    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)

Aggregations

ArrayList (java.util.ArrayList)7 ImportedPackage (org.apache.aries.application.modelling.ImportedPackage)7 PackageRequirementMerger (org.apache.aries.application.modelling.internal.PackageRequirementMerger)7 Test (org.junit.Test)6 HashSet (java.util.HashSet)2 ResolverException (org.apache.aries.application.management.ResolverException)1 ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)1 ModelledResource (org.apache.aries.application.modelling.ModelledResource)1