use of org.apache.felix.bundlerepository.Reason in project karaf by apache.
the class ObrCommandSupport method doDeploy.
protected void doDeploy(RepositoryAdmin admin, List<String> bundles, boolean start, boolean deployOptional) throws Exception {
Resolver resolver = admin.resolver();
for (String bundle : bundles) {
String[] target = getTarget(bundle);
Resource resource = selectNewestVersion(searchRepository(admin, target[0], target[1]));
if (resource != null) {
resolver.add(resource);
} else {
System.err.println("Unknown bundle - " + target[0]);
}
}
if ((resolver.getAddedResources() != null) && (resolver.getAddedResources().length > 0)) {
if (resolver.resolve(deployOptional ? 0 : Resolver.NO_OPTIONAL_RESOURCES)) {
System.out.println("Target resource(s):");
printUnderline(System.out, 19);
Resource[] resources = resolver.getAddedResources();
for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
System.out.println(" " + getResourceId(resources[resIdx]) + " (" + resources[resIdx].getVersion() + ")");
}
resources = resolver.getRequiredResources();
if ((resources != null) && (resources.length > 0)) {
System.out.println("\nRequired resource(s):");
printUnderline(System.out, 21);
for (Resource resource : resources) {
System.out.println(" " + getResourceId(resource) + " (" + resource.getVersion() + ")");
}
}
if (deployOptional) {
resources = resolver.getOptionalResources();
if ((resources != null) && (resources.length > 0)) {
System.out.println("\nOptional resource(s):");
printUnderline(System.out, 21);
for (Resource resource : resources) {
System.out.println(" " + getResourceId(resource) + " (" + resource.getVersion() + ")");
}
}
}
try {
System.out.print("\nDeploying...");
resolver.deploy(start ? Resolver.START : 0);
System.out.println("done.");
} catch (IllegalStateException ex) {
System.err.println(ex);
}
} else {
Reason[] reqs = resolver.getUnsatisfiedRequirements();
if ((reqs != null) && (reqs.length > 0)) {
System.out.println("Unsatisfied requirement(s):");
printUnderline(System.out, 27);
for (Reason req : reqs) {
System.out.println(" " + req.getRequirement().getFilter());
System.out.println(" " + getResourceId(req.getResource()));
}
} else {
System.out.println("Could not resolve targets.");
}
}
}
}
use of org.apache.felix.bundlerepository.Reason in project felix by apache.
the class ResolverWrapper method getUnsatisfiedRequirementsMap.
private Map getUnsatisfiedRequirementsMap() {
Reason[] reasons = resolver.getUnsatisfiedRequirements();
Map map = new HashMap();
for (int i = 0; i < reasons.length; i++) {
org.osgi.service.obr.Requirement req = Wrapper.wrap(reasons[i].getRequirement());
org.osgi.service.obr.Resource res = Wrapper.wrap(reasons[i].getResource());
List l = (List) map.get(req);
if (l == null) {
l = new ArrayList();
map.put(req, l);
}
l.add(res);
}
return map;
}
use of org.apache.felix.bundlerepository.Reason in project felix by apache.
the class ObrCommandImpl method _deploy.
private void _deploy(ParsedCommand pc, String command, PrintStream out, PrintStream err) throws IOException, InvalidSyntaxException {
org.apache.felix.bundlerepository.Resolver resolver = m_repoAdmin.resolver();
for (int i = 0; (pc != null) && (i < pc.getTargetCount()); i++) {
// Find the target's bundle resource.
Resource resource = selectNewestVersion(searchRepository(pc.getTargetId(i), pc.getTargetVersion(i)));
if (resource != null) {
resolver.add(resource);
} else {
err.println("Unknown bundle - " + pc.getTargetId(i));
}
}
if ((resolver.getAddedResources() != null) && (resolver.getAddedResources().length > 0)) {
if (resolver.resolve()) {
out.println("Target resource(s):");
printUnderline(out, 19);
Resource[] resources = resolver.getAddedResources();
for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
out.println(" " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
}
resources = resolver.getRequiredResources();
if ((resources != null) && (resources.length > 0)) {
out.println("\nRequired resource(s):");
printUnderline(out, 21);
for (int resIdx = 0; resIdx < resources.length; resIdx++) {
out.println(" " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
}
}
resources = resolver.getOptionalResources();
if ((resources != null) && (resources.length > 0)) {
out.println("\nOptional resource(s):");
printUnderline(out, 21);
for (int resIdx = 0; resIdx < resources.length; resIdx++) {
out.println(" " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
}
}
try {
out.print("\nDeploying...");
resolver.deploy(command.equals(START_CMD) ? Resolver.START : 0);
out.println("done.");
} catch (IllegalStateException ex) {
err.println(ex);
}
} else {
Reason[] reqs = resolver.getUnsatisfiedRequirements();
if ((reqs != null) && (reqs.length > 0)) {
out.println("Unsatisfied requirement(s):");
printUnderline(out, 27);
for (int reqIdx = 0; reqIdx < reqs.length; reqIdx++) {
out.println(" " + reqs[reqIdx].getRequirement().getFilter());
out.println(" " + reqs[reqIdx].getResource().getPresentationName());
}
} else {
out.println("Could not resolve targets.");
}
}
}
}
use of org.apache.felix.bundlerepository.Reason in project aries by apache.
the class OBRAriesResolver method satisfiesAll.
protected boolean satisfiesAll(Resource res, Reason[] reasons) {
log.debug(LOG_ENTRY, "satisfiesAll", new Object[] { res, Arrays.toString(reasons) });
// Let's convert the reason to requirement
List<Requirement> reqs = new ArrayList<Requirement>();
for (Reason reason : reasons) {
reqs.add(reason.getRequirement());
}
boolean result = true;
outer: for (Requirement r : reqs) {
boolean found = false;
inner: for (Capability c : res.getCapabilities()) {
if (r.isSatisfied(c)) {
found = true;
break inner;
}
}
if (!!!found && !!!r.isOptional()) {
result = false;
break outer;
}
}
log.debug(LOG_EXIT, "satisfiesAll", result);
return result;
}
use of org.apache.felix.bundlerepository.Reason 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