use of aQute.bnd.deployer.repository.api.IRepositoryContentProvider 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.IRepositoryContentProvider in project bnd by bndtools.
the class LocalIndexedRepo method loadIndexes.
@Override
protected synchronized List<URI> loadIndexes() throws Exception {
Collection<URI> remotes = super.loadIndexes();
List<URI> indexes = new ArrayList<URI>(remotes.size() + generatingProviders.size());
for (IRepositoryContentProvider contentProvider : generatingProviders) {
File indexFile = getIndexFile(contentProvider);
try {
if (indexFile.exists()) {
indexes.add(indexFile.toURI());
} else {
if (contentProvider.supportsGeneration()) {
generateIndex(indexFile, contentProvider);
indexes.add(indexFile.toURI());
}
}
} catch (Exception e) {
logService.log(LogService.LOG_ERROR, String.format("Unable to load/generate index file '%s' for repository type %s", indexFile, contentProvider.getName()), e);
}
}
indexes.addAll(remotes);
return indexes;
}
use of aQute.bnd.deployer.repository.api.IRepositoryContentProvider in project bndtools by bndtools.
the class GitOBRRepo method put.
@Override
public synchronized PutResult put(InputStream stream, PutOptions options) throws Exception {
init();
try {
repository.incrementOpen();
Git git = Git.wrap(repository);
// Pull remote repository
PullResult pullResult = git.pull().call();
// Check result
MergeResult mergeResult = pullResult.getMergeResult();
if (mergeResult != null && (mergeResult.getMergeStatus() == MergeStatus.CONFLICTING || mergeResult.getMergeStatus() == MergeStatus.FAILED)) {
// TODO: How to report failure
throw new RuntimeException(String.format("Failed to merge changes from %s", gitUri));
}
// TODO: Check if jar already exists, is it ok to overwrite in all repositories?
PutResult result = super.put(stream, options);
if (result.artifact != null) {
File newFile = new File(result.artifact);
// Add, Commit and Push
for (IRepositoryContentProvider provider : generatingProviders) {
if (!provider.supportsGeneration())
continue;
git.add().addFilepattern(getRelativePath(gitRootDir, newFile)).addFilepattern(getRelativePath(gitRootDir, new File(provider.getDefaultIndexName(pretty)))).call();
}
git.commit().setMessage("bndtools added bundle : " + getRelativePath(gitRootDir, newFile)).call();
git.push().setCredentialsProvider(CredentialsProvider.getDefault()).call();
// Re-read the index
reset();
init();
}
return result;
} finally {
if (repository != null) {
repository.close();
}
}
}
use of aQute.bnd.deployer.repository.api.IRepositoryContentProvider in project bnd by bndtools.
the class RepoResourceUtils method readIndex.
public static void readIndex(String name, URI baseUri, InputStream stream, Collection<IRepositoryContentProvider> contentProviders, IRepositoryIndexProcessor listener, LogService log) throws Exception {
// Make sure we have a buffering stream
try (InputStream bufferedStream = stream.markSupported() ? stream : new BufferedInputStream(stream)) {
// Find a compatible content provider for the input
IRepositoryContentProvider selectedProvider = null;
IRepositoryContentProvider maybeSelectedProvider = null;
for (IRepositoryContentProvider provider : contentProviders) {
CheckResult checkResult;
try {
bufferedStream.mark(READ_AHEAD_MAX);
checkResult = provider.checkStream(name, new ProtectedStream(bufferedStream));
} finally {
bufferedStream.reset();
}
if (checkResult.getDecision() == Decision.accept) {
selectedProvider = provider;
break;
} else if (checkResult.getDecision() == Decision.undecided) {
log.log(LogService.LOG_WARNING, String.format("Content provider '%s' was unable to determine compatibility with index at URL '%s': %s", provider.getName(), baseUri, checkResult.getMessage()));
if (maybeSelectedProvider == null)
maybeSelectedProvider = provider;
}
}
// undecided provider, with an appropriate warning.
if (selectedProvider == null) {
if (maybeSelectedProvider != null) {
selectedProvider = maybeSelectedProvider;
log.log(LogService.LOG_WARNING, String.format("No content provider matches the specified index unambiguously. Selected '%s' arbitrarily.", selectedProvider.getName()));
} else {
throw new IOException("Invalid repository index: no configured content provider understands the specified index.");
}
}
// Finally, parse the damn file.
selectedProvider.parseIndex(bufferedStream, baseUri, listener, log);
}
}
Aggregations