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());
}
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);
}
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");
}
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;
}
Aggregations