Search in sources :

Example 1 with ResolverException

use of org.apache.aries.application.management.ResolverException in project aries by apache.

the class DeployedBundlesTest method testGetRequiredUseBundle_Valid.

@Test
public void testGetRequiredUseBundle_Valid() throws Exception {
    // Get a valid set of deployment information.
    DeployedBundles deployedBundles = validDeployedBundles();
    packagesResolve(deployedBundles);
    // Check all the use-bundle entries are required.
    Collection<ModelledResource> requiredUseBundle = null;
    try {
        requiredUseBundle = deployedBundles.getRequiredUseBundle();
    } catch (ResolverException e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
    Assert.assertTrue("RequiredUseBundle=" + requiredUseBundle, requiredUseBundle.size() == 2);
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Test(org.junit.Test)

Example 2 with ResolverException

use of org.apache.aries.application.management.ResolverException in project aries by apache.

the class DeployedBundlesTest method testGetImportPackage_Valid.

@Test
public void testGetImportPackage_Valid() throws Exception {
    // Check the import package entry is correct.
    String importPackageEntry = null;
    try {
        DeployedBundles deployedBundles = validDeployedBundles();
        packagesResolve(deployedBundles);
        importPackageEntry = deployedBundles.getImportPackage();
    } catch (ResolverException e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
    String expectedResult = "package.c;version=\"1.0.0\";bundle-symbolic-name=\"bundle.c\";bundle-version=\"[1.0.0,1.0.0]\"," + "package.d;version=\"1.0.0\";bundle-symbolic-name=\"bundle.d\";bundle-version=\"[1.0.0,1.0.0]\"," + "package.e;version=\"[1.0.0,2.0.0)\"," + "package.g;version=\"0.0.0\"";
    /*
     * String expectedResult = "package.c;bundle-symbolic-name=bundle.c;bundle-version=\"[1.0.0,1.0.0]\""
     
        + ",package.d;version=\"1.0.0\";bundle-symbolic-name=bundle.d;bundle-version=\"[1.0.0,1.0.0]\""
        + ",package.e;version=\"[1.0.0,2.0.0)\""
        + ",package.g";
     */
    Assert.assertTrue("ImportPackage=" + importPackageEntry, isEqual(importPackageEntry, expectedResult));
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Test(org.junit.Test)

Example 3 with ResolverException

use of org.apache.aries.application.management.ResolverException in project aries by apache.

the class DeployedBundlesTest method testGetImportPackage_InvalidDuplicates.

@Test
public void testGetImportPackage_InvalidDuplicates() throws Exception {
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.CONTENT, ternary.NONE);
    deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.c;version=\"[1.0.0,2.0.0)\""), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.b", "1.0.0", Arrays.asList("package.c;version=2.0.0"), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.c", "1.0.0", new ArrayList<String>(), Arrays.asList("package.c;version=2.0.0;was_internal=true")));
    // Check that the incompatible version requirements cannot be resolved.
    String importPackageEntry = null;
    try {
        importPackageEntry = deployedBundles.getImportPackage();
        Assert.fail("Expected exception. ImportPackage=" + importPackageEntry);
    } catch (ResolverException e) {
    // We expect to reach this point if the test passes.
    }
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Test(org.junit.Test)

Example 4 with ResolverException

use of org.apache.aries.application.management.ResolverException in project aries by apache.

the class DeployedBundlesImpl method validateOtherImports.

/**
   * Create entries for the Import-Package header corresponding to the supplied
   * packages, referring to bundles not in Use-Bundle.
   * @param requirements packages for which entries should be created.
   * @return manifest header entries.
   * @throws ResolverException if the imports are invalid.
   */
private void validateOtherImports(Collection<ImportedPackage> requirements) throws ResolverException {
    logger.debug(LOG_ENTRY, "validateOtherImports", requirements);
    for (ImportedPackage req : requirements) {
        String pkgName = req.getPackageName();
        for (String name : req.getAttributes().keySet()) {
            if (Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE.equals(name) || Constants.BUNDLE_VERSION_ATTRIBUTE.equals(name)) {
                ResolverException re = new ResolverException(MessageUtil.getMessage("INVALID_PACKAGE_REQUIREMENT_ATTRIBUTES", new Object[] { assetName, name, pkgName }));
                re.setUnsatisfiedRequirements(Arrays.asList(pkgName));
                logger.debug(LOG_EXIT, "validateOtherImports", re);
                throw re;
            }
        }
    }
    logger.debug(LOG_EXIT, "validateOtherImports");
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage)

Example 5 with ResolverException

use of org.apache.aries.application.management.ResolverException 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)

Aggregations

ResolverException (org.apache.aries.application.management.ResolverException)26 ArrayList (java.util.ArrayList)20 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)17 Test (org.junit.Test)15 ModelledResource (org.apache.aries.application.modelling.ModelledResource)11 Content (org.apache.aries.application.Content)8 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)6 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)5 HashSet (java.util.HashSet)4 ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)4 List (java.util.List)3 ImportedBundle (org.apache.aries.application.modelling.ImportedBundle)3 ImportedPackage (org.apache.aries.application.modelling.ImportedPackage)3 MethodCall (org.apache.aries.unittest.mocks.MethodCall)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 Manifest (java.util.jar.Manifest)2 AriesApplication (org.apache.aries.application.management.AriesApplication)2 ResolveConstraint (org.apache.aries.application.management.ResolveConstraint)2