Search in sources :

Example 1 with ContentCapability

use of aQute.bnd.osgi.resource.ResourceUtils.ContentCapability 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 2 with ContentCapability

use of aQute.bnd.osgi.resource.ResourceUtils.ContentCapability in project bnd by bndtools.

the class OSGiIndex method get.

Promise<File> get(String bsn, Version version, File file) throws Exception {
    Resource resource = getBridge().get(bsn, version);
    if (resource == null)
        return null;
    ContentCapability content = ResourceUtils.getContentCapability(resource);
    if (content == null) {
        logger.warn("{}: No content capability for {}", name, resource);
        return null;
    }
    URI url = content.url();
    if (url == null) {
        logger.warn("{}: No content capability for {}", name, resource);
        return null;
    }
    return client.build().useCache(file, staleTime).async(url);
}
Also used : Resource(org.osgi.resource.Resource) URI(java.net.URI) ContentCapability(aQute.bnd.osgi.resource.ResourceUtils.ContentCapability)

Example 3 with ContentCapability

use of aQute.bnd.osgi.resource.ResourceUtils.ContentCapability in project bnd by bndtools.

the class P2Indexer method get.

File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception {
    Resource resource = getBridge().get(bsn, version);
    if (resource == null)
        return null;
    ContentCapability contentCapability = ResourceUtils.getContentCapability(resource);
    if (contentCapability == null)
        return null;
    URI url = contentCapability.url();
    final File source = client.getCacheFileFor(url);
    final File link = new File(location, bsn + "-" + version + ".jar");
    IO.createSymbolicLinkOrCopy(link, source);
    Promise<File> go = client.build().useCache(MAX_STALE).async(url.toURL()).map(new Function<File, File>() {

        @Override
        public File apply(File t) {
            return link;
        }
    });
    if (listeners.length == 0)
        return go.getValue();
    new DownloadListenerPromise(reporter, name + ": get " + bsn + ";" + version + " " + url, go, listeners);
    return link;
}
Also used : Resource(org.osgi.resource.Resource) DownloadListenerPromise(aQute.bnd.util.repository.DownloadListenerPromise) URI(java.net.URI) File(java.io.File) ContentCapability(aQute.bnd.osgi.resource.ResourceUtils.ContentCapability)

Example 4 with ContentCapability

use of aQute.bnd.osgi.resource.ResourceUtils.ContentCapability in project bnd by bndtools.

the class ResourceImpl method getContent.

@Override
public InputStream getContent() {
    try {
        ContentCapability c = ResourceUtils.getContentCapability(this);
        URI url = c.url();
        return url.toURL().openStream();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : URI(java.net.URI) ContentCapability(aQute.bnd.osgi.resource.ResourceUtils.ContentCapability)

Aggregations

ContentCapability (aQute.bnd.osgi.resource.ResourceUtils.ContentCapability)4 URI (java.net.URI)4 Resource (org.osgi.resource.Resource)3 File (java.io.File)2 DownloadListenerPromise (aQute.bnd.util.repository.DownloadListenerPromise)1 JarFile (java.util.jar.JarFile)1