List<Resource> deploy = new ArrayList<Resource>();
Map<Object, BundleInfo> infos = new HashMap<Object, BundleInfo>();
for (BundleInfo bundleInfo : feature.getBundles()) {
try {
URL url = new URL(bundleInfo.getLocation());
Resource res = repositoryAdmin.getHelper().createResource(url);
ress.add(res);
infos.put(res, bundleInfo);
} catch (MalformedURLException e) {
Requirement req = parseRequirement(bundleInfo.getLocation());
reqs.add(req);
infos.put(req, bundleInfo);
}
}
Repository repository = repositoryAdmin.getHelper().repository(ress.toArray(new Resource[ress.size()]));
List<Repository> repos = new ArrayList<Repository>();
repos.add(repositoryAdmin.getSystemRepository());
repos.add(repositoryAdmin.getLocalRepository());
repos.add(repository);
repos.addAll(Arrays.asList(repositoryAdmin.listRepositories()));
org.apache.felix.bundlerepository.Resolver resolver = repositoryAdmin.resolver(repos.toArray(new Repository[repos.size()]));
for (Resource res : ress) {
if (!infos.get(res).isDependency()) {
resolver.add(res);
}
}
for (Requirement req : reqs) {
resolver.add(req);
}
if (!resolver.resolve(org.apache.felix.bundlerepository.Resolver.NO_OPTIONAL_RESOURCES)) {
StringWriter w = new StringWriter();
PrintWriter out = new PrintWriter(w);
Reason[] failedReqs = resolver.getUnsatisfiedRequirements();
if ((failedReqs != null) && (failedReqs.length > 0)) {
out.println("Unsatisfied requirement(s):");
printUnderline(out, 27);
for (Reason r : failedReqs) {
out.println(" " + r.getRequirement().getName() + ":" + r.getRequirement().getFilter());
out.println(" " + r.getResource().getPresentationName());
}
} else {
out.println("Could not resolve targets.");
}
out.flush();
throw new Exception("Can not resolve feature:\n" + w.toString());
}
List<BundleInfo> bundles = new ArrayList<BundleInfo>();
Collections.addAll(deploy, resolver.getAddedResources());
Collections.addAll(deploy, resolver.getRequiredResources());
for (Resource res : deploy) {
BundleInfo info = infos.get(res);
if (info == null) {
Reason[] reasons = resolver.getReason(res);
if (reasons != null) {
for (Reason r : reasons) {
info = infos.get(r);
if (info != null) {
break;
}
}
}
}
if (info == null) {
info = new BundleInfoImpl(res.getURI());
}
bundles.add(info);
}
return bundles;
}