Search in sources :

Example 1 with ResourceHandle

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;
}
Also used : ResourceHandle(aQute.bnd.service.ResourceHandle)

Example 2 with ResourceHandle

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;
}
Also used : ResourceHandle(aQute.bnd.service.ResourceHandle) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with ResourceHandle

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;
    }
}
Also used : Version(aQute.bnd.version.Version) ResourceHandle(aQute.bnd.service.ResourceHandle) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) File(java.io.File) IFile(org.eclipse.core.resources.IFile)

Example 4 with ResourceHandle

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;
}
Also used : ResourceHandle(aQute.bnd.service.ResourceHandle) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) InvocationTargetException(java.lang.reflect.InvocationTargetException) Location(aQute.bnd.service.ResourceHandle.Location)

Example 5 with ResourceHandle

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;
}
Also used : ResourceHandle(aQute.bnd.service.ResourceHandle)

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