Search in sources :

Example 81 with Resource

use of org.osgi.resource.Resource in project bnd by bndtools.

the class ResolveTest method testDefaultVersionsForJava.

/**
	 * Missing default version
	 */
public void testDefaultVersionsForJava() throws Exception {
    Run run = Run.createRun(null, IO.getFile("testdata/defltversions/run.bndrun"));
    try (ProjectResolver pr = new ProjectResolver(run)) {
        Map<Resource, List<Wire>> resolve = pr.resolve();
        assertTrue(pr.check());
        assertNotNull(resolve);
        assertTrue(resolve.size() > 0);
        System.out.println(resolve);
    }
}
Also used : Resource(org.osgi.resource.Resource) Run(aQute.bnd.build.Run) ArrayList(java.util.ArrayList) List(java.util.List)

Example 82 with Resource

use of org.osgi.resource.Resource 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 83 with Resource

use of org.osgi.resource.Resource 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)

Example 84 with Resource

use of org.osgi.resource.Resource in project bnd by bndtools.

the class ResolveTest method getResource.

/**
	 * Check if we can resolve against capabilities defined on the -provided
	 */
// public static void testResolveWithProfile() throws Exception {
// Resolver resolver = new BndResolver(new ResolverLogger(4));
// MockRegistry registry = new MockRegistry();
// registry.addPlugin(createRepo(IO.getFile("testdata/repo3.index.xml")));
// BndEditModel model = new BndEditModel();
//
// //
// // Provided capabilities
// //
//
// model.setRunFw("org.apache.felix.framework");
// model.setGenericString(Constants.DISTRO,
// "testdata/repo1/org.apache.felix.gogo.runtime-0.10.0.jar;version=file");
//
// //
// // We require gogo, but now the gogo runtime is on the runpath
// // so should be excluded
// //
//
// Requirement erq =
// CapReqBuilder.createPackageRequirement("org.apache.felix.gogo.api",
// "0.10.0")
// .buildSyntheticRequirement();
//
// model.setRunRequires(Arrays.asList(erq));
//
// BndrunResolveContext context = new BndrunResolveContext(model, registry,
// log);
// context.setLevel(4);
// context.init();
//
// Map<Resource,List<Wire>> resolved = resolver.resolve(context);
// List<Wire> wires = resolved.get(context.getInputResource());
// assertNotNull(wires);
// boolean found = false;
// for ( Wire wire : wires ) {
// if (equals(wire.getRequirement(), erq)) {
// found = true;
// assertTrue(wire.getProvider().equals(context.getSystemResource()));
// }
// }
// assertTrue("System resource not found for wire", found);
//
// Set<Resource> resources = resolved.keySet();
// Resource resource = getResource(resources,
// "org.apache.felix.gogo.runtime", "0.10");
// assertNull(resource);
//
// }
// private static boolean equals(Requirement a, Requirement b) {
// if ( a== b)
// return true;
//
// if ( a == null || b == null)
// return false;
//
// if ( a.equals(b))
// return true;
//
// if ( !a.getNamespace().equals(b.getNamespace()))
// return false;
//
// return a.getDirectives().equals(b.getDirectives()) &&
// a.getAttributes().equals(b.getAttributes());
// }
private static Resource getResource(Set<Resource> resources, String bsn, String versionString) {
    for (Resource resource : resources) {
        List<Capability> identities = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
        if (identities != null && identities.size() == 1) {
            Capability idCap = identities.get(0);
            Object id = idCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
            Object version = idCap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
            if (bsn.equals(id)) {
                if (versionString == null) {
                    return resource;
                }
                Version requested = Version.parseVersion(versionString);
                Version current;
                if (version instanceof Version) {
                    current = (Version) version;
                } else {
                    current = Version.parseVersion((String) version);
                }
                if (requested.equals(current)) {
                    return resource;
                }
            }
        }
    }
    return null;
}
Also used : Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version) Resource(org.osgi.resource.Resource)

Example 85 with Resource

use of org.osgi.resource.Resource in project bnd by bndtools.

the class ValidatorTest method testDelibarateFailWithSpecificResources.

public void testDelibarateFailWithSpecificResources() throws Exception {
    try (ResolverValidator validator = new ResolverValidator()) {
        ResourceBuilder system = new ResourceBuilder();
        system.addEE(EE.JavaSE_1_8);
        system.addManifest(OSGI_CORE.R6_0_0.getManifest());
        validator.setSystem(system.build());
        validator.setTrace(true);
        List<Resource> resources = XMLResourceParser.getResources(IO.getFile("testdata/repo5-broken.index.xml").toURI());
        List<Resolution> resolutions = validator.validate(resources);
        assertFalse(validator.check());
        assertEquals(1, resolutions.size());
        String message = resolutions.get(0).message;
        String expectedToContain = "missing requirement org.apache.felix.gogo.api";
        assertTrue(String.format("expected to contain <%s> but was <%s>", expectedToContain, message), message.contains(expectedToContain));
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Resource(org.osgi.resource.Resource) Resolution(biz.aQute.resolve.ResolverValidator.Resolution)

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