use of org.osgi.resource.Requirement in project bnd by bndtools.
the class CapReqBuilder method getRequirementsFrom.
/**
* Parse requirements from a Parameters set in the form of an OSGi
* Require-Capability header.
*
* @param rr The Require-Capability header.
* @param unalias Whether to unalias requirements. If false then an aliases
* such as "bundle; bsn=org.foo" will be returned as a raw
* Requirement in the unspecified namespace "bundle".
* @return The list of parsed requirements.
* @throws Exception
*/
public static List<Requirement> getRequirementsFrom(Parameters rr, boolean unalias) throws Exception {
List<Requirement> requirements = new ArrayList<Requirement>();
for (Entry<String, Attrs> e : rr.entrySet()) {
Requirement req = getRequirementFrom(Processor.removeDuplicateMarker(e.getKey()), e.getValue(), unalias);
requirements.add(req);
}
return requirements;
}
use of org.osgi.resource.Requirement in project bnd by bndtools.
the class CapReqBuilder method getRequirementFrom.
public static Requirement getRequirementFrom(String namespace, Attrs attrs, boolean unalias) throws Exception {
CapReqBuilder builder = createCapReqBuilder(namespace, attrs);
Requirement requirement = builder.buildSyntheticRequirement();
if (unalias)
requirement = unalias(requirement);
return requirement;
}
use of org.osgi.resource.Requirement in project bnd by bndtools.
the class ResourceBuilder method addRequirement.
public ResourceBuilder addRequirement(CapReqBuilder builder) {
if (builder == null)
return this;
if (built)
throw new IllegalStateException("Resource already built");
Requirement req = builder.setResource(resource).buildRequirement();
requirements.add(req);
return this;
}
use of org.osgi.resource.Requirement in project bnd by bndtools.
the class ResolveTest method testMultipleOptionsNotDuplicated.
/**
* Simple test that resolves a requirement
*
* @throws ResolutionException
*/
public void testMultipleOptionsNotDuplicated() throws ResolutionException {
// Resolve against repo 5
MockRegistry registry = new MockRegistry();
registry.addPlugin(createRepo(IO.getFile("testdata/repo5/index.xml"), "Test-5"));
// Set up a simple Java 7 Felix requirement as per Issue #971
BndEditModel runModel = new BndEditModel();
runModel.setRunFw("org.apache.felix.framework;version='4.2.1'");
runModel.setEE(EE.JavaSE_1_7);
runModel.setSystemPackages(Collections.singletonList(new ExportedPackage("org.w3c.dom.traversal", null)));
runModel.setGenericString("-resolve.effective", "active");
// Require the log service, GoGo shell and GoGo commands
List<Requirement> requirements = new ArrayList<Requirement>();
requirements.add(new CapReqBuilder("osgi.identity").addDirective("filter", "(osgi.identity=org.apache.felix.log)").buildSyntheticRequirement());
requirements.add(new CapReqBuilder("osgi.identity").addDirective("filter", "(osgi.identity=org.apache.felix.gogo.shell)").buildSyntheticRequirement());
requirements.add(new CapReqBuilder("osgi.identity").addDirective("filter", "(osgi.identity=org.apache.felix.gogo.command)").buildSyntheticRequirement());
runModel.setRunRequires(requirements);
// Resolve the bndrun
BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
Resolver resolver = new BndResolver(new org.apache.felix.resolver.Logger(4));
Collection<Resource> resolvedResources = new ResolveProcess().resolveRequired(runModel, registry, resolver, Collections.<ResolutionCallback>emptyList(), log).keySet();
Map<String, Resource> mandatoryResourcesBySymbolicName = new HashMap<String, Resource>();
for (Resource r : resolvedResources) {
Capability cap = r.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).get(0);
// We shouldn't have more than one match for each symbolic name for
// this resolve
String symbolicName = (String) cap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
assertNull("Multiple results for " + symbolicName, mandatoryResourcesBySymbolicName.put(symbolicName, r));
}
assertEquals(4, resolvedResources.size());
}
use of org.osgi.resource.Requirement in project bnd by bndtools.
the class ResolveTest method testenRouteGuard.
/**
* The enRoute base guard resolved but is missing bundles, the runbundles do
* not run
*/
public void testenRouteGuard() throws Exception {
MockRegistry registry = new MockRegistry();
Repository repo = createRepo(IO.getFile("testdata/enroute/index.xml"));
registry.addPlugin(repo);
List<Requirement> reqs = CapReqBuilder.getRequirementsFrom(new Parameters("osgi.wiring.package;filter:='(osgi.wiring.package=org.osgi.service.async)'"));
Collection<Capability> pack = repo.findProviders(reqs).get(reqs.get(0));
assertEquals(2, pack.size());
ResourceBuilder b = new ResourceBuilder();
File guard = IO.getFile("testdata/enroute/osgi.enroute.base.guard.jar");
Domain manifest = Domain.domain(guard);
b.addManifest(manifest);
Repository resourceRepository = new ResourcesRepository(b.build());
registry.addPlugin(resourceRepository);
Processor model = new Processor();
model.setRunfw("org.eclipse.osgi");
model.setRunblacklist("osgi.identity;filter:='(osgi.identity=osgi.enroute.base.api)',osgi.identity;filter:='(osgi.identity=osgi.cmpn)',osgi.identity;filter:='(osgi.identity=osgi.core)");
model.setRunRequires("osgi.identity;filter:='(osgi.identity=osgi.enroute.base.guard)'");
model.setRunee("JavaSE-1.8");
try {
BndrunResolveContext context = new BndrunResolveContext(model, null, registry, log);
Resolver resolver = new BndResolver(new ResolverLogger(4));
Map<Resource, List<Wire>> resolved = resolver.resolve(context);
Set<Resource> resources = resolved.keySet();
} catch (ResolutionException e) {
String msg = e.getMessage().replaceAll("\\[caused by:", "\n->");
System.out.println(msg);
fail(msg);
}
}
Aggregations