Search in sources :

Example 1 with Location

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

the class RepositoryEntry method isLocal.

public final boolean isLocal() {
    boolean result = true;
    try {
        if (repo instanceof RemoteRepositoryPlugin) {
            ResourceHandle handle = ((RemoteRepositoryPlugin) repo).getHandle(bsn, versionFinder.versionSpec, versionFinder.strategy, Collections.<String, String>emptyMap());
            Location location = handle.getLocation();
            result = location == Location.local || location == Location.remote_cached;
        }
    } catch (Exception e) {
        logger.logError(MessageFormat.format("Failed to query repository {0} for bundle {1} version {2}.", repo.getName(), bsn, versionFinder), e);
    }
    return result;
}
Also used : ResourceHandle(aQute.bnd.service.ResourceHandle) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) Location(aQute.bnd.service.ResourceHandle.Location)

Example 2 with Location

use of aQute.bnd.service.ResourceHandle.Location 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

RemoteRepositoryPlugin (aQute.bnd.service.RemoteRepositoryPlugin)2 ResourceHandle (aQute.bnd.service.ResourceHandle)2 Location (aQute.bnd.service.ResourceHandle.Location)2 RepositoryBundle (bndtools.model.repo.RepositoryBundle)1 RepositoryBundleVersion (bndtools.model.repo.RepositoryBundleVersion)1 LinkedList (java.util.LinkedList)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