Search in sources :

Example 1 with Content

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

the class SimpleBundleInfo method getContentSetFromHeader.

private Set<Content> getContentSetFromHeader(Attributes attributes, String key) {
    String header = _attributes.getValue(key);
    List<String> splitHeader = ManifestHeaderProcessor.split(header, ",");
    HashSet<Content> result = new HashSet<Content>();
    for (String s : splitHeader) {
        Content c = new ContentImpl(s);
        result.add(c);
    }
    return result;
}
Also used : Content(org.apache.aries.application.Content) ContentImpl(org.apache.aries.application.impl.ContentImpl) HashSet(java.util.HashSet)

Example 2 with Content

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

the class ApplicationMetadataImplTest method testMetadataCreation.

@Test
public void testMetadataCreation() throws Exception {
    ApplicationMetadataFactory manager = new ApplicationMetadataFactoryImpl();
    ApplicationMetadata app = manager.parseApplicationMetadata(getClass().getResourceAsStream("/META-INF/APPLICATION4.MF"));
    assertEquals("Travel Reservation", app.getApplicationName());
    assertEquals("com.travel.reservation", app.getApplicationSymbolicName());
    assertEquals(Version.parseVersion("1.2.0"), app.getApplicationVersion());
    List<Content> appContents = app.getApplicationContents();
    assertEquals(2, appContents.size());
    Content appContent1 = new ContentImpl("com.travel.reservation.business");
    Map<String, String> attrs = new HashMap<String, String>();
    attrs.put("version", "\"[1.1.0,1.2.0)\"");
    Content appContent2 = new ContentImpl("com.travel.reservation.web", attrs);
    assertTrue(appContents.contains(appContent2));
    assertTrue(appContents.contains(appContent1));
    List<ServiceDeclaration> importedService = app.getApplicationImportServices();
    assertEquals(2, importedService.size());
    assertTrue(importedService.contains(new ServiceDeclarationImpl("com.travel.flight.api")));
    assertTrue(importedService.contains(new ServiceDeclarationImpl("com.travel.rail.api")));
    List<ServiceDeclaration> exportedService = app.getApplicationExportServices();
    assertTrue(exportedService.contains(new ServiceDeclarationImpl("com.travel.reservation")));
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) HashMap(java.util.HashMap) Content(org.apache.aries.application.Content) ServiceDeclaration(org.apache.aries.application.ServiceDeclaration) ApplicationMetadataFactory(org.apache.aries.application.ApplicationMetadataFactory) ApplicationMetadataFactoryImpl(org.apache.aries.application.impl.ApplicationMetadataFactoryImpl) Test(org.junit.Test)

Example 3 with Content

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

the class OBRResolverAdvancedTest method testDemoApp.

@Test
public void testDemoApp() throws Exception {
    // do not provision against the local runtime
    System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "true");
    generateOBRRepoXML(false, TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + ".jar", USE_BUNDLE_BY_REFERENCE + ".jar");
    RepositoryAdmin repositoryAdmin = context().getService(RepositoryAdmin.class);
    Repository[] repos = repositoryAdmin.listRepositories();
    for (Repository repo : repos) {
        repositoryAdmin.removeRepository(repo.getURI());
    }
    repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("demo.eba")));
    //installing requires a valid url for the bundle in repository.xml.
    app = manager.resolve(app);
    DeploymentMetadata depMeta = app.getDeploymentMetadata();
    List<DeploymentContent> provision = depMeta.getApplicationProvisionBundles();
    Collection<DeploymentContent> useBundles = depMeta.getDeployedUseBundle();
    Collection<Content> importPackages = depMeta.getImportPackage();
    assertEquals(provision.toString(), 2, provision.size());
    assertEquals(useBundles.toString(), 1, useBundles.size());
    assertEquals(importPackages.toString(), 4, importPackages.size());
    List<String> bundleSymbolicNames = new ArrayList<String>();
    for (DeploymentContent dep : provision) {
        bundleSymbolicNames.add(dep.getContentName());
    }
    assertTrue("Bundle " + TRANSITIVE_BUNDLE_BY_REFERENCE + " not found.", bundleSymbolicNames.contains(TRANSITIVE_BUNDLE_BY_REFERENCE));
    assertTrue("Bundle " + TRANSITIVE_BUNDLE_BY_VALUE + " not found.", bundleSymbolicNames.contains(TRANSITIVE_BUNDLE_BY_VALUE));
    bundleSymbolicNames.clear();
    for (DeploymentContent dep : useBundles) {
        bundleSymbolicNames.add(dep.getContentName());
    }
    assertTrue("Bundle " + USE_BUNDLE_BY_REFERENCE + " not found.", bundleSymbolicNames.contains(USE_BUNDLE_BY_REFERENCE));
    Collection<String> packages = new ArrayList<String>();
    Map<String, String> maps = new HashMap<String, String>();
    maps.put("version", "0.0.0");
    maps.put("bundle-symbolic-name", "use.bundle.by.reference");
    maps.put("bundle-version", "[1.0.0,1.0.0]");
    Content useContent = ContentFactory.parseContent("a.b.c", maps);
    assertTrue("Use Bundle not found in import packags", importPackages.contains(useContent));
    for (Content c : importPackages) {
        packages.add(c.getContentName());
    }
    assertTrue("package javax.naming not found", packages.contains("javax.naming"));
    assertTrue("package p.q.r not found", packages.contains("p.q.r"));
    assertTrue("package x.y.z not found", packages.contains("x.y.z"));
    assertTrue("package a.b.c not found", packages.contains("a.b.c"));
    AriesApplicationContext ctx = manager.install(app);
    ctx.start();
    Set<Bundle> bundles = ctx.getApplicationContent();
    assertEquals("Number of bundles provisioned in the app", 5, bundles.size());
    ctx.stop();
    manager.uninstall(ctx);
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) HashMap(java.util.HashMap) Bundle(org.osgi.framework.Bundle) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) ArrayList(java.util.ArrayList) DeploymentContent(org.apache.aries.application.DeploymentContent) Repository(org.apache.felix.bundlerepository.Repository) Content(org.apache.aries.application.Content) DeploymentContent(org.apache.aries.application.DeploymentContent) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) File(java.io.File) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with Content

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

the class AriesApplicationManagerImplTest method testCreate.

@Test
public void testCreate() throws Exception {
    AriesApplication app = createApplication(TEST_EBA);
    ApplicationMetadata appMeta = app.getApplicationMetadata();
    assertEquals(appMeta.getApplicationName(), "Test application");
    assertEquals(appMeta.getApplicationSymbolicName(), "org.apache.aries.application.management.test");
    assertEquals(appMeta.getApplicationVersion(), new Version("1.0"));
    List<Content> appContent = appMeta.getApplicationContents();
    assertEquals(appContent.size(), 2);
    Content fbw = new ContentImpl("foo.bar.widgets;version=1.0.0");
    Content mbl = new ContentImpl("my.business.logic;version=1.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("foo.bar.widgets;deployed-version=1.1.0");
    DeploymentContent dc2 = new DeploymentContentImpl("my.business.logic;deployed-version=1.1.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));
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) 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 5 with Content

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

the class RepositoryDescriptorGenerator method generateRepositoryDescriptor.

public static Document generateRepositoryDescriptor(String name, Set<BundleInfo> bundles) throws ParserConfigurationException {
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    Element root = doc.createElement("repository");
    root.setAttribute("name", name);
    doc.appendChild(root);
    for (BundleInfo info : bundles) {
        Element resource = doc.createElement("resource");
        resource.setAttribute(Resource.VERSION, info.getVersion().toString());
        resource.setAttribute("uri", info.getLocation());
        resource.setAttribute(Resource.SYMBOLIC_NAME, info.getSymbolicName());
        resource.setAttribute(Resource.PRESENTATION_NAME, info.getHeaders().get(Constants.BUNDLE_NAME));
        resource.setAttribute(Resource.ID, info.getSymbolicName() + "/" + info.getVersion());
        root.appendChild(resource);
        addBundleCapability(doc, resource, info);
        for (Content p : info.getExportPackage()) {
            addPackageCapability(doc, resource, info, p);
        }
        for (Content p : info.getImportPackage()) {
            addPackageRequirement(doc, resource, info, p);
        }
        for (Content p : info.getRequireBundle()) {
            addBundleRequirement(doc, resource, info, p);
        }
    }
    return doc;
}
Also used : BundleInfo(org.apache.aries.application.management.BundleInfo) Content(org.apache.aries.application.Content) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

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