Search in sources :

Example 11 with Capability

use of org.apache.felix.bundlerepository.Capability in project aries by apache.

the class FelixCapabilityAdapterTest method testOsgiServiceNamespace.

@Test
public void testOsgiServiceNamespace() {
    Capability cap = EasyMock.createNiceMock(Capability.class);
    EasyMock.expect(cap.getName()).andReturn(Capability.SERVICE);
    EasyMock.replay(cap);
    FelixCapabilityAdapter adapter = new FelixCapabilityAdapter(cap, EasyMock.createNiceMock(org.osgi.resource.Resource.class));
    assertEquals("Wrong namespace", ServiceNamespace.SERVICE_NAMESPACE, adapter.getNamespace());
}
Also used : Capability(org.apache.felix.bundlerepository.Capability) FelixCapabilityAdapter(org.apache.aries.subsystem.util.felix.FelixCapabilityAdapter) Resource(org.apache.felix.bundlerepository.Resource) Test(org.junit.Test)

Example 12 with Capability

use of org.apache.felix.bundlerepository.Capability in project aries by apache.

the class OBRAppManagerTest method testAppWithApplicationManifest.

@Test
public void testAppWithApplicationManifest() throws Exception {
    RepositoryAdmin repositoryAdmin = context().getService(RepositoryAdmin.class);
    repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
    Repository[] repos = repositoryAdmin.listRepositories();
    for (Repository repo : repos) {
        Resource[] resources = repo.getResources();
        for (Resource r : resources) {
            Capability[] cs = r.getCapabilities();
            for (Capability c : cs) {
                System.out.println(c.getName() + " : " + c.getProperties());
            }
        }
    }
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test.eba")));
    app = manager.resolve(app);
    //installing requires a valid url for the bundle in repository.xml.
    AriesApplicationContext ctx = manager.install(app);
    ctx.start();
    HelloWorld hw = context().getService(HelloWorld.class);
    String result = hw.getMessage();
    assertEquals(result, "hello world");
    ctx.stop();
    manager.uninstall(ctx);
}
Also used : RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) Capability(org.apache.felix.bundlerepository.Capability) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) Resource(org.apache.felix.bundlerepository.Resource) AriesApplication(org.apache.aries.application.management.AriesApplication) HelloWorld(org.apache.aries.sample.HelloWorld) Repository(org.apache.felix.bundlerepository.Repository) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) File(java.io.File) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 13 with Capability

use of org.apache.felix.bundlerepository.Capability in project aries by apache.

the class OBRAriesResolver method addPlatformRepositories.

/* A 'platform repository' describes capabilities of the target runtime environment
   * These should be added to the resolver without being listed as coming from a particular 
   * repository or bundle.  
   */
private void addPlatformRepositories(Resolver obrResolver, String appName, PlatformRepository platformRepository) {
    log.debug(LOG_ENTRY, "addPlatformRepositories", new Object[] { obrResolver, appName });
    DataModelHelper helper = repositoryAdmin.getHelper();
    if (platformRepository != null) {
        Collection<URI> uris = platformRepository.getPlatformRepositoryURLs();
        if ((uris != null) && (!uris.isEmpty())) {
            for (URI uri : uris) {
                InputStream is = null;
                try {
                    is = uri.toURL().openStream();
                    Reader repoReader = new InputStreamReader(is);
                    Repository aPlatformRepo = helper.readRepository(repoReader);
                    Resource[] resources = aPlatformRepo.getResources();
                    for (Resource r : resources) {
                        Capability[] caps = r.getCapabilities();
                        for (Capability c : caps) {
                            obrResolver.addGlobalCapability(c);
                        }
                    }
                } catch (Exception e) {
                    // not a big problem
                    log.error(MessageUtil.getMessage("RESOLVER_UNABLE_TO_READ_REPOSITORY_EXCEPTION", new Object[] { appName, uri }));
                } finally {
                    IOUtils.close(is);
                }
            }
        }
    }
    log.debug(LOG_EXIT, "addPlatformRepositories");
}
Also used : PlatformRepository(org.apache.aries.application.management.spi.repository.PlatformRepository) Repository(org.apache.felix.bundlerepository.Repository) InputStreamReader(java.io.InputStreamReader) Capability(org.apache.felix.bundlerepository.Capability) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ModelledBundleResource(org.apache.aries.application.resolver.obr.ext.ModelledBundleResource) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Resource(org.apache.felix.bundlerepository.Resource) DataModelHelper(org.apache.felix.bundlerepository.DataModelHelper) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) URI(java.net.URI) ResolverException(org.apache.aries.application.management.ResolverException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException)

Example 14 with Capability

use of org.apache.felix.bundlerepository.Capability in project aries by apache.

the class OBRAriesResolver method refineUnsatisfiedRequirements.

/**
   * Refine the unsatisfied requirements ready for later human comsumption
   * 
   * @param resolver The resolver to be used to refine the requirements
   * @param reasons The reasons
   * @return A map of the unsatifiedRequirement to the set of bundles that have that requirement unsatisfied (values associated with the keys can be null) 
   */
private Map<String, Set<String>> refineUnsatisfiedRequirements(Resolver resolver, Reason[] reasons) {
    log.debug(LOG_ENTRY, "refineUnsatisfiedRequirements", new Object[] { resolver, Arrays.toString(reasons) });
    Map<Requirement, Set<String>> req_resources = new HashMap<Requirement, Set<String>>();
    // add the reasons to the map, use the requirement as the key, the resources required the requirement as the values
    Set<Resource> resources = new HashSet<Resource>();
    for (Reason reason : reasons) {
        resources.add(reason.getResource());
        Requirement key = reason.getRequirement();
        String value = reason.getResource().getSymbolicName() + "_" + reason.getResource().getVersion().toString();
        Set<String> values = req_resources.get(key);
        if (values == null) {
            values = new HashSet<String>();
        }
        values.add(value);
        req_resources.put(key, values);
    }
    // remove the requirements that can be satisifed by the resources. It is listed because the resources are not satisfied by other requirements.
    // For an instance, the unsatisfied reasons are [package a, required by bundle aa], [package b, required by bundle bb] and [package c, required by bundle cc], 
    // If the bundle aa exports the package a and c. In our error message, we only want to display package a is needed by bundle aa.
    // Go through each requirement and find out whether the requirement can be satisfied by the reasons.
    Set<Capability> caps = new HashSet<Capability>();
    for (Resource res : resources) {
        if ((res != null) && (res.getCapabilities() != null)) {
            List<Capability> capList = Arrays.asList(res.getCapabilities());
            if (capList != null) {
                caps.addAll(capList);
            }
        }
    }
    Iterator<Map.Entry<Requirement, Set<String>>> iterator = req_resources.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<Requirement, Set<String>> entry = iterator.next();
        Requirement req = entry.getKey();
        for (Capability cap : caps) {
            if (req.isSatisfied(cap)) {
                // remove the key from the map
                iterator.remove();
                break;
            }
        }
    }
    //Now the map only contains the necessary missing requirements
    Map<String, Set<String>> result = new HashMap<String, Set<String>>();
    for (Map.Entry<Requirement, Set<String>> req_res : req_resources.entrySet()) {
        result.put(req_res.getKey().getFilter(), req_res.getValue());
    }
    log.debug(LOG_EXIT, "refineUnsatisfiedRequirements", new Object[] { result });
    return result;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Capability(org.apache.felix.bundlerepository.Capability) HashMap(java.util.HashMap) ModelledBundleResource(org.apache.aries.application.resolver.obr.ext.ModelledBundleResource) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Resource(org.apache.felix.bundlerepository.Resource) Reason(org.apache.felix.bundlerepository.Reason) Requirement(org.apache.felix.bundlerepository.Requirement) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

Capability (org.apache.felix.bundlerepository.Capability)14 Resource (org.apache.felix.bundlerepository.Resource)10 Test (org.junit.Test)8 FelixCapabilityAdapter (org.apache.aries.subsystem.util.felix.FelixCapabilityAdapter)6 HashMap (java.util.HashMap)5 Requirement (org.apache.felix.bundlerepository.Requirement)5 Map (java.util.Map)3 ModelledResource (org.apache.aries.application.modelling.ModelledResource)2 ModelledBundleResource (org.apache.aries.application.resolver.obr.ext.ModelledBundleResource)2 Reason (org.apache.felix.bundlerepository.Reason)2 Repository (org.apache.felix.bundlerepository.Repository)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1