Search in sources :

Example 51 with Resource

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());
}
Also used : Processor(aQute.bnd.osgi.Processor) ResolverLogger(biz.aQute.resolve.ResolverLogger) RemoteOptions(aQute.bnd.main.RemoteCommand.RemoteOptions) ArrayList(java.util.ArrayList) MockRegistry(aQute.bnd.main.testlib.MockRegistry) Resource(org.osgi.resource.Resource) CommandLine(aQute.lib.getopt.CommandLine) DistroOptions(aQute.bnd.main.RemoteCommand.DistroOptions) ResolveProcess(biz.aQute.resolve.ResolveProcess) ArrayList(java.util.ArrayList) List(java.util.List) BndResolver(biz.aQute.resolve.BndResolver) File(java.io.File)

Example 52 with Resource

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());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Capability(org.osgi.resource.Capability) Resource(org.osgi.resource.Resource) NotExpression(org.osgi.service.repository.NotExpression) OrExpression(org.osgi.service.repository.OrExpression) Requirement(org.osgi.resource.Requirement) AndExpression(org.osgi.service.repository.AndExpression) RequirementExpression(org.osgi.service.repository.RequirementExpression) Iterator(java.util.Iterator) Collection(java.util.Collection) IdentityExpression(org.osgi.service.repository.IdentityExpression) HashSet(java.util.HashSet)

Example 53 with Resource

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);
    }
}
Also used : Requirement(org.osgi.resource.Requirement) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Capability(org.osgi.resource.Capability) ContentCapability(aQute.bnd.osgi.resource.ResourceUtils.ContentCapability) Resource(org.osgi.resource.Resource) Collection(java.util.Collection)

Example 54 with Resource

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;
}
Also used : Capability(org.osgi.resource.Capability) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource)

Example 55 with Resource

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);
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Resource(org.osgi.resource.Resource)

Aggregations

Resource (org.osgi.resource.Resource)201 Capability (org.osgi.resource.Capability)62 Requirement (org.osgi.resource.Requirement)62 ArrayList (java.util.ArrayList)57 List (java.util.List)39 HashMap (java.util.HashMap)32 File (java.io.File)27 Collection (java.util.Collection)24 Wire (org.osgi.resource.Wire)24 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)23 Map (java.util.Map)22 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)18 URI (java.net.URI)18 HashSet (java.util.HashSet)18 BndEditModel (aQute.bnd.build.model.BndEditModel)15 MockRegistry (test.lib.MockRegistry)15 Version (org.osgi.framework.Version)14 BundleRevision (org.osgi.framework.wiring.BundleRevision)14 Repository (org.osgi.service.repository.Repository)14 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)13