use of org.apache.felix.bundlerepository.Resolver in project karaf by apache.
the class ObrMBeanImpl method deployBundle.
public void deployBundle(String bundle, boolean start, boolean deployOptional) throws MBeanException {
try {
Resolver resolver = repositoryAdmin.resolver();
String[] target = getTarget(bundle);
Resource resource = selectNewestVersion(searchRepository(repositoryAdmin, target[0], target[1]));
if (resource == null) {
throw new IllegalArgumentException("Unknown bundle " + target[0]);
}
resolver.add(resource);
if ((resolver.getAddedResources() != null) && (resolver.getAddedResources().length > 0)) {
if (resolver.resolve(deployOptional ? 0 : Resolver.NO_OPTIONAL_RESOURCES)) {
try {
resolver.deploy(start ? Resolver.START : 0);
} catch (IllegalStateException ex) {
throw new IllegalStateException("Can't deploy using OBR", ex);
}
}
}
} catch (Exception e) {
throw new MBeanException(null, e.toString());
}
}
use of org.apache.felix.bundlerepository.Resolver in project karaf by apache.
the class ObrCommandSupport method doDeploy.
protected void doDeploy(RepositoryAdmin admin, List<String> bundles, boolean start, boolean deployOptional) throws Exception {
Resolver resolver = admin.resolver();
for (String bundle : bundles) {
String[] target = getTarget(bundle);
Resource resource = selectNewestVersion(searchRepository(admin, target[0], target[1]));
if (resource != null) {
resolver.add(resource);
} else {
System.err.println("Unknown bundle - " + target[0]);
}
}
if ((resolver.getAddedResources() != null) && (resolver.getAddedResources().length > 0)) {
if (resolver.resolve(deployOptional ? 0 : Resolver.NO_OPTIONAL_RESOURCES)) {
System.out.println("Target resource(s):");
printUnderline(System.out, 19);
Resource[] resources = resolver.getAddedResources();
for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
System.out.println(" " + getResourceId(resources[resIdx]) + " (" + resources[resIdx].getVersion() + ")");
}
resources = resolver.getRequiredResources();
if ((resources != null) && (resources.length > 0)) {
System.out.println("\nRequired resource(s):");
printUnderline(System.out, 21);
for (Resource resource : resources) {
System.out.println(" " + getResourceId(resource) + " (" + resource.getVersion() + ")");
}
}
if (deployOptional) {
resources = resolver.getOptionalResources();
if ((resources != null) && (resources.length > 0)) {
System.out.println("\nOptional resource(s):");
printUnderline(System.out, 21);
for (Resource resource : resources) {
System.out.println(" " + getResourceId(resource) + " (" + resource.getVersion() + ")");
}
}
}
try {
System.out.print("\nDeploying...");
resolver.deploy(start ? Resolver.START : 0);
System.out.println("done.");
} catch (IllegalStateException ex) {
System.err.println(ex);
}
} else {
Reason[] reqs = resolver.getUnsatisfiedRequirements();
if ((reqs != null) && (reqs.length > 0)) {
System.out.println("Unsatisfied requirement(s):");
printUnderline(System.out, 27);
for (Reason req : reqs) {
System.out.println(" " + req.getRequirement().getFilter());
System.out.println(" " + getResourceId(req.getResource()));
}
} else {
System.out.println("Could not resolve targets.");
}
}
}
}
use of org.apache.felix.bundlerepository.Resolver in project karaf by apache.
the class ResolveCommand method doExecute.
protected void doExecute(RepositoryAdmin admin) throws Exception {
List<Repository> repositories = new ArrayList<>();
repositories.add(admin.getSystemRepository());
if (!noLocal) {
repositories.add(admin.getLocalRepository());
}
if (!noRemote) {
repositories.addAll(Arrays.asList(admin.listRepositories()));
}
Resolver resolver = admin.resolver(repositories.toArray(new Repository[repositories.size()]));
for (Requirement requirement : parseRequirements(admin, requirements)) {
resolver.add(requirement);
}
if (resolver.resolve(optional ? 0 : Resolver.NO_OPTIONAL_RESOURCES)) {
Resource[] resources;
resources = resolver.getRequiredResources();
if ((resources != null) && (resources.length > 0)) {
System.out.println("Required resource(s):");
printUnderline(System.out, 21);
for (Resource resource : resources) {
System.out.println(" " + resource.getPresentationName() + " (" + resource.getVersion() + ")");
if (why) {
Reason[] req = resolver.getReason(resource);
for (int reqIdx = 0; req != null && reqIdx < req.length; reqIdx++) {
if (!req[reqIdx].getRequirement().isOptional()) {
Resource r = req[reqIdx].getResource();
if (r != null) {
System.out.println(" - " + r.getPresentationName() + " / " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
} else {
System.out.println(" - " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
}
}
}
}
}
}
resources = resolver.getOptionalResources();
if ((resources != null) && (resources.length > 0)) {
System.out.println();
System.out.println("Optional resource(s):");
printUnderline(System.out, 21);
for (Resource resource : resources) {
System.out.println(" " + resource.getPresentationName() + " (" + resource.getVersion() + ")");
if (why) {
Reason[] req = resolver.getReason(resource);
for (int reqIdx = 0; req != null && reqIdx < req.length; reqIdx++) {
if (!req[reqIdx].getRequirement().isOptional()) {
Resource r = req[reqIdx].getResource();
if (r != null) {
System.out.println(" - " + r.getPresentationName() + " / " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
} else {
System.out.println(" - " + req[reqIdx].getRequirement().getName() + ":" + req[reqIdx].getRequirement().getFilter());
}
}
}
}
}
}
if (deploy || start) {
try {
System.out.print("\nDeploying...");
resolver.deploy(start ? Resolver.START : 0);
System.out.println("done.");
} catch (IllegalStateException ex) {
System.err.println(ex);
}
}
} else {
Reason[] reqs = resolver.getUnsatisfiedRequirements();
if ((reqs != null) && (reqs.length > 0)) {
System.out.println("Unsatisfied requirement(s):");
printUnderline(System.out, 27);
for (Reason req : reqs) {
System.out.println(" " + req.getRequirement().getName() + ":" + req.getRequirement().getFilter());
System.out.println(" " + req.getResource().getPresentationName());
}
} else {
System.out.println("Could not resolve targets.");
}
}
}
Aggregations