Search in sources :

Example 16 with ModelledResource

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

the class DeploymentGeneratorTest method checkBundleInAppContentAndUseContent.

@Test
public void checkBundleInAppContentAndUseContent() throws Exception {
    List<ModelledResource> cmr = new ArrayList<ModelledResource>();
    cmr.add(createModelledResource("test.api", "1.1.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.1.0")));
    cmr.add(createModelledResource("test.api", "1.0.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.0.0")));
    cmr.add(createModelledResource("test.consumer", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,2.0.0)\""), Collections.<String>emptyList()));
    cmr.add(createModelledResource("test.provider", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,1.1.0)\""), Collections.<String>emptyList()));
    // The second time DeploymentGenerator calls the Resolver, it will provide just 
    // test.shared. The resolver will return test.shared _plus_ test.isolated. 
    _resolver.addResult(cmr);
    Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getApplicationContents"), Arrays.asList(mockContent("test.api", "1.1.0"), mockContent("test.consumer", "1.0.0"), mockContent("test.provider", "1.0.0")));
    Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getUseBundles"), Arrays.asList(mockContent("test.api", "1.0.0")));
    app = Skeleton.newMock(AriesApplication.class);
    Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getApplicationMetadata"), appMetadata);
    DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles(appMetadata, Arrays.asList(new ModelledResource[] { cmr.get(0), cmr.get(2), cmr.get(3) }), new ArrayList<Content>());
    Manifest mf = deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
    mf.write(System.out);
    assertTrue(mf.getMainAttributes().getValue("Deployed-Content").contains("test.api;deployed-version=1.1.0"));
    assertTrue(mf.getMainAttributes().getValue("Deployed-Use-Bundle").contains("test.api;deployed-version=1.0.0"));
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) Content(org.apache.aries.application.Content) ArrayList(java.util.ArrayList) AriesApplication(org.apache.aries.application.management.AriesApplication) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Manifest(java.util.jar.Manifest) MethodCall(org.apache.aries.unittest.mocks.MethodCall) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Test(org.junit.Test)

Example 17 with ModelledResource

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

the class DeploymentGeneratorTest method checkBundleInAppContentAndProvisionContent.

@Test
public void checkBundleInAppContentAndProvisionContent() throws Exception {
    List<ModelledResource> cmr = new ArrayList<ModelledResource>();
    cmr.add(createModelledResource("test.api", "1.1.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.1.0")));
    cmr.add(createModelledResource("test.api", "1.0.0", Collections.<String>emptyList(), Arrays.asList("test.api.pack;version=1.0.0")));
    cmr.add(createModelledResource("test.consumer", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,2.0.0)\""), Collections.<String>emptyList()));
    cmr.add(createModelledResource("test.provider", "1.0.0", Arrays.asList("test.api.pack;version=\"[1.0.0,1.1.0)\""), Collections.<String>emptyList()));
    // The second time DeploymentGenerator calls the Resolver, it will provide just 
    // test.shared. The resolver will return test.shared _plus_ test.isolated. 
    _resolver.addResult(cmr);
    Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getApplicationContents"), Arrays.asList(mockContent("test.api", "1.1.0"), mockContent("test.consumer", "1.0.0"), mockContent("test.provider", "1.0.0")));
    app = Skeleton.newMock(AriesApplication.class);
    Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getApplicationMetadata"), appMetadata);
    try {
        DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles(appMetadata, Arrays.asList(new ModelledResource[] { cmr.get(0), cmr.get(2), cmr.get(3) }), new ArrayList<Content>());
        deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
        fail("Expected exception because we can't provision an isolated bundle twice");
    } catch (ResolverException rx) {
    }
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) ResolverException(org.apache.aries.application.management.ResolverException) Content(org.apache.aries.application.Content) ArrayList(java.util.ArrayList) AriesApplication(org.apache.aries.application.management.AriesApplication) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) MethodCall(org.apache.aries.unittest.mocks.MethodCall) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Test(org.junit.Test)

Example 18 with ModelledResource

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

the class DeploymentManifestManagerImpl method pruneFakeBundlesFromResults.

private void pruneFakeBundlesFromResults(Collection<ModelledResource> results, Collection<ModelledResource> fakeResources) {
    _logger.debug(LOG_ENTRY, "pruneFakeBundleFromResults", new Object[] { results });
    List<String> fakeBundles = new ArrayList<String>();
    fakeBundles.add(FAKE_BUNDLE_NAME);
    for (ModelledResource resource : fakeResources) {
        fakeBundles.add(resource.getSymbolicName());
    }
    Iterator<ModelledResource> it = results.iterator();
    while (it.hasNext()) {
        ModelledResource mr = it.next();
        if (fakeBundles.contains(mr.getSymbolicName())) {
            it.remove();
        }
    }
    _logger.debug(LOG_EXIT, "pruneFakeBundleFromResults");
}
Also used : ArrayList(java.util.ArrayList) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Example 19 with ModelledResource

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

the class IsolationTestUtils method prepareSampleBundleV2.

/**
   * Set up the necessary resources for installing version 2 of the org.apache.aries.isolated.sample sample bundle, 
   * which returns the message "hello brave new world" rather than "hello world"
   * 
   * This means setting up a global bundle repository as well as a global OBR repository
   */
public static void prepareSampleBundleV2(BundleContext runtimeCtx, RepositoryGenerator repoGen, RepositoryAdmin repoAdmin, ModellingManager modellingManager) throws Exception {
    BundleRepository repo = new BundleRepository() {

        public int getCost() {
            return 1;
        }

        public BundleSuggestion suggestBundleToUse(DeploymentContent content) {
            if (content.getContentName().equals("org.apache.aries.isolated.sample")) {
                return new BundleSuggestion() {

                    public Bundle install(BundleFramework framework, AriesApplication app) throws BundleException {
                        File f = new File("sample_2.0.0.jar");
                        try {
                            return framework.getIsolatedBundleContext().installBundle(f.toURL().toString());
                        } catch (MalformedURLException mue) {
                            throw new RuntimeException(mue);
                        }
                    }

                    public Version getVersion() {
                        return new Version("2.0.0");
                    }

                    public Set<Content> getImportPackage() {
                        return Collections.emptySet();
                    }

                    public Set<Content> getExportPackage() {
                        return Collections.emptySet();
                    }

                    public int getCost() {
                        return 1;
                    }
                };
            } else {
                return null;
            }
        }
    };
    Hashtable<String, String> props = new Hashtable<String, String>();
    props.put(BundleRepository.REPOSITORY_SCOPE, BundleRepository.GLOBAL_SCOPE);
    runtimeCtx.registerService(BundleRepository.class.getName(), repo, props);
    Attributes attrs = new Attributes();
    attrs.putValue("Bundle-ManifestVersion", "2");
    attrs.putValue("Bundle-Version", "2.0.0");
    attrs.putValue("Bundle-SymbolicName", "org.apache.aries.isolated.sample");
    attrs.putValue("Manifest-Version", "1");
    ModelledResource res = modellingManager.getModelledResource(new File("sample_2.0.0.jar").toURI().toString(), attrs, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
    repoGen.generateRepository("repo.xml", Arrays.asList(res), new FileOutputStream("repo.xml"));
    repoAdmin.addRepository(new File("repo.xml").toURI().toString());
}
Also used : MalformedURLException(java.net.MalformedURLException) Hashtable(java.util.Hashtable) AriesApplication(org.apache.aries.application.management.AriesApplication) Attributes(java.util.jar.Attributes) BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) BundleRepository(org.apache.aries.application.management.spi.repository.BundleRepository) DeploymentContent(org.apache.aries.application.DeploymentContent) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Version(org.osgi.framework.Version) DeploymentContent(org.apache.aries.application.DeploymentContent) Content(org.apache.aries.application.Content) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 20 with ModelledResource

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

the class OBRResolverAdvancedTest method generateOBRRepoXML.

private void generateOBRRepoXML(boolean nullURI, String... bundleFiles) throws Exception {
    Set<ModelledResource> mrs = new HashSet<ModelledResource>();
    FileOutputStream fout = new FileOutputStream("repository.xml");
    RepositoryGenerator repositoryGenerator = context().getService(RepositoryGenerator.class);
    ModelledResourceManager modelledResourceManager = context().getService(ModelledResourceManager.class);
    for (String fileName : bundleFiles) {
        File bundleFile = new File(fileName);
        IDirectory jarDir = FileSystem.getFSRoot(bundleFile);
        String uri = "";
        if (!!!nullURI) {
            uri = bundleFile.toURI().toString();
        }
        if ("delete.jar".equals(fileName)) {
            jarDir = null;
        }
        mrs.add(modelledResourceManager.getModelledResource(uri, jarDir));
    }
    repositoryGenerator.generateRepository("Test repo description", mrs, fout);
    fout.close();
}
Also used : RepositoryGenerator(org.apache.aries.application.management.spi.repository.RepositoryGenerator) FileOutputStream(java.io.FileOutputStream) IDirectory(org.apache.aries.util.filesystem.IDirectory) ModelledResourceManager(org.apache.aries.application.modelling.ModelledResourceManager) File(java.io.File) HashSet(java.util.HashSet) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Aggregations

ModelledResource (org.apache.aries.application.modelling.ModelledResource)41 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)16 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ZipOutputStream (java.util.zip.ZipOutputStream)11 ResolverException (org.apache.aries.application.management.ResolverException)11 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)11 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)10 File (java.io.File)8 Content (org.apache.aries.application.Content)8 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)7 FileOutputStream (java.io.FileOutputStream)6 HashSet (java.util.HashSet)6 MethodCall (org.apache.aries.unittest.mocks.MethodCall)6 Manifest (java.util.jar.Manifest)5 AriesApplication (org.apache.aries.application.management.AriesApplication)5 ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)5 HashMap (java.util.HashMap)4 Attributes (java.util.jar.Attributes)4 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)4