Search in sources :

Example 6 with MockRegistry

use of test.lib.MockRegistry in project bnd by bndtools.

the class BndrunResolveContextTest method testResolveSystemBundleAlias.

public static void testResolveSystemBundleAlias() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework");
    runModel.setEE(EE.JavaSE_1_6);
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    Requirement req = new CapReqBuilder("osgi.wiring.host").addDirective("filter", "(osgi.wiring.host=system.bundle)").buildSyntheticRequirement();
    List<Capability> providers = context.findProviders(req);
    assertEquals(1, providers.size());
    assertEquals(IO.getFile("testdata/repo3/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) MockRegistry(test.lib.MockRegistry) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 7 with MockRegistry

use of test.lib.MockRegistry in project bnd by bndtools.

the class BndrunResolveContextTest method testJREPackageNotResolved.

public static void testJREPackageNotResolved() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework");
    // javax.annotation added in Java 6
    runModel.setEE(EE.J2SE_1_5);
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    Requirement req = CapReqBuilder.createPackageRequirement("javax.annotation", null).buildSyntheticRequirement();
    List<Capability> providers = context.findProviders(req);
    assertEquals(0, providers.size());
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) MockRegistry(test.lib.MockRegistry) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 8 with MockRegistry

use of test.lib.MockRegistry in project bnd by bndtools.

the class BndrunResolveContextTest method testFrameworkCapabilitiesPreferredOverRepository.

public static void testFrameworkCapabilitiesPreferredOverRepository() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/osgi.cmpn-4.3.0.index.xml")));
    registry.addPlugin(createRepo(IO.getFile("testdata/org.apache.felix.framework-4.0.2.index.xml")));
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework");
    Requirement requirement = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(&(osgi.wiring.package=org.osgi.util.tracker)(version>=1.5)(!(version>=1.6)))").buildSyntheticRequirement();
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    List<Capability> providers = context.findProviders(requirement);
    assertEquals(2, providers.size());
    assertEquals(IO.getFile("testdata/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
    assertEquals(IO.getFile("testdata/osgi.cmpn-4.3.0.jar").toURI(), findContentURI(providers.get(1).getResource()));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) MockRegistry(test.lib.MockRegistry) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 9 with MockRegistry

use of test.lib.MockRegistry in project bnd by bndtools.

the class BndrunResolveContextTest method testResolverHookCannotFilterFrameworkCapabilities.

public static void testResolverHookCannotFilterFrameworkCapabilities() {
    MockRegistry registry = new MockRegistry();
    registry.addPlugin(createRepo(IO.getFile("testdata/osgi.cmpn-4.3.0.index.xml")));
    registry.addPlugin(createRepo(IO.getFile("testdata/org.apache.felix.framework-4.0.2.index.xml")));
    // Add a hook that tries to remove all capabilities from resource with
    // id "org.apache.felix.framework"
    registry.addPlugin(new ResolverHook() {

        public void filterMatches(Requirement requirement, List<Capability> candidates) {
            for (Iterator<Capability> iter = candidates.iterator(); iter.hasNext(); ) {
                Object id = iter.next().getResource().getCapabilities("osgi.identity").get(0).getAttributes().get("osgi.identity");
                if ("org.apache.felix.framework".equals(id)) {
                    fail("this line should not be reached");
                }
            }
        }
    });
    BndEditModel runModel = new BndEditModel();
    runModel.setRunFw("org.apache.felix.framework");
    Requirement requirement = new CapReqBuilder("osgi.wiring.package").addDirective("filter", "(&(osgi.wiring.package=org.osgi.util.tracker)(version>=1.5)(!(version>=1.6)))").buildSyntheticRequirement();
    BndrunResolveContext context = new BndrunResolveContext(runModel, registry, log);
    List<Capability> providers = context.findProviders(requirement);
    // The filter was ineffective
    assertEquals(2, providers.size());
    assertEquals(IO.getFile("testdata/org.apache.felix.framework-4.0.2.jar").toURI(), findContentURI(providers.get(0).getResource()));
    assertEquals(IO.getFile("testdata/osgi.cmpn-4.3.0.jar").toURI(), findContentURI(providers.get(1).getResource()));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) ResolverHook(aQute.bnd.service.resolve.hook.ResolverHook) MockRegistry(test.lib.MockRegistry) Iterator(java.util.Iterator) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 10 with MockRegistry

use of test.lib.MockRegistry in project bnd by bndtools.

the class BndrunResolveContextTest method testEffective3.

public static void testEffective3() {
    BndEditModel model = new BndEditModel();
    model.genericSet(BndrunResolveContext.RUN_EFFECTIVE_INSTRUCTION, "active;skip:=\"filtered.ns,another.filtered.ns\", arbitrary");
    BndrunResolveContext context = new BndrunResolveContext(model, new MockRegistry(), log);
    Requirement resolveReq = new CapReqBuilder("dummy.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, Namespace.EFFECTIVE_RESOLVE).buildSyntheticRequirement();
    Requirement activeReq = new CapReqBuilder("dummy.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, Namespace.EFFECTIVE_ACTIVE).buildSyntheticRequirement();
    Requirement filteredActiveReq = new CapReqBuilder("filtered.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, Namespace.EFFECTIVE_ACTIVE).buildSyntheticRequirement();
    Requirement anotherFilteredActiveReq = new CapReqBuilder("another.filtered.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, Namespace.EFFECTIVE_ACTIVE).buildSyntheticRequirement();
    Requirement arbitrary1Req = new CapReqBuilder("dummy.ns").addDirective(Namespace.REQUIREMENT_EFFECTIVE_DIRECTIVE, "arbitrary").buildSyntheticRequirement();
    Requirement noEffectiveDirectiveReq = new CapReqBuilder("dummy.ns").buildSyntheticRequirement();
    assertTrue(context.isEffective(resolveReq));
    assertTrue(context.isEffective(activeReq));
    assertTrue(context.isEffective(arbitrary1Req));
    assertFalse(context.isEffective(filteredActiveReq));
    assertFalse(context.isEffective(anotherFilteredActiveReq));
    assertTrue(context.isEffective(noEffectiveDirectiveReq));
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) MockRegistry(test.lib.MockRegistry) BndEditModel(aQute.bnd.build.model.BndEditModel)

Aggregations

MockRegistry (test.lib.MockRegistry)41 BndEditModel (aQute.bnd.build.model.BndEditModel)34 Requirement (org.osgi.resource.Requirement)32 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)28 Capability (org.osgi.resource.Capability)26 IdentityCapability (aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)25 Resource (org.osgi.resource.Resource)15 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)7 List (java.util.List)6 Resolver (org.osgi.service.resolver.Resolver)6 Processor (aQute.bnd.osgi.Processor)5 File (java.io.File)4 ExportedPackage (aQute.bnd.build.model.clauses.ExportedPackage)2 Parameters (aQute.bnd.header.Parameters)2 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)2 ResolverHook (aQute.bnd.service.resolve.hook.ResolverHook)2 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 Iterator (java.util.Iterator)2