Search in sources :

Example 76 with Resource

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

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

the class FileSetRepository method get.

private Promise<File> get(final String bsn, final Version version) throws Exception {
    logger.debug("{}: get {} {}", getName(), bsn, version);
    Resource resource = getBridge().get(bsn, version);
    if (resource == null) {
        logger.debug("{}: resource not found {} {}", getName(), bsn, version);
        return null;
    }
    ContentCapability content = ResourceUtils.getContentCapability(resource);
    if (content == null) {
        logger.warn("{}: No content capability for {}", getName(), resource);
        return null;
    }
    URI uri = content.url();
    if (uri == null) {
        logger.warn("{}: No content URI for {}", getName(), resource);
        return null;
    }
    logger.debug("{}: get returning {}", getName(), uri);
    return Promises.resolved(new File(uri));
}
Also used : Resource(org.osgi.resource.Resource) URI(java.net.URI) JarFile(java.util.jar.JarFile) File(java.io.File) ContentCapability(aQute.bnd.osgi.resource.ResourceUtils.ContentCapability)

Example 78 with Resource

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

the class InfoRepositoryWrapper method init.

boolean init() {
    try {
        if (System.currentTimeMillis() < lastTime + 10000)
            return true;
    } finally {
        lastTime = System.currentTimeMillis();
    }
    Set<String> errors = new LinkedHashSet<String>();
    try {
        //
        // Get the current repo contents
        //
        Set<String> toBeDeleted = new HashSet<String>(persistent.keySet());
        Map<String, DownloadBlocker> blockers = new HashMap<String, DownloadBlocker>();
        for (InfoRepository repo : repos) {
            Map<String, ResourceDescriptor> map = collectKeys(repo);
            for (final Map.Entry<String, ResourceDescriptor> entry : map.entrySet()) {
                final String id = entry.getKey();
                toBeDeleted.remove(id);
                if (persistent.containsKey(id))
                    continue;
                final ResourceDescriptor rd = entry.getValue();
                DownloadBlocker blocker = new DownloadBlocker(null) {

                    //
                    // We steal the thread of the downloader to index
                    //
                    @Override
                    public void success(File file) throws Exception {
                        IndexResult index = null;
                        try {
                            index = repoIndexer.indexFile(file);
                            ResourceBuilder rb = new ResourceBuilder();
                            for (org.osgi.service.indexer.Capability capability : index.capabilities) {
                                CapReqBuilder cb = new CapReqBuilder(capability.getNamespace());
                                cb.addAttributes(capability.getAttributes());
                                cb.addDirectives(capability.getDirectives());
                                rb.addCapability(cb.buildSyntheticCapability());
                            }
                            for (org.osgi.service.indexer.Requirement requirement : index.requirements) {
                                CapReqBuilder cb = new CapReqBuilder(requirement.getNamespace());
                                cb.addAttributes(requirement.getAttributes());
                                cb.addDirectives(requirement.getDirectives());
                                rb.addRequirement(cb.buildSyntheticRequirement());
                            }
                            Resource resource = rb.build();
                            PersistentResource pr = new PersistentResource(resource);
                            persistent.put(id, pr);
                        } finally {
                            super.success(file);
                            if (index != null) {
                                index.resource.close();
                            }
                        }
                    }
                };
                blockers.put(entry.getKey(), blocker);
                repo.get(rd.bsn, rd.version, null, blocker);
            }
        }
        for (Entry<String, DownloadBlocker> entry : blockers.entrySet()) {
            String key = entry.getKey();
            DownloadBlocker blocker = entry.getValue();
            String reason = blocker.getReason();
            if (reason != null) {
                errors.add(key + ": " + reason);
            }
        }
        persistent.keySet().removeAll(toBeDeleted);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (!errors.isEmpty())
        throw new IllegalStateException("Cannot index " + repos + " due to " + errors);
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) IndexResult(org.osgi.service.indexer.ResourceIndexer.IndexResult) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) PersistentResource(aQute.bnd.osgi.resource.PersistentResource) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) PersistentResource(aQute.bnd.osgi.resource.PersistentResource) Resource(org.osgi.resource.Resource) DownloadBlocker(aQute.bnd.build.DownloadBlocker) InfoRepository(aQute.bnd.service.repository.InfoRepository) IOException(java.io.IOException) HashMap(java.util.HashMap) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map) PersistentMap(aQute.lib.persistentmap.PersistentMap) File(java.io.File) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 79 with Resource

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

the class PomRepository method read.

void read() throws Exception {
    if (isStale()) {
        refresh();
    } else {
        try (XMLResourceParser parser = new XMLResourceParser(getLocation())) {
            List<Resource> resources = parser.parse();
            addAll(resources);
        }
    }
}
Also used : Resource(org.osgi.resource.Resource) XMLResourceParser(aQute.bnd.osgi.repository.XMLResourceParser)

Example 80 with Resource

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

the class SearchRepository method read.

void read() throws Exception {
    if (isStale()) {
        refresh();
    } else {
        try (XMLResourceParser parser = new XMLResourceParser(getLocation())) {
            List<Resource> resources = parser.parse();
            addAll(resources);
        }
    }
}
Also used : Resource(org.osgi.resource.Resource) XMLResourceParser(aQute.bnd.osgi.repository.XMLResourceParser)

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