Map<String, Map<VersionRange, Map<String, String>>> metadata,
DeploymentDownloadListener listener) throws IOException, MultiException, InterruptedException, ResolutionException {
this.downloader = new AgentUtils.FileDownloader(manager);
this.resources = new ConcurrentHashMap<String, Resource>();
this.providers = new ConcurrentHashMap<String, StreamProvider>();
this.requirements = new ResourceImpl("dummy", "dummy", Version.emptyVersion);
this.metadata = metadata;
// First, gather all bundle resources
for (String feature : features) {
registerMatchingFeatures(feature);
}
for (String bundle : bundles) {
downloadAndBuildResource(bundle, listener);
}
for (String fab : fabs) {
downloadAndBuildResource(FAB_PROTOCOL + fab, listener);
}
for (String req : reqs) {
downloadAndBuildResource(REQ_PROTOCOL + req, listener);
}
for (String override : overrides) {
// TODO: ignore download failures for overrides
downloadAndBuildResource(extractUrl(override), listener);
}
for (String optional : optionals) {
downloadAndBuildResource(optional, listener);
}
// Wait for all resources to be created
downloader.await();
// Do override replacement
for (String override : overrides) {
Resource over = resources.remove(extractUrl(override));
if (over == null) {
// Ignore invalid overrides
continue;
}
for (String uri : new ArrayList<String>(resources.keySet())) {
Resource res = resources.get(uri);
if (getSymbolicName(res).equals(getSymbolicName(over))) {
VersionRange range;
String vr = extractVersionRange(override);
if (vr == null) {
// default to micro version compatibility
Version v1 = getVersion(res);
Version v2 = new Version(v1.getMajor(), v1.getMinor() + 1, 0);
range = new VersionRange(false, v1, v2, true);
} else {
range = VersionRange.parseVersionRange(vr);
}
// The resource matches, so replace it with the overridden resource
// if the override is actually a newer version than what we currently have
if (range.contains(getVersion(res)) && getVersion(res).compareTo(getVersion(over)) < 0) {
resources.put(uri, over);
}
}
}
}
// Build features resources
for (Feature feature : featuresToRegister) {
ResourceImpl resource = FeatureResource.build(feature, featureRange, resources);
resources.put("feature:" + feature.getName() + "/" + feature.getVersion(), resource);
for (Conditional cond : feature.getConditional()) {
Feature featCond = cond.asFeature(feature.getName(), feature.getVersion());
FeatureResource resCond = FeatureResource.build(feature, cond, featureRange, resources);
requireFeature(featCond.getName() + "/" + featCond.getVersion(), resource, true);