Search in sources :

Example 21 with Content

use of org.apache.aries.application.Content in project aries by apache.

the class DeploymentMetadataImpl method getContentsAsString.

private String getContentsAsString(Collection<Content> contents) {
    StringBuilder builder = new StringBuilder();
    boolean beginning = true;
    for (Content c : contents) {
        if (!!!beginning) {
            builder.append(",");
        }
        builder.append(c);
        beginning = false;
    }
    return builder.toString();
}
Also used : DeploymentContent(org.apache.aries.application.DeploymentContent) Content(org.apache.aries.application.Content)

Example 22 with Content

use of org.apache.aries.application.Content 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 23 with Content

use of org.apache.aries.application.Content in project aries by apache.

the class AriesApplicationManagerImplTest method testCreateAndConversion.

@Test
public void testCreateAndConversion() throws Exception {
    AriesApplication app = createApplication(CONVERSION_EBA);
    ApplicationMetadata appMeta = app.getApplicationMetadata();
    assertEquals(appMeta.getApplicationName(), "conversion.eba");
    assertEquals(appMeta.getApplicationSymbolicName(), "conversion.eba");
    assertEquals(appMeta.getApplicationVersion(), new Version("0.0"));
    List<Content> appContent = appMeta.getApplicationContents();
    assertEquals(2, appContent.size());
    Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
    Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.0.0]\"");
    assertTrue(appContent.contains(fbw));
    assertTrue(appContent.contains(mbl));
    DeploymentMetadata dm = app.getDeploymentMetadata();
    List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
    assertEquals(2, dcList.size());
    DeploymentContent dc1 = new DeploymentContentImpl("hello.world.jar;deployed-version=1.1.0");
    DeploymentContent dc2 = new DeploymentContentImpl("helloWorld.war;deployed-version=0.0.0");
    DeploymentContent dc3 = new DeploymentContentImpl("a.handy.persistence.library;deployed-version=1.1.0");
    assertTrue(dcList.contains(dc1));
    assertTrue(dcList.contains(dc2));
    dcList = dm.getApplicationProvisionBundles();
    assertEquals(1, dcList.size());
    assertTrue(dcList.contains(dc3));
    assertEquals(2, app.getBundleInfo().size());
    BundleInfo info;
    info = findBundleInfo(app.getBundleInfo(), "hello.world.jar");
    assertNotNull(info);
    assertEquals("HelloWorldJar", info.getHeaders().get(Constants.BUNDLE_NAME));
    info = findBundleInfo(app.getBundleInfo(), "helloWorld.war");
    assertNotNull(info);
    assertEquals("helloWorld.war", info.getHeaders().get(Constants.BUNDLE_NAME));
    assertEquals("/test", info.getHeaders().get("Bundle-ContextPath"));
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) BundleInfo(org.apache.aries.application.management.BundleInfo) SimpleBundleInfo(org.apache.aries.application.utils.management.SimpleBundleInfo) Version(org.osgi.framework.Version) Content(org.apache.aries.application.Content) DeploymentContent(org.apache.aries.application.DeploymentContent) AriesApplication(org.apache.aries.application.management.AriesApplication) ContentImpl(org.apache.aries.application.impl.ContentImpl) DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) DeploymentContent(org.apache.aries.application.DeploymentContent) Test(org.junit.Test)

Example 24 with Content

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

Example 25 with Content

use of org.apache.aries.application.Content in project aries by apache.

the class BundleFrameworkConfigurationFactoryImpl method createBundleFrameworkConfig.

public BundleFrameworkConfiguration createBundleFrameworkConfig(String frameworkId, BundleContext parentCtx, AriesApplication app) {
    BundleFrameworkConfiguration config = null;
    DeploymentMetadata metadata = app.getDeploymentMetadata();
    /**
     * Set up framework config properties
     */
    Properties frameworkConfig = new Properties();
    // Problems occur if the parent framework has osgi.console set because the child framework
    // will also attempt to listen on the same port which will cause port clashs. Setting this
    // to null essentially turns the console off.
    frameworkConfig.put("osgi.console", "none");
    String flowedSystemPackages = EquinoxFrameworkUtils.calculateSystemPackagesToFlow(EquinoxFrameworkUtils.getSystemExtraPkgs(parentCtx), metadata.getImportPackage());
    frameworkConfig.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, flowedSystemPackages);
    /**
     * Set up BundleManifest for the framework bundle
     */
    Properties frameworkBundleManifest = new Properties();
    frameworkBundleManifest.put(Constants.BUNDLE_SYMBOLICNAME, metadata.getApplicationSymbolicName());
    frameworkBundleManifest.put(Constants.BUNDLE_VERSION, metadata.getApplicationVersion().toString());
    /**
     * Set up Import-Package header for framework manifest
     */
    // Extract the import packages and remove anything we already have available in the current framework
    Collection<Content> imports = EquinoxFrameworkUtils.calculateImports(metadata.getImportPackage(), EquinoxFrameworkUtils.getExportPackages(parentCtx));
    if (imports != null && !imports.isEmpty()) {
        StringBuffer buffer = new StringBuffer();
        for (Content i : imports) buffer.append(EquinoxFrameworkUtils.contentToString(i) + ",");
        frameworkBundleManifest.put(Constants.IMPORT_PACKAGE, buffer.substring(0, buffer.length() - 1));
    }
    /**
     * Set up CompositeServiceFilter-Import header for framework manifest
     */
    StringBuilder serviceImportFilter = new StringBuilder();
    String txRegsitryImport = "(" + Constants.OBJECTCLASS + "=" + EquinoxFrameworkConstants.TRANSACTION_REGISTRY_BUNDLE + ")";
    Collection<Filter> deployedServiceImports = metadata.getDeployedServiceImport();
    //if there are more services than the txRegistry import a OR group is required for the Filter
    if (deployedServiceImports.size() > 0) {
        serviceImportFilter.append("(|");
    }
    for (Filter importFilter : metadata.getDeployedServiceImport()) {
        serviceImportFilter.append(importFilter.toString());
    }
    serviceImportFilter.append(txRegsitryImport);
    //close the OR group if needed
    if (deployedServiceImports.size() > 0) {
        serviceImportFilter.append(")");
    }
    frameworkBundleManifest.put(EquinoxFrameworkConstants.COMPOSITE_SERVICE_FILTER_IMPORT, serviceImportFilter.toString());
    config = new BundleFrameworkConfigurationImpl(frameworkId, frameworkConfig, frameworkBundleManifest);
    return config;
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) Filter(org.osgi.framework.Filter) Content(org.apache.aries.application.Content) Properties(java.util.Properties) BundleFrameworkConfiguration(org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration)

Aggregations

Content (org.apache.aries.application.Content)27 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)12 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 ModelledResource (org.apache.aries.application.modelling.ModelledResource)9 AriesApplication (org.apache.aries.application.management.AriesApplication)8 ResolverException (org.apache.aries.application.management.ResolverException)8 Version (org.osgi.framework.Version)8 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)7 HashSet (java.util.HashSet)6 MethodCall (org.apache.aries.unittest.mocks.MethodCall)6 DeploymentContent (org.apache.aries.application.DeploymentContent)5 HashMap (java.util.HashMap)4 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)4 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)4 VersionRange (org.apache.aries.util.VersionRange)4 List (java.util.List)3 Map (java.util.Map)3 Manifest (java.util.jar.Manifest)3 ApplicationMetadataFactoryImpl (org.apache.aries.application.impl.ApplicationMetadataFactoryImpl)3