use of org.apache.karaf.features.internal.download.Downloader in project karaf by apache.
the class SubsystemResolver method resolve.
@Override
public Map<Resource, List<Wire>> resolve(String featureResolutionRange, FeaturesService.ServiceRequirementsBehavior serviceRequirements, final Repository globalRepository, String outputFile) throws Exception {
if (root == null) {
return Collections.emptyMap();
}
// Download bundles
root.downloadBundles(manager, featureResolutionRange, serviceRequirements, new RepositoryManager(), callback);
// Populate digraph and resolve
digraph = new StandardRegionDigraph(null, null);
populateDigraph(digraph, root);
Downloader downloader = manager.createDownloader();
SubsystemResolveContext context = new SubsystemResolveContext(root, digraph, globalRepository, downloader, serviceRequirements);
if (outputFile != null) {
Map<String, Object> json = new HashMap<>();
if (globalRepository != null) {
json.put("globalRepository", toJson(globalRepository));
}
json.put("repository", toJson(context.getRepository()));
try {
// this is where the magic happens...
wiring = resolver.resolve(context);
json.put("success", "true");
json.put("wiring", toJson(wiring));
} catch (Exception e) {
json.put("success", "false");
json.put("exception", e.toString());
throw e;
} finally {
try (Writer writer = Files.newBufferedWriter(Paths.get(outputFile), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
JsonWriter.write(writer, json, true);
}
}
} else {
// this is where the magic happens...
wiring = resolver.resolve(context);
}
downloader.await();
// Remove wiring to the fake environment resource
if (environmentResource != null) {
for (List<Wire> wires : wiring.values()) {
wires.removeIf(wire -> wire.getProvider() == environmentResource);
}
}
// Fragments are always wired to their host only, so create fake wiring to
// the subsystem the host is wired to
associateFragments();
return wiring;
}
use of org.apache.karaf.features.internal.download.Downloader 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