use of org.apache.karaf.features.internal.download.StreamProvider in project karaf by apache.
the class VerifyMojo method loadRepositories.
public Map<String, Features> loadRepositories(DownloadManager manager, Set<String> uris) throws Exception {
final Map<String, Features> loaded = new HashMap<>();
final Downloader downloader = manager.createDownloader();
FeaturesServiceConfig config = null;
if (featureProcessingInstructions != null) {
config = new FeaturesServiceConfig(featureProcessingInstructions.toURI().toString(), null);
} else {
config = new FeaturesServiceConfig();
}
FeaturesProcessorImpl processor = new FeaturesProcessorImpl(config);
if (blacklistedDescriptors != null) {
blacklistedDescriptors.forEach(lp -> processor.getInstructions().getBlacklistedRepositoryLocationPatterns().add(new LocationPattern(lp)));
}
processor.getInstructions().getBlacklistedRepositoryLocationPatterns().add(new LocationPattern("mvn:" + selfGroupId + "/" + selfArtifactId));
for (String repository : uris) {
if (!processor.isRepositoryBlacklisted(repository)) {
downloader.download(repository, new DownloadCallback() {
@Override
public void downloaded(final StreamProvider provider) throws Exception {
synchronized (loaded) {
// If provider was already loaded, no need to do it again.
if (loaded.containsKey(provider.getUrl())) {
return;
}
}
try (InputStream is = provider.open()) {
Features featuresModel;
if (JacksonUtil.isJson(provider.getUrl())) {
featuresModel = JacksonUtil.unmarshal(provider.getUrl());
} else {
featuresModel = JaxbUtil.unmarshal(provider.getUrl(), is, false);
}
processor.process(featuresModel);
synchronized (loaded) {
loaded.put(provider.getUrl(), featuresModel);
for (String innerRepository : featuresModel.getRepository()) {
if (!processor.isRepositoryBlacklisted(innerRepository)) {
downloader.download(innerRepository, this);
}
}
}
}
}
});
}
}
downloader.await();
return loaded;
}
Aggregations