Search in sources :

Example 1 with ResourcesRepository

use of aQute.bnd.osgi.repository.ResourcesRepository in project bnd by bndtools.

the class FileSetRepository method readFiles.

private Promise<BridgeRepository> readFiles() {
    List<Promise<Resource>> promises = new ArrayList<>(getFiles().size());
    for (File file : getFiles()) {
        promises.add(parse(Promises.resolved(file)));
    }
    Promise<List<Resource>> all = Promises.all(promises);
    return all.map(new Function<List<Resource>, BridgeRepository>() {

        @Override
        public BridgeRepository apply(List<Resource> resources) {
            try {
                ResourcesRepository rr = new ResourcesRepository();
                for (Resource r : resources) {
                    if (r != null) {
                        logger.debug("{}: adding resource {}", getName(), r);
                        rr.add(r);
                    }
                }
                return new BridgeRepository(rr);
            } catch (Exception e) {
                throw Exceptions.duck(e);
            }
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) BridgeRepository(aQute.bnd.osgi.repository.BridgeRepository) DownloadListenerPromise(aQute.bnd.util.repository.DownloadListenerPromise) Promise(org.osgi.util.promise.Promise) ArrayList(java.util.ArrayList) List(java.util.List) JarFile(java.util.jar.JarFile) File(java.io.File) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Example 2 with ResourcesRepository

use of aQute.bnd.osgi.repository.ResourcesRepository 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 3 with ResourcesRepository

use of aQute.bnd.osgi.repository.ResourcesRepository in project bnd by bndtools.

the class ProjectResolverTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    ws = Workspace.findWorkspace(IO.getFile("testdata/projectresolver/ws"));
    ws.setTrace(true);
    tmp = IO.getFile("generated/tmp");
    local = IO.getFile("generated/tmp/local");
    IO.delete(tmp);
    local.mkdirs();
    OSGiRepository or = new OSGiRepository();
    or.setRegistry(ws);
    or.setReporter(ws);
    Map<String, String> map = new HashMap<>();
    map.put("locations", "https://raw.githubusercontent.com/osgi/osgi.enroute/v1.0.0/cnf/distro/index.xml");
    map.put("name", "enroute");
    or.setProperties(map);
    fr = new ResourcesRepository();
    add(fr, IO.getFile(home, "jar/com.example.jerome.application.jar"));
    add(fr, IO.getFile(home, "jar/osgi.enroute.base.api.jar"));
    ws.addBasicPlugin(fr);
    ws.addBasicPlugin(or);
    ws.propertiesChanged();
}
Also used : HashMap(java.util.HashMap) OSGiRepository(aQute.bnd.repository.osgi.OSGiRepository) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Example 4 with ResourcesRepository

use of aQute.bnd.osgi.repository.ResourcesRepository in project bnd by bndtools.

the class ValidatorTest method testValidatingResourcesWithDocumentaryAttributes.

public void testValidatingResourcesWithDocumentaryAttributes() 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);
        ResourcesRepository repository = new ResourcesRepository();
        ResourceBuilder builder = new ResourceBuilder();
        File file = IO.getFile("testdata/osgi.cmpn-4.3.0.jar");
        builder.addFile(file, file.toURI());
        repository.add(builder.build());
        builder = new ResourceBuilder();
        file = IO.getFile("testdata/org.apache.felix.framework-4.0.0.jar");
        builder.addFile(file, file.toURI());
        repository.add(builder.build());
        List<Resource> resources = repository.getResources();
        validator.validateResources(repository, resources);
        assertTrue(validator.check());
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Resource(org.osgi.resource.Resource) File(java.io.File) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Example 5 with ResourcesRepository

use of aQute.bnd.osgi.repository.ResourcesRepository in project bnd by bndtools.

the class P2Indexer method readRepository.

private Repository readRepository() throws Exception {
    P2Impl p2 = new P2Impl(client, this.url, Processor.getExecutor());
    List<Artifact> artifacts = p2.getArtifacts();
    List<Promise<Resource>> fetched = new ArrayList<>(artifacts.size());
    Set<URI> visitedURIs = new HashSet<>(artifacts.size());
    Set<ArtifactID> visitedArtifacts = new HashSet<>(artifacts.size());
    Map<ArtifactID, Resource> knownResources = new HashMap<>();
    if (getBridge() != null) {
        for (Capability capability : getBridge().getRepository().findProviders(singleton(MD5_REQUIREMENT)).get(MD5_REQUIREMENT)) {
            Resource resource = capability.getResource();
            IdentityCapability identity = ResourceUtils.getIdentityCapability(resource);
            ArtifactID artifact = new ArtifactID(identity.osgi_identity(), identity.version(), (String) capability.getAttributes().get(MD5_ATTRIBUTE));
            knownResources.put(artifact, resource);
        }
    }
    for (final Artifact a : artifacts) {
        if (!visitedURIs.add(a.uri))
            continue;
        if (a.md5 != null) {
            ArtifactID id = new ArtifactID(a.id, toVersion(a.version), a.md5);
            if (!visitedArtifacts.add(id))
                continue;
            if (knownResources.containsKey(id)) {
                fetched.add(Promises.resolved(knownResources.get(id)));
                continue;
            }
        }
        Promise<Resource> promise = client.build().useCache(MAX_STALE).async(a.uri.toURL()).map(new Function<File, Resource>() {

            @Override
            public Resource apply(File file) {
                try {
                    ResourceBuilder rb = new ResourceBuilder();
                    rb.addFile(file, a.uri);
                    if (a.md5 != null)
                        rb.addCapability(new CapabilityBuilder(P2_CAPABILITY_NAMESPACE).addAttribute(MD5_ATTRIBUTE, a.md5));
                    return rb.build();
                } catch (Exception e) {
                    logger.debug("{}: Failed to create resource for %s from {}", name, a, file, e);
                    return RECOVERY;
                }
            }
        }).recover(new Function<Promise<?>, Resource>() {

            @Override
            public Resource apply(Promise<?> failed) {
                try {
                    logger.debug("{}: Failed to create resource for {}", name, a, failed.getFailure());
                } catch (InterruptedException e) {
                // impossible
                }
                return RECOVERY;
            }
        });
        fetched.add(promise);
    }
    Promise<List<Resource>> all = Promises.all(fetched);
    return all.map(new Function<List<Resource>, ResourcesRepository>() {

        @Override
        public ResourcesRepository apply(List<Resource> resources) {
            ResourcesRepository rr = new ResourcesRepository();
            for (Resource resource : resources) {
                if (resource != RECOVERY) {
                    rr.add(resource);
                }
            }
            return rr;
        }
    }).getValue();
}
Also used : P2Impl(aQute.p2.provider.P2Impl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CapabilityBuilder(aQute.bnd.osgi.resource.CapabilityBuilder) URI(java.net.URI) Function(org.osgi.util.function.Function) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Capability(org.osgi.resource.Capability) ContentCapability(aQute.bnd.osgi.resource.ResourceUtils.ContentCapability) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) Resource(org.osgi.resource.Resource) Artifact(aQute.p2.api.Artifact) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability) IOException(java.io.IOException) DownloadListenerPromise(aQute.bnd.util.repository.DownloadListenerPromise) Promise(org.osgi.util.promise.Promise) File(java.io.File) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository)

Aggregations

ResourcesRepository (aQute.bnd.osgi.repository.ResourcesRepository)12 File (java.io.File)7 Resource (org.osgi.resource.Resource)7 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 URI (java.net.URI)4 HashMap (java.util.HashMap)3 Promise (org.osgi.util.promise.Promise)3 BridgeRepository (aQute.bnd.osgi.repository.BridgeRepository)2 XMLResourceGenerator (aQute.bnd.osgi.repository.XMLResourceGenerator)2 CapabilityBuilder (aQute.bnd.osgi.resource.CapabilityBuilder)2 DownloadListenerPromise (aQute.bnd.util.repository.DownloadListenerPromise)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Capability (org.osgi.resource.Capability)2 Requirement (org.osgi.resource.Requirement)2