use of org.apache.aries.subsystem.util.felix.FelixResourceAdapter in project aries by apache.
the class RepositoryGenerator method resolve.
public List<Resource> resolve(List<Resource> subsystemContent, List<Resource> subsystemResources) throws SubsystemException {
generateOBR();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Attempt to resolve subsystem content {} subsystem resource {}", subsystemContent.toString(), subsystemResources.toString());
}
Resolver obrResolver = this.repositoryAdmin.resolver();
// add subsystem content to the resolver
for (Resource res : subsystemContent) {
// org.apache.felix.bundlerepository.Resource obrRes = findOBRResource(res);
// obrResolver.add(obrRes);
obrResolver.add(new OsgiResourceAdapter(res));
}
// add subsystem resource to the resolver
for (Resource res : subsystemResources) {
// org.apache.felix.bundlerepository.Resource obrRes = findOBRResource(res);
// obrResolver.add(obrRes);
obrResolver.add(new OsgiResourceAdapter(res));
}
// Question: do we need to create the repository.xml for the subsystem and add the repo to RepoAdmin?
List<Resource> resources = new ArrayList<Resource>();
if (obrResolver.resolve()) {
for (org.apache.felix.bundlerepository.Resource res : obrResolver.getRequiredResources()) {
// resources.add(toResource(res));
resources.add(new FelixResourceAdapter(res));
}
// Question: should we handle optional resource differently?
for (org.apache.felix.bundlerepository.Resource res : obrResolver.getOptionalResources()) {
// resources.add(toResource(res));
resources.add(new FelixResourceAdapter(res));
}
} else {
// log the unsatisfied requirement
Reason[] reasons = obrResolver.getUnsatisfiedRequirements();
StringBuilder builder = new StringBuilder("Failed to resolve subsystem").append(System.getProperty("line.separator"));
for (Reason reason : reasons) {
LOGGER.warn("Unable to resolve subsystem content {} subsystem resource {} because of unsatisfied requirement {}", new Object[] { subsystemContent.toString(), subsystemResources.toString(), reason.getRequirement().getName() });
builder.append("resource = ").append(reason.getResource().getSymbolicName()).append(", requirement = ").append(reason.getRequirement().getName()).append(System.getProperty("line.separator"));
}
throw new SubsystemException(builder.toString());
}
return resources;
}
use of org.apache.aries.subsystem.util.felix.FelixResourceAdapter in project aries by apache.
the class RepositoryGenerator method find.
/**
* the format of resource is like bundlesymbolicname;version=1.0.0, for example com.ibm.ws.eba.example.blog.api;version=1.0.0,
*/
@SuppressWarnings({ "rawtypes", "unused" })
public Resource find(String resource) throws SubsystemException {
generateOBR();
Content content = new ContentImpl(resource);
String symbolicName = content.getContentName();
// this version could possibly be a range
String version = content.getVersion().toString();
StringBuilder filterString = new StringBuilder();
filterString.append("(&(name" + "=" + symbolicName + "))");
filterString.append("(version" + "=" + version + "))");
// org.apache.felix.bundlerepository.Resource[] res = this.repositoryAdmin.discoverResources(filterString.toString());
Repository[] repos = this.repositoryAdmin.listRepositories();
org.apache.felix.bundlerepository.Resource res = null;
for (Repository repo : repos) {
org.apache.felix.bundlerepository.Resource[] resources = repo.getResources();
for (int i = 0; i < resources.length; i++) {
if (resources[i].getSymbolicName().equals(symbolicName)) {
if (resources[i].getVersion().compareTo(new Version(version)) == 0) {
res = resources[i];
break;
}
}
}
}
if (res == null) {
// throw new SubsystemException("unable to find the resource " + resource);
return null;
}
Map props = res.getProperties();
Object type = props.get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE);
return new FelixResourceAdapter(res);
}
use of org.apache.aries.subsystem.util.felix.FelixResourceAdapter in project aries by apache.
the class FelixResourceAdapterTest method testGetCapabilitiesWithNullNamespace.
@Test
public void testGetCapabilitiesWithNullNamespace() {
Resource resource = EasyMock.createNiceMock(Resource.class);
Capability capability = EasyMock.createNiceMock(Capability.class);
EasyMock.expect(capability.getName()).andReturn(Capability.PACKAGE);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(Capability.PACKAGE, "org.foo.bar");
EasyMock.expect(capability.getPropertiesAsMap()).andReturn(properties);
Capability[] capabilities = new Capability[] { capability };
EasyMock.expect(resource.getCapabilities()).andReturn(capabilities);
EasyMock.replay(resource);
FelixResourceAdapter adapter = new FelixResourceAdapter(resource);
List<org.osgi.resource.Capability> caps = adapter.getCapabilities(null);
// osgi.identity, osgi.content. osgi.wiring.host, and osgi.wiring.package
assertEquals("Null namespace should return all capabilities", 4, caps.size());
}
use of org.apache.aries.subsystem.util.felix.FelixResourceAdapter in project aries by apache.
the class RepositoryAdminRepository method findProviders.
public Collection<Capability> findProviders(Requirement requirement) {
logger.debug(LOG_ENTRY, "findProviders", requirement);
Collection<Capability> result = Collections.emptyList();
if (IdentityNamespace.IDENTITY_NAMESPACE.equals(requirement.getNamespace())) {
result = new ArrayList<Capability>();
for (org.apache.felix.bundlerepository.Repository r : repositoryAdmin.listRepositories()) {
FelixRepositoryAdapter repository = new FelixRepositoryAdapter(r);
Map<Requirement, Collection<Capability>> map = repository.findProviders(Arrays.asList(requirement));
Collection<Capability> capabilities = map.get(requirement);
if (capabilities != null)
result.addAll(capabilities);
}
return result;
} else {
Resource[] resources = repositoryAdmin.discoverResources(new org.apache.felix.bundlerepository.Requirement[] { new OsgiRequirementAdapter(requirement) });
logger.debug("Found {} resources with capabilities satisfying {}", resources == null ? 0 : resources.length, requirement);
if (resources != null && resources.length != 0) {
result = new ArrayList<Capability>(result.size());
OsgiRequirementAdapter adapter = new OsgiRequirementAdapter(requirement);
for (Resource resource : resources) {
logger.debug("Evaluating resource {}", resource);
for (org.apache.felix.bundlerepository.Capability capability : resource.getCapabilities()) {
logger.debug("Evaluating capability {}", capability);
if (adapter.isSatisfied(capability)) {
logger.debug("Adding capability {}", capability);
result.add(new FelixCapabilityAdapter(capability, new FelixResourceAdapter(resource)));
}
}
}
}
}
logger.debug(LOG_EXIT, "findProviders", result);
return result;
}
Aggregations