use of org.apache.felix.bundlerepository.Resource in project aries by apache.
the class OBRAriesResolver method doResolve.
private Collection<ModelledResource> doResolve(Resolver obrResolver, String appName) throws ResolverException {
log.debug(LOG_ENTRY, "doResolve");
Collection<ModelledResource> toReturn = new ArrayList<ModelledResource>();
if (obrResolver.resolve()) {
List<Resource> requiredResources = retrieveRequiredResources(obrResolver);
if (requiredResources == null) {
log.debug("resolver.getRequiredResources() returned null");
} else {
for (Resource r : requiredResources) {
Map<String, String> attribs = new HashMap<String, String>();
attribs.put(Constants.VERSION_ATTRIBUTE, "[" + r.getVersion() + ',' + r.getVersion() + "]");
ModelledResource modelledResourceForThisMatch = null;
// list of packages available in the target runtime environment. If the resource has no symbolic name, we can ignore it
if (r.getSymbolicName() != null) {
try {
modelledResourceForThisMatch = new ModelledBundleResource(r, modellingManager, modellingHelper);
} catch (InvalidAttributeException iax) {
ResolverException re = new ResolverException("Internal error occurred: " + iax);
log.debug(LOG_EXIT, "doResolve", re);
throw re;
}
toReturn.add(modelledResourceForThisMatch);
}
}
}
log.debug(LOG_EXIT, toReturn);
return toReturn;
} else {
Reason[] reasons = obrResolver.getUnsatisfiedRequirements();
// let's refine the list by removing the indirect unsatisfied bundles that are caused by unsatisfied packages or other bundles
Map<String, Set<String>> refinedReqs = refineUnsatisfiedRequirements(obrResolver, reasons);
StringBuffer reqList = new StringBuffer();
Map<String, String> unsatisfiedRequirements = extractConsumableMessageInfo(refinedReqs);
for (String reason : unsatisfiedRequirements.keySet()) {
reqList.append('\n');
reqList.append(reason);
}
ResolverException re = new ResolverException(MessageUtil.getMessage("RESOLVER_UNABLE_TO_RESOLVE", new Object[] { appName, reqList }));
re.setUnsatisfiedRequirementsAndReasons(unsatisfiedRequirements);
log.debug(LOG_EXIT, "doResolve", re);
throw re;
}
}
use of org.apache.felix.bundlerepository.Resource in project aries by apache.
the class OBRAriesResolver method retrieveRequiredResources.
/**
* Get the list of resources returned by the resolver
* @param resolver OBR resolver
* @return a list of required resources
*/
protected List<Resource> retrieveRequiredResources(Resolver resolver) {
log.debug(LOG_ENTRY, "retrieveRequiredResources", resolver);
Map<String, List<Resource>> resourcesByName = new HashMap<String, List<Resource>>();
for (Resource r : resolver.getRequiredResources()) {
resourcesByName.put(r.getSymbolicName(), mergeResource(resolver, r, resourcesByName.get(r.getSymbolicName())));
}
List<Resource> result = new ArrayList<Resource>();
for (List<Resource> res : resourcesByName.values()) {
result.addAll(res);
}
log.debug(LOG_EXIT, "retrieveRequiredResources", result);
return result;
}
use of org.apache.felix.bundlerepository.Resource in project aries by apache.
the class OBRAriesResolver method mergeResource.
/**
* Get rid of the redundant resources
* @param resolver OBR resolver
* @param r a resource
* @param list similar resources
* @return the list of minimum resources
*/
protected List<Resource> mergeResource(Resolver resolver, Resource r, List<Resource> list) {
log.debug(LOG_ENTRY, "mergeResource", new Object[] { resolver, r, list });
if (list == null) {
log.debug(LOG_EXIT, "mergeResource", Arrays.asList(r));
return Arrays.asList(r);
} else {
List<Resource> result = new ArrayList<Resource>();
for (Resource old : list) {
boolean oldRedundant = satisfiesAll(r, resolver.getReason(old));
boolean newRedundant = satisfiesAll(old, resolver.getReason(r));
if (oldRedundant && newRedundant) {
int comp = old.getVersion().compareTo(r.getVersion());
oldRedundant = comp < 0;
newRedundant = comp >= 0;
}
if (newRedundant) {
log.debug(LOG_EXIT, "mergeResource", list);
return list;
} else if (oldRedundant) {
// do nothing -> so don't add the old resource to the new list
} else {
result.add(old);
}
}
result.add(r);
log.debug(LOG_EXIT, "mergeResource", result);
return result;
}
}
use of org.apache.felix.bundlerepository.Resource in project aries by apache.
the class Aries1608Test method createRepositoryXml.
private URL createRepositoryXml(DataModelHelper helper) throws Exception {
File dir;
String cwd = new File("").getAbsolutePath();
if (cwd.endsWith(File.separator + "target")) {
dir = new File("test-classes/aries1608");
} else {
dir = new File("target/test-classes/aries1608");
}
File jar = new File(dir, "aries1608provider.jar");
assertTrue("The bundle jar does not exist: " + jar.getAbsolutePath(), jar.exists());
Resource resource = helper.createResource(jar.toURI().toURL());
Repository repository = helper.repository(new Resource[] { resource });
File file = new File(dir, "repository.xml");
FileWriter fw = new FileWriter(file);
try {
helper.writeRepository(repository, fw);
return file.toURI().toURL();
} finally {
fw.close();
}
}
use of org.apache.felix.bundlerepository.Resource in project aries by apache.
the class Aries1523Test method createRepositoryXml.
private URL createRepositoryXml(DataModelHelper helper) throws Exception {
File dir;
String cwd = new File("").getAbsolutePath();
if (cwd.endsWith(File.separator + "target")) {
dir = new File("test-classes/aries1523");
} else {
dir = new File("target/test-classes/aries1523");
}
File jar = new File(dir, "aries1523host.jar");
assertTrue("The host jar does not exist: " + jar.getAbsolutePath(), jar.exists());
Resource resource = helper.createResource(jar.toURI().toURL());
Repository repository = helper.repository(new Resource[] { resource });
File file = new File(dir, "repository.xml");
FileWriter fw = new FileWriter(file);
try {
helper.writeRepository(repository, fw);
return file.toURI().toURL();
} finally {
fw.close();
}
}
Aggregations