use of org.osgi.resource.Resource in project bnd by bndtools.
the class DistroCommandTest method testResolveAgainstDistro.
public void testResolveAgainstDistro() throws Exception {
bnd bnd = new bnd();
CommandLine cmdline = new CommandLine(null);
List<String> remoteArgs = new ArrayList<>();
RemoteOptions remoteOptions = cmdline.getOptions(RemoteOptions.class, remoteArgs);
File distro = new File("generated/tmp/test.distro.jar");
List<String> distroArgs = new ArrayList<>();
distroArgs.add("-o");
distroArgs.add(distro.getPath());
distroArgs.add("test.distro");
distroArgs.add("1.0.0");
DistroOptions distroOptions = cmdline.getOptions(DistroOptions.class, distroArgs);
new RemoteCommand(bnd, remoteOptions)._distro(distroOptions);
assertTrue(distro.exists());
ResolveProcess process = new ResolveProcess();
ResolverLogger logger = new ResolverLogger();
MockRegistry registry = new MockRegistry();
Processor model = new Processor();
model.setProperty("-distro", distro.getAbsolutePath() + ";version=file");
model.setProperty("-runfw", "org.eclipse.osgi");
model.setProperty("-runrequires", "osgi.wiring.package;filter:='(osgi.wiring.package=com.liferay.dynamic.data.mapping.taglib.servlet.taglib)'");
Map<Resource, List<Wire>> requiredResources = process.resolveRequired(model, null, registry, new BndResolver(logger), Collections.<ResolutionCallback>emptyList(), logger);
assertEquals(1, requiredResources.size());
}
use of org.osgi.resource.Resource in project bnd by bndtools.
the class BaseRepository method dispatch.
private void dispatch(RequirementExpression expression, Set<Resource> providers) {
if (expression instanceof IdentityExpression) {
Map<Requirement, Collection<Capability>> capabilities = findProviders(Collections.singleton(((IdentityExpression) expression).getRequirement()));
for (Collection<Capability> caps : capabilities.values()) {
for (Capability c : caps) providers.add(c.getResource());
}
} else if (expression instanceof OrExpression) {
for (RequirementExpression re : ((OrExpression) expression).getRequirementExpressions()) dispatch(re, providers);
} else if (expression instanceof AndExpression) {
List<RequirementExpression> requirementExpressions = ((AndExpression) expression).getRequirementExpressions();
if (requirementExpressions.isEmpty())
return;
if (requirementExpressions.size() == 1) {
dispatch(requirementExpressions.get(0), providers);
return;
}
Set<Resource> subset = new HashSet<>();
dispatch(requirementExpressions.get(0), subset);
for (int i = 1; i < requirementExpressions.size(); i++) {
for (Iterator<Resource> it = subset.iterator(); it.hasNext(); ) {
Resource resource = it.next();
RequirementExpression re = requirementExpressions.get(i);
if (!matches(re, resource)) {
it.remove();
if (subset.isEmpty())
return;
}
}
}
providers.addAll(subset);
} else if (expression instanceof NotExpression) {
Set<Resource> allSet = new HashSet<>();
dispatch(all, allSet);
RequirementExpression re = ((NotExpression) expression).getRequirementExpression();
for (Iterator<Resource> it = allSet.iterator(); it.hasNext(); ) {
Resource resource = it.next();
if (matches(re, resource)) {
it.remove();
if (allSet.isEmpty())
return;
}
}
providers.addAll(allSet);
} else
throw new UnsupportedOperationException("Unknown expression type " + expression.getClass());
}
use of org.osgi.resource.Resource in project bnd by bndtools.
the class BridgeRepository method index.
private void index() throws Exception {
Map<Requirement, Collection<Capability>> all = repository.findProviders(Collections.singleton(allRq));
for (Capability capability : all.get(allRq)) {
Resource r = capability.getResource();
index(r);
}
}
use of org.osgi.resource.Resource in project bnd by bndtools.
the class ResourcesRepository method findProvider.
public List<Capability> findProvider(Requirement requirement) {
List<Capability> result = new ArrayList<Capability>();
String namespace = requirement.getNamespace();
for (Resource resource : resources) {
for (Capability capability : resource.getCapabilities(namespace)) {
if (ResourceUtils.matches(requirement, capability)) {
result.add(capability);
}
}
}
return result;
}
use of org.osgi.resource.Resource in project bnd by bndtools.
the class XMLResourceParser method parseResource.
private void parseResource(List<Resource> resources) throws Exception {
ResourceBuilder resourceBuilder = new ResourceBuilder();
next();
while (reader.isStartElement()) {
parseCapabilityOrRequirement(resourceBuilder);
}
Resource resource = resourceBuilder.build();
resources.add(resource);
tagEnd(TAG_RESOURCE);
}
Aggregations