use of org.osgi.resource.Wire in project bndtools by bndtools.
the class ResolutionTreeContentProvider method processWires.
private static void processWires(Collection<Wire> wires, Map<Capability, ResolutionTreeItem> items) {
if (wires != null) {
for (Wire wire : wires) {
ResolutionTreeItem item = items.get(wire.getCapability());
if (item == null) {
item = new ResolutionTreeItem(wire.getCapability());
items.put(wire.getCapability(), item);
}
item.addWire(wire);
}
}
}
use of org.osgi.resource.Wire in project bndtools by bndtools.
the class ResolutionTreeContentProvider method getChildren.
@Override
public Object[] getChildren(Object parent) {
Object[] result;
if (parent instanceof Resource) {
Resource parentResource = (Resource) parent;
Map<Capability, ResolutionTreeItem> items = new HashMap<Capability, ResolutionTreeItem>();
List<Wire> wires = resolution.get(parentResource);
processWires(wires, items);
result = items.values().toArray();
} else if (parent instanceof Requirement) {
result = getChildren(((Requirement) parent).getResource());
} else if (parent instanceof ResolutionTreeItem) {
ResolutionTreeItem item = (ResolutionTreeItem) parent;
List<Wire> wires = item.getWires();
List<Requirement> reqs = new ArrayList<Requirement>();
for (Wire wire : wires) reqs.add(wire.getRequirement());
result = reqs.toArray();
} else {
result = null;
}
return result;
}
use of org.osgi.resource.Wire in project bndtools by bndtools.
the class ResolveOperation method run.
@Override
public void run(IProgressMonitor monitor) {
MultiStatus status = new MultiStatus(Plugin.PLUGIN_ID, 0, Messages.ResolveOperation_errorOverview, null);
// Start a coordination
BundleContext bc = Plugin.getDefault().getBundleContext();
ServiceReference<Coordinator> coordSvcRef = bc.getServiceReference(Coordinator.class);
Coordinator coordinator = coordSvcRef != null ? (Coordinator) bc.getService(coordSvcRef) : null;
Coordination coordination = coordinator != null ? coordinator.begin(ResolveOperation.class.getName(), 0) : null;
// Begin resolve
try (ResolverLogger logger = new ResolverLogger()) {
try {
ResolveProcess resolve = new ResolveProcess();
BndResolver bndResolver = new BndResolver(logger);
ReporterLogService log = new ReporterLogService(model.getWorkspace());
Map<Resource, List<Wire>> wirings = resolve.resolveRequired(model, model.getWorkspace(), bndResolver, callbacks, log);
Map<Resource, List<Wire>> optionalResources = new HashMap<Resource, List<Wire>>(resolve.getOptionalResources().size());
for (Resource optional : resolve.getOptionalResources()) {
optionalResources.put(optional, new ArrayList<Wire>(resolve.getOptionalReasons(optional)));
}
result = new ResolutionResult(Outcome.Resolved, wirings, optionalResources, null, status, logger.getLog());
if (coordination != null)
coordination.end();
} catch (ResolveCancelledException e) {
result = new ResolutionResult(Outcome.Cancelled, null, null, null, status, logger.getLog());
if (coordination != null)
coordination.fail(e);
} catch (ResolutionException e) {
status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e));
result = new ResolutionResult(Outcome.Unresolved, null, null, e, status, logger.getLog());
if (coordination != null)
coordination.fail(e);
} catch (Exception e) {
status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Exception during resolution.", e));
result = new ResolutionResult(Outcome.Error, null, null, null, status, logger.getLog());
if (coordination != null)
coordination.fail(e);
} finally {
if (coordinator != null)
bc.ungetService(coordSvcRef);
}
}
}
use of org.osgi.resource.Wire in project aries by apache.
the class DependencyCalculator method calculateDependencies.
public List<Requirement> calculateDependencies() throws ResolutionException {
ArrayList<Requirement> result = new ArrayList<Requirement>();
Resolver resolver = Activator.getInstance().getResolver();
Map<Resource, List<Wire>> resolution = resolver.resolve(context);
for (List<Wire> wires : resolution.values()) for (Wire wire : wires) if (wire.getCapability() instanceof MissingCapability)
result.add(wire.getRequirement());
result.trimToSize();
return result;
}
use of org.osgi.resource.Wire in project aries by apache.
the class ResolveContext method processAsSubstitutableExport.
private void processAsSubstitutableExport(boolean isFragment, Requirement requirement, List<Capability> capabilities) {
String namespace = requirement.getNamespace();
if (!PackageNamespace.PACKAGE_NAMESPACE.equals(namespace)) {
return;
}
Resource resource = requirement.getResource();
Wiring wiring = wirings.get(resource);
if (isFragment) {
List<Wire> fragmentWires = wiring.getRequiredResourceWires(HostNamespace.HOST_NAMESPACE);
for (Wire fragmentWire : fragmentWires) {
Resource host = fragmentWire.getProvider();
processResourceCapabilities(wirings.get(host).getResourceCapabilities(namespace), requirement, capabilities);
}
} else {
List<Capability> resourceCapabilities = wiring.getResourceCapabilities(namespace);
processResourceCapabilities(resourceCapabilities, requirement, capabilities);
}
}
Aggregations