use of aQute.bnd.deployer.repository.api.IRepositoryIndexProcessor in project bnd by bndtools.
the class AbstractIndexedRepo method init.
protected final synchronized void init(boolean ignoreCachedFile) throws Exception {
if (!initialised) {
clear();
// Load the available providers from the workspace plugins.
loadAllContentProviders();
// Load the request repository content providers, if specified
if (requestedContentProviderList != null && requestedContentProviderList.length() > 0) {
generatingProviders.clear();
// Find the requested providers from the available ones.
StringTokenizer tokenizer = new StringTokenizer(requestedContentProviderList, "|");
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken().trim();
IRepositoryContentProvider provider = allContentProviders.get(token);
if (provider == null) {
warning("Unknown repository content provider \"%s\".", token);
} else {
generatingProviders.add(provider);
}
}
if (generatingProviders.isEmpty()) {
warning("No valid repository index generators were found, requested list was: [%s]", requestedContentProviderList);
}
}
// Initialise index locations
indexLocations = loadIndexes();
// Create the callback for new referral and resource objects
final URLConnector connector = getConnector();
IRepositoryIndexProcessor processor = new IRepositoryIndexProcessor() {
public void processResource(Resource resource) {
identityMap.put(resource);
capabilityIndex.addResource(resource);
}
public void processReferral(URI parentUri, Referral referral, int maxDepth, int currentDepth) {
try {
URI indexLocation = new URI(referral.getUrl());
try {
CachingUriResourceHandle indexHandle = new CachingUriResourceHandle(indexLocation, getCacheDirectory(), connector, (String) null);
indexHandle.setReporter(reporter);
InputStream indexStream = GZipUtils.detectCompression(IO.stream(indexHandle.request()));
readIndex(indexLocation.getPath(), indexLocation, indexStream, allContentProviders.values(), this, logService);
} catch (Exception e) {
warning("Unable to read referral index at URL '%s' from parent index '%s': %s", indexLocation, parentUri, e);
}
} catch (URISyntaxException e) {
warning("Invalid referral URL '%s' from parent index '%s': %s", referral.getUrl(), parentUri, e);
}
}
};
// Parse the indexes
for (URI indexLocation : indexLocations) {
try {
CachingUriResourceHandle indexHandle = new CachingUriResourceHandle(indexLocation, getCacheDirectory(), connector, (String) null);
// OR 2) online is false
if (indexHandle.cachedFile != null && !ignoreCachedFile && ((System.currentTimeMillis() - indexHandle.cachedFile.lastModified() < this.cacheTimeoutSeconds * 1000) || !this.online)) {
indexHandle.sha = indexHandle.getCachedSHA();
if (indexHandle.sha != null && !this.online) {
System.out.println(String.format("Offline. Using cached %s.", indexLocation));
}
}
indexHandle.setReporter(reporter);
File indexFile = indexHandle.request();
InputStream indexStream = GZipUtils.detectCompression(IO.stream(indexFile));
readIndex(indexFile.getName(), indexLocation, indexStream, allContentProviders.values(), processor, logService);
} catch (Exception e) {
error("Unable to read index at URL '%s': %s", indexLocation, e);
}
}
initialised = true;
}
}
use of aQute.bnd.deployer.repository.api.IRepositoryIndexProcessor in project bnd by bndtools.
the class TestObrCapReqParsing method parseIndex.
private static List<Resource> parseIndex(InputStream stream, URI baseUri) throws Exception {
ObrContentProvider parser = new ObrContentProvider(new BundleIndexerImpl());
final List<Resource> resources = new LinkedList<Resource>();
IRepositoryIndexProcessor processor = new IRepositoryIndexProcessor() {
public void processResource(Resource resource) {
resources.add(resource);
}
public void processReferral(URI parentUri, Referral referral, int maxDepth, int currentDepth) {
}
};
parser.parseIndex(stream, baseUri, processor, new NullLogService());
return resources;
}
use of aQute.bnd.deployer.repository.api.IRepositoryIndexProcessor in project bndtools by bndtools.
the class WorkspaceR5Repository method loadProjectIndex.
public void loadProjectIndex(final IProject project, InputStream index, URI baseUri) {
synchronized (projectMap) {
try {
cleanProject(project);
IRepositoryIndexProcessor processor = new IRepositoryIndexProcessor() {
@Override
public void processResource(Resource resource) {
addResource(project, resource);
}
@Override
public void processReferral(URI parentUri, Referral referral, int maxDepth, int currentDepth) {
// ignore: we don't create any referrals
}
};
contentProvider.parseIndex(index, baseUri, processor, logAdapter);
} catch (Exception e) {
logger.logError(MessageFormat.format("Failed to process index file for bundles in project {0}.", project.getName()), e);
} finally {
IO.close(index);
}
}
}
Aggregations