use of org.osgi.resource.Capability in project bnd by bndtools.
the class ResourceUtils method toVersionClause.
/**
* Create a VersionedClause by applying a version range mask to the
* resource! Masks are defined by
* {@link aQute.bnd.osgi.Macro#_range(String[])}. If the resource should
* represent a project in the bnd workspace, then instead the VersionClause
* will refer to it as a snapshot version: e.g. <bsn>;version=snapshot
*/
public static VersionedClause toVersionClause(Resource resource, String mask) {
Capability idCap = getIdentityCapability(resource);
String identity = getIdentity(idCap);
String versionString;
if (resource.getCapabilities(WORKSPACE_NAMESPACE).isEmpty()) {
Macro macro = new Macro(new Processor());
Version version = getVersion(idCap);
versionString = macro._range(new String[] { "range", mask, version.toString() });
} else {
versionString = "snapshot";
}
Attrs attribs = new Attrs();
attribs.put(Constants.VERSION_ATTRIBUTE, versionString);
return new VersionedClause(identity, attribs);
}
use of org.osgi.resource.Capability in project bnd by bndtools.
the class FilterParser method simple.
public String simple(Resource resource) {
if (resource == null)
return "<>";
List<Capability> capabilities = resource.getCapabilities("osgi.identity");
if (capabilities.isEmpty())
return resource.toString();
Capability c = capabilities.get(0);
String bsn = (String) c.getAttributes().get("osgi.identity");
Object version = c.getAttributes().get("version");
if (version == null)
return bsn;
else
return bsn + ";version=" + version;
}
use of org.osgi.resource.Capability in project bnd by bndtools.
the class ResourceBuilder method findCapabilities.
public List<Capability> findCapabilities(String ns, String filter) throws Exception {
if (filter == null || capabilities.isEmpty())
return Collections.emptyList();
List<Capability> capabilities = new ArrayList<Capability>();
Filter f = new Filter(filter);
for (Capability c : getCapabilities()) {
if (ns != null && !ns.equals(c.getNamespace()))
continue;
Map<String, Object> attributes = c.getAttributes();
if (attributes != null) {
if (f.matchMap(attributes))
capabilities.add(c);
}
}
return capabilities;
}
use of org.osgi.resource.Capability 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.Capability 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