use of org.apache.felix.bundlerepository.Resource in project felix by apache.
the class RepositoryAdminImpl method discoverResources.
public synchronized Resource[] discoverResources(Requirement[] requirements) {
initialize();
Resource[] resources = null;
Repository[] repos = listRepositories();
List matchList = new ArrayList();
for (int repoIdx = 0; (repos != null) && (repoIdx < repos.length); repoIdx++) {
resources = repos[repoIdx].getResources();
for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
boolean match = true;
for (int reqIdx = 0; (requirements != null) && (reqIdx < requirements.length); reqIdx++) {
boolean reqMatch = false;
Capability[] caps = resources[resIdx].getCapabilities();
for (int capIdx = 0; (caps != null) && (capIdx < caps.length); capIdx++) {
if (requirements[reqIdx].isSatisfied(caps[capIdx])) {
reqMatch = true;
break;
}
}
match &= reqMatch;
if (!match) {
break;
}
}
if (match) {
matchList.add(resources[resIdx]);
}
}
}
// Convert matching resources to an array an sort them by name.
resources = (Resource[]) matchList.toArray(new Resource[matchList.size()]);
Arrays.sort(resources, m_nameComparator);
return resources;
}
use of org.apache.felix.bundlerepository.Resource in project felix by apache.
the class RepositoryAdminImpl method discoverResources.
public synchronized Resource[] discoverResources(String filterExpr) throws InvalidSyntaxException {
initialize();
Filter filter = filterExpr != null ? m_helper.filter(filterExpr) : null;
Resource[] resources;
MapToDictionary dict = new MapToDictionary(null);
Repository[] repos = listRepositories();
List matchList = new ArrayList();
for (int repoIdx = 0; (repos != null) && (repoIdx < repos.length); repoIdx++) {
resources = repos[repoIdx].getResources();
for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
dict.setSourceMap(resources[resIdx].getProperties());
if (filter == null || filter.match(dict)) {
matchList.add(resources[resIdx]);
}
}
}
// Convert matching resources to an array an sort them by name.
resources = (Resource[]) matchList.toArray(new Resource[matchList.size()]);
Arrays.sort(resources, m_nameComparator);
return resources;
}
use of org.apache.felix.bundlerepository.Resource in project spring-roo by spring-projects.
the class ObrAddonSearchOperationsImpl method populateBundleCache.
/**
* Method to populate current Bundles on installed repositories
*/
private void populateBundleCache() {
// Refreshing Repositories
populateRepositories();
// Cleaning Bundle Cache
bundleCache.clear();
for (Repository repo : repositories) {
Resource[] repoResources = repo.getResources();
for (Resource repoResource : repoResources) {
// Creating bundle of current resource
ObrBundle bundle = new ObrBundle(repoResource.getSymbolicName(), repoResource.getPresentationName(), repoResource.getSize(), repoResource.getVersion(), repoResource.getURI());
// Getting Resource Capabilites
Capability[] resourceCapabilities = repoResource.getCapabilities();
for (Capability capability : resourceCapabilities) {
// Getting resource commands
if (capability.getName().equals(CAPABILITY_COMMANDS_NAME) || capability.getName().equals(CAPABILITY_JDBCDRIVER_NAME) || capability.getName().equals(CAPABILITY_LIBRARY_NAME)) {
// Getting all resource properties
Map<String, Object> capabilityProperties = capability.getPropertiesAsMap();
for (Entry capabilityProperty : capabilityProperties.entrySet()) {
String capabilityCommand = (String) capabilityProperty.getValue();
bundle.addCommand(capabilityCommand);
}
bundleCache.put(bundle.getSymbolicName(), bundle);
}
}
}
}
}
use of org.apache.felix.bundlerepository.Resource in project spring-roo by spring-projects.
the class ObrRepositoryOperationsImpl method introspectRepos.
@Override
public void introspectRepos() throws Exception {
LOGGER.log(Level.INFO, "Getting available bundles on installed repositories...");
// Populating repositories
populateRepositories();
LOGGER.log(Level.INFO, "");
// Getting all names of installed bundles
List<String> installedBundles = getNamesOfInstalledBundles();
// Getting all addons installed on repositories
int totalAddons = 0;
LOGGER.log(Level.INFO, "Status Bundle Description and version");
LOGGER.log(Level.INFO, "-------------------------------------------------------------------------------");
for (Repository repo : repositories) {
Resource[] allResources = repo.getResources();
// Getting all resources for repo
for (Resource resource : allResources) {
String status = "";
// Checking if resource is installed or not
if (installedBundles.indexOf(resource.getSymbolicName()) != -1) {
status = "Installed ";
} else {
status = "Not Installed";
}
// Printing all resources
LOGGER.log(Level.INFO, status + " " + resource.getPresentationName() + " (" + resource.getVersion() + ")");
totalAddons++;
}
}
LOGGER.log(Level.INFO, "");
LOGGER.log(Level.INFO, String.format("%s available bundles on installed repositories were found", totalAddons));
}
use of org.apache.felix.bundlerepository.Resource in project aries by apache.
the class OBRAriesResolver method resolve.
@Deprecated
@Override
public Set<BundleInfo> resolve(AriesApplication app, ResolveConstraint... constraints) throws ResolverException {
log.trace("resolving {}", app);
ApplicationMetadata appMeta = app.getApplicationMetadata();
String appName = appMeta.getApplicationSymbolicName();
Version appVersion = appMeta.getApplicationVersion();
List<Content> appContent = appMeta.getApplicationContents();
Collection<Content> useBundleContent = appMeta.getUseBundles();
List<Content> contents = new ArrayList<Content>();
contents.addAll(appContent);
contents.addAll(useBundleContent);
if ((constraints != null) && (constraints.length > 0)) {
for (ResolveConstraint con : constraints) {
contents.add(ContentFactory.parseContent(con.getBundleName(), con.getVersionRange().toString()));
}
}
Resolver obrResolver = getConfiguredObrResolver(appName, appVersion.toString(), toModelledResource(app.getBundleInfo()), false);
// add a resource describing the requirements of the application metadata.
obrResolver.add(createApplicationResource(appName, appVersion, contents));
if (obrResolver.resolve()) {
Set<BundleInfo> result = new HashSet<BundleInfo>();
List<Resource> requiredResources = retrieveRequiredResources(obrResolver);
for (Resource resource : requiredResources) {
BundleInfo bundleInfo = toBundleInfo(resource, false);
result.add(bundleInfo);
}
if (returnOptionalResources) {
for (Resource resource : obrResolver.getOptionalResources()) {
BundleInfo bundleInfo = toBundleInfo(resource, true);
result.add(bundleInfo);
}
}
return result;
} else {
Reason[] reasons = obrResolver.getUnsatisfiedRequirements();
// 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[] { app.getApplicationMetadata().getApplicationName(), reqList }));
re.setUnsatisfiedRequirementsAndReasons(unsatisfiedRequirements);
log.debug(LOG_EXIT, "resolve", re);
throw re;
}
}
Aggregations