use of aQute.bnd.service.ResourceHandle in project bnd by bndtools.
the class AbstractIndexedRepo method resolveBundle.
ResourceHandle resolveBundle(String bsn, String rangeStr, Strategy strategy, Map<String, String> properties) throws Exception {
if (rangeStr == null)
rangeStr = "0.0.0";
if (PROP_VERSION_HASH.equals(rangeStr)) {
return findByHash(bsn, properties);
}
if (strategy == Strategy.EXACT) {
return findExactMatch(bsn, rangeStr);
}
ResourceHandle[] handles = getHandles(bsn, rangeStr);
ResourceHandle selected;
if (handles == null || handles.length == 0)
selected = null;
else {
switch(strategy) {
case LOWEST:
selected = handles[0];
break;
default:
selected = handles[handles.length - 1];
}
}
return selected;
}
use of aQute.bnd.service.ResourceHandle in project bnd by bndtools.
the class AbstractIndexedRepo method mapResourceToHandle.
ResourceHandle mapResourceToHandle(Resource resource) throws Exception {
ResourceHandle result = null;
CachingUriResourceHandle handle;
try {
String contentSha = getContentSha(resource);
handle = new CachingUriResourceHandle(getContentUrl(resource), getCacheDirectory(), getConnector(), contentSha);
if (contentSha == null) {
handle.sha = handle.getCachedSHA();
}
} catch (FileNotFoundException e) {
throw new FileNotFoundException("Broken link in repository index: " + e);
}
if (handle.getLocation() == Location.local || getCacheDirectory() != null)
result = handle;
return result;
}
use of aQute.bnd.service.ResourceHandle in project bndtools by bndtools.
the class RepositoryEntry method getFile.
public final File getFile(boolean forceDownload) {
File result;
try {
if (repo instanceof RemoteRepositoryPlugin) {
ResourceHandle handle = ((RemoteRepositoryPlugin) repo).getHandle(bsn, versionFinder.versionSpec, versionFinder.strategy, Collections.<String, String>emptyMap());
switch(handle.getLocation()) {
case local:
case remote_cached:
result = handle.request();
break;
default:
result = forceDownload ? handle.request() : null;
}
} else {
Version version = versionFinder.findVersion();
result = (version != null) ? repo.get(bsn, version, Collections.<String, String>emptyMap()) : null;
}
return result;
} catch (Exception e) {
logger.logError(MessageFormat.format("Failed to query repository {0} for bundle {1} version {2}.", repo.getName(), bsn, versionFinder), e);
return null;
}
}
use of aQute.bnd.service.ResourceHandle 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;
}
use of aQute.bnd.service.ResourceHandle in project bnd by bndtools.
the class AbstractIndexedRepo method getHandle.
public ResourceHandle getHandle(String bsn, String range, Strategy strategy, Map<String, String> properties) throws Exception {
init();
ResourceHandle result;
if (bsn != null)
result = resolveBundle(bsn, range, strategy, properties);
else {
throw new IllegalArgumentException("Cannot resolve bundle: bundle symbolic name not specified.");
}
return result;
}
Aggregations