Search in sources :

Example 6 with ResourceHandle

use of aQute.bnd.service.ResourceHandle in project bnd by bndtools.

the class AbstractIndexedRepo method get.

/**
	 * This can be optimized to use the download technique with the listeners.
	 * Now just a quick hack to make it work. I actually think these classes
	 * should extend FileRepo. TODO
	 */
public File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception {
    init();
    String versionStr;
    if (version != null)
        versionStr = version.toString();
    else
        versionStr = properties.get(PROP_VERSION_KEY);
    ResourceHandle handle = resolveBundle(bsn, versionStr, Strategy.EXACT, properties);
    if (handle == null)
        return null;
    File f = handle.request();
    if (f == null)
        return null;
    for (DownloadListener l : listeners) {
        try {
            l.success(f);
        } catch (Exception e) {
            error("Download listener for %s: %s", f, e);
        }
    }
    return f;
}
Also used : ResourceHandle(aQute.bnd.service.ResourceHandle) File(java.io.File) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException)

Example 7 with ResourceHandle

use of aQute.bnd.service.ResourceHandle in project bnd by bndtools.

the class LocalIndexedRepo method tooltip.

public String tooltip(Object... target) throws Exception {
    if (target == null || target.length == 0)
        return "LocalIndexedRepo @ " + getLocation();
    if (target.length == 2) {
        ResourceHandle h = getHandle(target);
        if (h == null) {
            regenerateAllIndexes();
            refresh();
            return null;
        }
        if (h.getLocation() == Location.remote) {
            return h.getName() + " (remote, not yet cached)";
        }
        return h.request().getAbsolutePath() + "\n" + SHA1.digest(h.request()).asHex() + "\n" + h.getLocation();
    }
    return null;
}
Also used : ResourceHandle(aQute.bnd.service.ResourceHandle)

Example 8 with ResourceHandle

use of aQute.bnd.service.ResourceHandle in project bnd by bndtools.

the class LocalIndexedRepo method getHandle.

private ResourceHandle getHandle(Object... target) throws Exception {
    String bsn = (String) target[0];
    Version v = (Version) target[1];
    VersionRange r = new VersionRange("[" + v.getWithoutQualifier() + "," + v.getWithoutQualifier() + "]");
    ResourceHandle[] handles = getHandles(bsn, r.toString());
    if (handles == null || handles.length == 0) {
        return null;
    }
    ResourceHandle h = handles[0];
    return h;
}
Also used : Version(aQute.bnd.version.Version) ResourceHandle(aQute.bnd.service.ResourceHandle) VersionRange(aQute.bnd.version.VersionRange)

Example 9 with ResourceHandle

use of aQute.bnd.service.ResourceHandle in project bndtools by bndtools.

the class RepoDownloadJob method run.

@Override
protected IStatus run(IProgressMonitor progress) {
    SubMonitor monitor = SubMonitor.convert(progress);
    boolean locked = LOCK.tryLock();
    try {
        while (!locked) {
            monitor.setBlocked(new Status(IStatus.INFO, Plugin.PLUGIN_ID, 0, "Waiting for other download jobs to complete.", null));
            if (progress.isCanceled())
                return Status.CANCEL_STATUS;
            try {
                locked = LOCK.tryLock(5, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
            }
        }
        monitor.clearBlocked();
        MultiStatus status = new MultiStatus(Plugin.PLUGIN_ID, 0, "One or more repository files failed to download.", null);
        monitor.setTaskName("Expanding repository contents");
        List<RepositoryBundleVersion> rbvs = new LinkedList<RepositoryBundleVersion>();
        try {
            for (RemoteRepositoryPlugin repo : repos) {
                expandContentsInto(repo, rbvs);
            }
            for (RepositoryBundle bundle : bundles) {
                expandContentsInto(bundle, rbvs);
            }
            rbvs.addAll(bundleVersions);
        } catch (Exception e) {
            return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error listing repository contents", e);
        }
        monitor.setWorkRemaining(rbvs.size());
        for (RepositoryBundleVersion rbv : rbvs) {
            if (monitor.isCanceled())
                return Status.CANCEL_STATUS;
            String resourceName = "<<unknown>>";
            try {
                RemoteRepositoryPlugin repo = (RemoteRepositoryPlugin) rbv.getRepo();
                ResourceHandle handle = repo.getHandle(rbv.getBsn(), rbv.getVersion().toString(), Strategy.EXACT, Collections.<String, String>emptyMap());
                resourceName = handle.getName();
                Location location = handle.getLocation();
                if (location == Location.remote) {
                    monitor.setTaskName("Downloading " + handle.getName());
                    handle.request();
                }
            } catch (Exception e) {
                status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, String.format("Download of %s:%s with remote name %s failed", rbv.getBsn(), rbv.getVersion(), resourceName), e));
            } finally {
                monitor.worked(1);
            }
        }
        return status;
    } finally {
        if (locked)
            LOCK.unlock();
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) RepositoryBundle(bndtools.model.repo.RepositoryBundle) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) SubMonitor(org.eclipse.core.runtime.SubMonitor) MultiStatus(org.eclipse.core.runtime.MultiStatus) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) LinkedList(java.util.LinkedList) ResourceHandle(aQute.bnd.service.ResourceHandle) Location(aQute.bnd.service.ResourceHandle.Location)

Aggregations

ResourceHandle (aQute.bnd.service.ResourceHandle)9 RemoteRepositoryPlugin (aQute.bnd.service.RemoteRepositoryPlugin)3 Location (aQute.bnd.service.ResourceHandle.Location)2 Version (aQute.bnd.version.Version)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 VersionRange (aQute.bnd.version.VersionRange)1 RepositoryBundle (bndtools.model.repo.RepositoryBundle)1 RepositoryBundleVersion (bndtools.model.repo.RepositoryBundleVersion)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 LinkedList (java.util.LinkedList)1 IFile (org.eclipse.core.resources.IFile)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 Status (org.eclipse.core.runtime.Status)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1