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;
}
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;
}
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;
}
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();
}
}
Aggregations