use of org.apache.felix.bundlerepository.Resource in project felix by apache.
the class DataModelHelperImpl method toXml.
private static void toXml(XmlWriter w, Repository repository) throws IOException {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmss.SSS");
w.element(RepositoryParser.REPOSITORY).attribute(RepositoryParser.NAME, repository.getName()).attribute(RepositoryParser.LASTMODIFIED, format.format(new Date(repository.getLastModified())));
if (repository instanceof RepositoryImpl) {
Referral[] referrals = ((RepositoryImpl) repository).getReferrals();
for (int i = 0; referrals != null && i < referrals.length; i++) {
w.element(RepositoryParser.REFERRAL).attribute(RepositoryParser.DEPTH, new Integer(referrals[i].getDepth())).attribute(RepositoryParser.URL, referrals[i].getUrl()).end();
}
}
Resource[] resources = repository.getResources();
for (int i = 0; resources != null && i < resources.length; i++) {
toXml(w, resources[i]);
}
w.end();
}
use of org.apache.felix.bundlerepository.Resource in project aries by apache.
the class OBRAriesResolver method getBundleInfo.
@Override
public BundleInfo getBundleInfo(String bundleSymbolicName, Version bundleVersion) {
Map<String, String> attribs = new HashMap<String, String>();
// bundleVersion is an exact version - so ensure right version filter is generated
VersionRange range = ManifestHeaderProcessor.parseVersionRange(bundleVersion.toString(), true);
attribs.put(Resource.VERSION, range.toString());
String filterString = ManifestHeaderProcessor.generateFilter(Resource.SYMBOLIC_NAME, bundleSymbolicName, attribs);
Resource[] resources;
try {
resources = repositoryAdmin.discoverResources(filterString);
if (resources != null && resources.length > 0) {
return toBundleInfo(resources[0], false);
} else {
return null;
}
} catch (InvalidSyntaxException e) {
log.error("Invalid filter", e);
return null;
}
}
use of org.apache.felix.bundlerepository.Resource 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.Resource 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;
}
use of org.apache.felix.bundlerepository.Resource in project aries by apache.
the class OBRAriesResolver method getLocalRepository.
private Repository getLocalRepository(RepositoryAdmin admin) {
Repository localRepository = repositoryAdmin.getLocalRepository();
Resource[] resources = localRepository.getResources();
Resource[] newResources = new Resource[resources.length];
for (int i = 0; i < resources.length; i++) {
newResources[i] = new ResourceWrapper(resources[i]);
}
return repositoryAdmin.getHelper().repository(newResources);
}
Aggregations