Search in sources :

Example 21 with ResolverException

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

the class DeployedBundlesTest method testGetImportPackage_InvalidBundleVersion.

//Inside cannot bundle-symbolic-name an outside bundle until the new RFC 138!
@Test
public void testGetImportPackage_InvalidBundleVersion() throws Exception {
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.USES, ternary.NONE);
    deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.b;version=\"[1.0.0,1.0.0]\";bundle-symbolic-name=bundle.b;bundle-version=\"[0.0.0,1.0.0)\""), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.b", "1.0.0", new ArrayList<String>(), Arrays.asList("package.b;version=1.0.0")));
    // Check that the bundle version requirement generates an error because it doesn't match the a bundle in use-bundle.
    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 22 with ResolverException

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

the class DeployedBundlesTest method testGetImportPackage_rfc138PreventsBundleVersionWorking.

@Test
public void testGetImportPackage_rfc138PreventsBundleVersionWorking() throws Exception {
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.NONE, ternary.NONE);
    deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.b;version=1.0.0;bundle-version=1.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 outside use-bundle causes an exception.
    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 23 with ResolverException

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

the class DeployedBundlesTest method testGetImportPackage_ValidDuplicates.

@Test
public void testGetImportPackage_ValidDuplicates() throws Exception {
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.CONTENT, ternary.CONTENT);
    deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.d;version=\"[1.0.0,3.0.0)\""), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.b", "1.0.0", Arrays.asList("package.d;version=\"2.0.0\""), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.c", "1.0.0", Arrays.asList("package.d;version=\"1.0.0\""), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.d", "1.0.0", new ArrayList<String>(), Arrays.asList("package.d;version=2.0.1")));
    // Check that package D is not duplicated in Import-Package, and that the version range
    // has been narrowed to the intersection of the original requirements.
    String importPackageEntry = null;
    try {
        importPackageEntry = deployedBundles.getImportPackage();
    } catch (ResolverException e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
    String expectedResult = "package.d;version=\"[2.0.0,3.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 24 with ResolverException

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

the class AriesApplicationManagerImpl method resolve.

public AriesApplication resolve(AriesApplication originalApp, ResolveConstraint... constraints) throws ResolverException {
    AriesApplicationImpl application = new AriesApplicationImpl(originalApp.getApplicationMetadata(), originalApp.getBundleInfo(), _localPlatform);
    Manifest deploymentManifest = deploymentManifestManager.generateDeploymentManifest(originalApp, constraints);
    try {
        application.setDeploymentMetadata(_deploymentMetadataFactory.createDeploymentMetadata(deploymentManifest));
    } catch (IOException ioe) {
        throw new ResolverException(ioe);
    }
    // Store a reference to any modified bundles
    if (originalApp instanceof AriesApplicationImpl) {
        // TODO: are we really passing streams around ?
        application.setModifiedBundles(((AriesApplicationImpl) originalApp).getModifiedBundles());
    }
    return application;
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) BundleManifest(org.apache.aries.util.manifest.BundleManifest)

Example 25 with ResolverException

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

the class OBRAriesResolver method toImportedBundle.

private Collection<ImportedBundle> toImportedBundle(Collection<Content> content) throws ResolverException {
    log.debug(LOG_ENTRY, "toImportedBundle", content);
    List<ImportedBundle> result = new ArrayList<ImportedBundle>();
    for (Content c : content) {
        try {
            result.add(modellingManager.getImportedBundle(c.getContentName(), c.getVersion().toString()));
        } catch (InvalidAttributeException iae) {
            throw new ResolverException(iae);
        }
    }
    log.debug(LOG_EXIT, "toImportedBundle", result);
    return result;
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException) Content(org.apache.aries.application.Content) ArrayList(java.util.ArrayList) ImportedBundle(org.apache.aries.application.modelling.ImportedBundle)

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