Search in sources :

Example 6 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 7 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 8 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)

Example 9 with ResolverException

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

the class DeployedBundlesTest method testGetImportPackage_ValidResolutionAttribute.

@Test
public void testGetImportPackage_ValidResolutionAttribute() 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;resolution:=optional"), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.b", "1.0.0", Arrays.asList("package.c;version=1.0.0"), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.c", "1.0.0", new ArrayList<String>(), Arrays.asList("package.c;version=1.0.0")));
    // Check that the resulting resolution directive is not optional.
    String importPackageEntry = null;
    try {
        importPackageEntry = deployedBundles.getImportPackage();
    } catch (ResolverException e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
    String expectedResult = "package.c;version=1.0.0";
    Assert.assertTrue("ImportPackage=" + importPackageEntry, isEqual(importPackageEntry, expectedResult));
}
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 10 with ResolverException

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

the class DeployedBundlesTest method testGetImportPackage_bundleSymbolicNameOK.

@Test
public void testGetImportPackage_bundleSymbolicNameOK() throws Exception {
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.CONTENT, ternary.NONE);
    deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.b;version=1.0.0;bundle-symbolic-name=bundle.b;bundle-version=\"[1.0.0,2.0.0)\""), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.b", "1.0.0", new ArrayList<String>(), Arrays.asList("package.b;version=2.0.0")));
    // Check that the bundle-symbolic-name attribute for a bundle within deployed-content is ok. 
    String importPackageEntry = null;
    try {
        importPackageEntry = deployedBundles.getImportPackage();
    } catch (ResolverException e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
    // All packages are satisfied internally 
    String expectedResult = "";
    Assert.assertTrue("ImportPackage=" + importPackageEntry, isEqual(importPackageEntry, expectedResult));
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Test(org.junit.Test)

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