Search in sources :

Example 61 with Requirement

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;
}
Also used : Requirement(org.osgi.resource.Requirement) ArrayList(java.util.ArrayList) Attrs(aQute.bnd.header.Attrs)

Example 62 with Requirement

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;
}
Also used : Requirement(org.osgi.resource.Requirement)

Example 63 with 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;
}
Also used : Requirement(org.osgi.resource.Requirement)

Example 64 with Requirement

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());
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Resolver(org.osgi.service.resolver.Resolver) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) MockRegistry(test.lib.MockRegistry) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) Requirement(org.osgi.resource.Requirement) ExportedPackage(aQute.bnd.build.model.clauses.ExportedPackage) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 65 with Requirement

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);
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Parameters(aQute.bnd.header.Parameters) Processor(aQute.bnd.osgi.Processor) Capability(org.osgi.resource.Capability) Resolver(org.osgi.service.resolver.Resolver) MockRegistry(test.lib.MockRegistry) Resource(org.osgi.resource.Resource) ResolutionException(org.osgi.service.resolver.ResolutionException) Requirement(org.osgi.resource.Requirement) Repository(org.osgi.service.repository.Repository) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository) ArrayList(java.util.ArrayList) List(java.util.List) Domain(aQute.bnd.osgi.Domain) File(java.io.File) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Aggregations

Requirement (org.osgi.resource.Requirement)201 Capability (org.osgi.resource.Capability)103 Resource (org.osgi.resource.Resource)59 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)53 ArrayList (java.util.ArrayList)51 Collection (java.util.Collection)44 BndEditModel (aQute.bnd.build.model.BndEditModel)35 HashMap (java.util.HashMap)35 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)34 MockRegistry (test.lib.MockRegistry)32 List (java.util.List)19 Repository (org.osgi.service.repository.Repository)19 Test (org.junit.Test)18 File (java.io.File)16 Map (java.util.Map)12 Resolver (org.osgi.service.resolver.Resolver)11 LinkedHashSet (java.util.LinkedHashSet)10 LinkedList (java.util.LinkedList)10 Wire (org.osgi.resource.Wire)10 Parameters (aQute.bnd.header.Parameters)9