Search in sources :

Example 1 with GenericRequirement

use of org.apache.felix.resolver.test.util.GenericRequirement in project felix by apache.

the class Main method populateScenario6.

private static List<Resource> populateScenario6(Map<Resource, Wiring> wirings, Map<Requirement, List<Capability>> candMap) {
    wirings.clear();
    candMap.clear();
    ResourceImpl a1 = new ResourceImpl("A");
    a1.addRequirement(new PackageRequirement(a1, "p1"));
    a1.addRequirement(new PackageRequirement(a1, "p2"));
    Requirement a1Req = new GenericRequirement(a1, "generic");
    a1Req.getDirectives().put(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE, Namespace.CARDINALITY_MULTIPLE);
    a1.addRequirement(a1Req);
    ResourceImpl a2 = new ResourceImpl("A");
    a2.addRequirement(new BundleRequirement(a2, "B"));
    a2.addRequirement(new BundleRequirement(a2, "C"));
    Requirement a2Req = new GenericRequirement(a2, "generic");
    a2Req.getDirectives().put(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE, Namespace.CARDINALITY_MULTIPLE);
    a2.addRequirement(a2Req);
    ResourceImpl b1 = new ResourceImpl("B");
    b1.addCapability(new BundleCapability(b1, "B"));
    Capability b1_p2 = new PackageCapability(b1, "p2");
    b1_p2.getDirectives().put(Namespace.CAPABILITY_USES_DIRECTIVE, "p1");
    b1.addCapability(b1_p2);
    b1.addRequirement(new PackageRequirement(b1, "p1"));
    ResourceImpl b2 = new ResourceImpl("B");
    b2.addCapability(new BundleCapability(b2, "B"));
    Capability b2_p2 = new PackageCapability(b2, "p2");
    b2_p2.getDirectives().put(Namespace.CAPABILITY_USES_DIRECTIVE, "p1");
    b2.addCapability(b2_p2);
    b2.addRequirement(new PackageRequirement(b2, "p1"));
    ResourceImpl c1 = new ResourceImpl("C");
    c1.addCapability(new BundleCapability(c1, "C"));
    Capability c1_p1 = new PackageCapability(c1, "p1");
    ResourceImpl c2 = new ResourceImpl("C");
    c2.addCapability(new BundleCapability(c2, "C"));
    Capability c2_p1 = new PackageCapability(c2, "p1");
    ResourceImpl d1 = new ResourceImpl("D");
    GenericCapability d1_generic = new GenericCapability(d1, "generic");
    d1_generic.addDirective(Namespace.CAPABILITY_USES_DIRECTIVE, "p1,p2");
    d1.addCapability(d1_generic);
    d1.addRequirement(new PackageRequirement(d1, "p1"));
    d1.addRequirement(new PackageRequirement(d1, "p2"));
    ResourceImpl d2 = new ResourceImpl("D");
    GenericCapability d2_generic = new GenericCapability(d2, "generic");
    d2_generic.addDirective(Namespace.CAPABILITY_USES_DIRECTIVE, "p1,p2");
    d2.addCapability(d2_generic);
    d2.addRequirement(new PackageRequirement(d2, "p1"));
    d2.addRequirement(new PackageRequirement(d2, "p2"));
    candMap.put(a1.getRequirements(null).get(0), Arrays.asList(c2_p1));
    candMap.put(a1.getRequirements(null).get(1), Arrays.asList(b2_p2));
    candMap.put(a1.getRequirements(null).get(2), Arrays.asList((Capability) d1_generic, (Capability) d2_generic));
    candMap.put(a2.getRequirements(null).get(0), c2.getCapabilities(BundleNamespace.BUNDLE_NAMESPACE));
    candMap.put(a2.getRequirements(null).get(1), b2.getCapabilities(BundleNamespace.BUNDLE_NAMESPACE));
    candMap.put(a2.getRequirements(null).get(2), Arrays.asList((Capability) d1_generic, (Capability) d2_generic));
    candMap.put(b1.getRequirements(null).get(0), Arrays.asList(c1_p1, c2_p1));
    candMap.put(b2.getRequirements(null).get(0), Arrays.asList(c1_p1, c2_p1));
    candMap.put(d1.getRequirements(null).get(0), Arrays.asList(c1_p1, c2_p1));
    candMap.put(d1.getRequirements(null).get(1), Arrays.asList(b1_p2, b2_p2));
    candMap.put(d2.getRequirements(null).get(0), Arrays.asList(c1_p1, c2_p1));
    candMap.put(d2.getRequirements(null).get(1), Arrays.asList(b1_p2, b2_p2));
    List<Resource> resources = new ArrayList<Resource>();
    resources.add(a1);
    resources.add(a2);
    return resources;
}
Also used : Requirement(org.osgi.resource.Requirement) BundleRequirement(org.apache.felix.resolver.test.util.BundleRequirement) GenericRequirement(org.apache.felix.resolver.test.util.GenericRequirement) PackageRequirement(org.apache.felix.resolver.test.util.PackageRequirement) ResourceImpl(org.apache.felix.resolver.test.util.ResourceImpl) GenericRequirement(org.apache.felix.resolver.test.util.GenericRequirement) PackageCapability(org.apache.felix.resolver.test.util.PackageCapability) GenericCapability(org.apache.felix.resolver.test.util.GenericCapability) PackageCapability(org.apache.felix.resolver.test.util.PackageCapability) Capability(org.osgi.resource.Capability) BundleCapability(org.apache.felix.resolver.test.util.BundleCapability) PackageRequirement(org.apache.felix.resolver.test.util.PackageRequirement) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) GenericCapability(org.apache.felix.resolver.test.util.GenericCapability) BundleCapability(org.apache.felix.resolver.test.util.BundleCapability) BundleRequirement(org.apache.felix.resolver.test.util.BundleRequirement)

Example 2 with GenericRequirement

use of org.apache.felix.resolver.test.util.GenericRequirement in project felix by apache.

the class Main method populateScenario7.

private static List<Resource> populateScenario7(Map<Resource, Wiring> wirings, Map<Requirement, List<Capability>> candMap) {
    wirings.clear();
    candMap.clear();
    ResourceImpl a1 = new ResourceImpl("A");
    GenericCapability a1_hostCap = new GenericCapability(a1, HostNamespace.HOST_NAMESPACE);
    a1_hostCap.addAttribute(HostNamespace.HOST_NAMESPACE, "A");
    a1.addCapability(a1_hostCap);
    ResourceImpl f1 = new ResourceImpl("F1", IdentityNamespace.TYPE_FRAGMENT, Version.emptyVersion);
    GenericRequirement f1_hostReq = new GenericRequirement(f1, HostNamespace.HOST_NAMESPACE);
    f1_hostReq.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(" + HostNamespace.HOST_NAMESPACE + "=A)");
    f1.addRequirement(f1_hostReq);
    ResourceImpl f2 = new ResourceImpl("F2", IdentityNamespace.TYPE_FRAGMENT, Version.emptyVersion);
    GenericRequirement f2_hostReq = new GenericRequirement(f2, HostNamespace.HOST_NAMESPACE);
    f2_hostReq.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(" + HostNamespace.HOST_NAMESPACE + "=A)");
    f2.addRequirement(f2_hostReq);
    ResourceImpl b1 = new ResourceImpl("B");
    GenericRequirement b1_identityReq = new GenericRequirement(f2, IdentityNamespace.IDENTITY_NAMESPACE);
    b1_identityReq.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(" + IdentityNamespace.IDENTITY_NAMESPACE + "=F2)");
    b1.addRequirement(b1_identityReq);
    candMap.put(f1.getRequirements(null).get(0), a1.getCapabilities(HostNamespace.HOST_NAMESPACE));
    candMap.put(f2.getRequirements(null).get(0), a1.getCapabilities(HostNamespace.HOST_NAMESPACE));
    candMap.put(b1.getRequirements(null).get(0), f2.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE));
    List<Resource> resources = new ArrayList<Resource>();
    resources.add(a1);
    resources.add(f1);
    resources.add(f2);
    resources.add(b1);
    return resources;
}
Also used : ResourceImpl(org.apache.felix.resolver.test.util.ResourceImpl) GenericRequirement(org.apache.felix.resolver.test.util.GenericRequirement) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) GenericCapability(org.apache.felix.resolver.test.util.GenericCapability)

Example 3 with GenericRequirement

use of org.apache.felix.resolver.test.util.GenericRequirement in project felix by apache.

the class ResolverTest method addReq.

private static Requirement addReq(ResourceImpl res, String namespace, String value, boolean optional) {
    GenericRequirement req = new GenericRequirement(res, namespace);
    req.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(" + namespace + "=" + value + ")");
    if (optional) {
        req.addDirective(Constants.RESOLUTION_DIRECTIVE, Constants.RESOLUTION_OPTIONAL);
    }
    res.addRequirement(req);
    return req;
}
Also used : GenericRequirement(org.apache.felix.resolver.test.util.GenericRequirement)

Example 4 with GenericRequirement

use of org.apache.felix.resolver.test.util.GenericRequirement in project felix by apache.

the class ResolverTest method populateScenario6.

private static List<Resource> populateScenario6(Map<Resource, Wiring> wirings, Map<Requirement, List<Capability>> candMap) {
    ResourceImpl a1 = new ResourceImpl("A");
    a1.addRequirement(new PackageRequirement(a1, "p1"));
    a1.addRequirement(new PackageRequirement(a1, "p2"));
    Requirement a1Req = new GenericRequirement(a1, "generic");
    a1Req.getDirectives().put(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE, Namespace.CARDINALITY_MULTIPLE);
    a1.addRequirement(a1Req);
    ResourceImpl a2 = new ResourceImpl("A");
    a2.addRequirement(new BundleRequirement(a2, "B"));
    a2.addRequirement(new BundleRequirement(a2, "C"));
    Requirement a2Req = new GenericRequirement(a2, "generic");
    a2Req.getDirectives().put(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE, Namespace.CARDINALITY_MULTIPLE);
    a2.addRequirement(a2Req);
    ResourceImpl b1 = new ResourceImpl("B");
    b1.addCapability(new BundleCapability(b1, "B"));
    Capability b1_p2 = new PackageCapability(b1, "p2");
    b1_p2.getDirectives().put(Namespace.CAPABILITY_USES_DIRECTIVE, "p1");
    b1.addCapability(b1_p2);
    b1.addRequirement(new PackageRequirement(b1, "p1"));
    ResourceImpl b2 = new ResourceImpl("B");
    b2.addCapability(new BundleCapability(b2, "B"));
    Capability b2_p2 = new PackageCapability(b2, "p2");
    b2_p2.getDirectives().put(Namespace.CAPABILITY_USES_DIRECTIVE, "p1");
    b2.addCapability(b2_p2);
    b2.addRequirement(new PackageRequirement(b2, "p1"));
    ResourceImpl c1 = new ResourceImpl("C");
    c1.addCapability(new BundleCapability(c1, "C"));
    Capability c1_p1 = new PackageCapability(c1, "p1");
    c1.addCapability(c1_p1);
    ResourceImpl c2 = new ResourceImpl("C");
    c2.addCapability(new BundleCapability(c2, "C"));
    Capability c2_p1 = new PackageCapability(c2, "p1");
    c2.addCapability(c2_p1);
    ResourceImpl d1 = new ResourceImpl("D");
    GenericCapability d1_generic = new GenericCapability(d1, "generic");
    d1_generic.addDirective(Namespace.CAPABILITY_USES_DIRECTIVE, "p1,p2");
    d1.addCapability(d1_generic);
    d1.addRequirement(new PackageRequirement(d1, "p1"));
    d1.addRequirement(new PackageRequirement(d1, "p2"));
    ResourceImpl d2 = new ResourceImpl("D");
    GenericCapability d2_generic = new GenericCapability(d2, "generic");
    d2_generic.addDirective(Namespace.CAPABILITY_USES_DIRECTIVE, "p1,p2");
    d2.addCapability(d2_generic);
    d2.addRequirement(new PackageRequirement(d2, "p1"));
    d2.addRequirement(new PackageRequirement(d2, "p2"));
    candMap.put(a1.getRequirements(null).get(0), Arrays.asList(c2_p1));
    candMap.put(a1.getRequirements(null).get(1), Arrays.asList(b2_p2));
    candMap.put(a1.getRequirements(null).get(2), Arrays.asList((Capability) d1_generic, (Capability) d2_generic));
    candMap.put(a2.getRequirements(null).get(0), c2.getCapabilities(BundleNamespace.BUNDLE_NAMESPACE));
    candMap.put(a2.getRequirements(null).get(1), b2.getCapabilities(BundleNamespace.BUNDLE_NAMESPACE));
    candMap.put(a2.getRequirements(null).get(2), Arrays.asList((Capability) d1_generic, (Capability) d2_generic));
    candMap.put(b1.getRequirements(null).get(0), Arrays.asList(c1_p1, c2_p1));
    candMap.put(b2.getRequirements(null).get(0), Arrays.asList(c1_p1, c2_p1));
    candMap.put(d1.getRequirements(null).get(0), Arrays.asList(c1_p1, c2_p1));
    candMap.put(d1.getRequirements(null).get(1), Arrays.asList(b1_p2, b2_p2));
    candMap.put(d2.getRequirements(null).get(0), Arrays.asList(c1_p1, c2_p1));
    candMap.put(d2.getRequirements(null).get(1), Arrays.asList(b1_p2, b2_p2));
    List<Resource> resources = new ArrayList<Resource>();
    resources.add(a1);
    resources.add(a2);
    return resources;
}
Also used : Requirement(org.osgi.resource.Requirement) BundleRequirement(org.apache.felix.resolver.test.util.BundleRequirement) GenericRequirement(org.apache.felix.resolver.test.util.GenericRequirement) PackageRequirement(org.apache.felix.resolver.test.util.PackageRequirement) ResourceImpl(org.apache.felix.resolver.test.util.ResourceImpl) GenericRequirement(org.apache.felix.resolver.test.util.GenericRequirement) PackageCapability(org.apache.felix.resolver.test.util.PackageCapability) GenericCapability(org.apache.felix.resolver.test.util.GenericCapability) PackageCapability(org.apache.felix.resolver.test.util.PackageCapability) Capability(org.osgi.resource.Capability) BundleCapability(org.apache.felix.resolver.test.util.BundleCapability) PackageRequirement(org.apache.felix.resolver.test.util.PackageRequirement) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) GenericCapability(org.apache.felix.resolver.test.util.GenericCapability) BundleCapability(org.apache.felix.resolver.test.util.BundleCapability) BundleRequirement(org.apache.felix.resolver.test.util.BundleRequirement)

Example 5 with GenericRequirement

use of org.apache.felix.resolver.test.util.GenericRequirement in project felix by apache.

the class BigResolutionTest method parseRequirement.

private static void parseRequirement(ResourceImpl res, String s) throws BundleException {
    List<ClauseParser.ParsedHeaderClause> clauses = ClauseParser.parseStandardHeader(s);
    normalizeRequirementClauses(clauses);
    for (ClauseParser.ParsedHeaderClause clause : clauses) {
        for (String path : clause.paths) {
            GenericRequirement requirement = new GenericRequirement(res, path);
            for (Map.Entry<String, String> dir : clause.dirs.entrySet()) {
                requirement.addDirective(dir.getKey(), dir.getValue());
            }
            for (Map.Entry<String, Object> attr : clause.attrs.entrySet()) {
                requirement.addAttribute(attr.getKey(), attr.getValue());
            }
            res.addRequirement(requirement);
        }
    }
}
Also used : GenericRequirement(org.apache.felix.resolver.test.util.GenericRequirement) HashMap(java.util.HashMap) Map(java.util.Map) ClauseParser(org.apache.felix.resolver.test.util.ClauseParser)

Aggregations

GenericRequirement (org.apache.felix.resolver.test.util.GenericRequirement)6 ArrayList (java.util.ArrayList)4 GenericCapability (org.apache.felix.resolver.test.util.GenericCapability)4 ResourceImpl (org.apache.felix.resolver.test.util.ResourceImpl)4 Resource (org.osgi.resource.Resource)4 BundleCapability (org.apache.felix.resolver.test.util.BundleCapability)2 BundleRequirement (org.apache.felix.resolver.test.util.BundleRequirement)2 PackageCapability (org.apache.felix.resolver.test.util.PackageCapability)2 PackageRequirement (org.apache.felix.resolver.test.util.PackageRequirement)2 Capability (org.osgi.resource.Capability)2 Requirement (org.osgi.resource.Requirement)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ClauseParser (org.apache.felix.resolver.test.util.ClauseParser)1