use of org.apache.felix.bundlerepository.Resource 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.Resource 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.Resource in project karaf by apache.
the class ListCommand method doExecute.
@Override
void doExecute(RepositoryAdmin admin) throws Exception {
StringBuilder substr = new StringBuilder();
if (packages != null) {
for (String packageName : packages) {
substr.append(" ");
substr.append(packageName);
}
}
String query;
if ((substr == null) || (substr.length() == 0)) {
query = "(|(presentationname=*)(symbolicname=*))";
} else {
query = "(|(presentationname=*" + substr + "*)(symbolicname=*" + substr + "*))";
}
Resource[] resources = admin.discoverResources(query);
ShellTable table = new ShellTable();
table.column("Name");
table.column("Symbolic Name");
table.column("Version");
table.emptyTableText("No matching bundles");
for (Resource resource : resources) {
table.addRow().addContent(emptyIfNull(resource.getPresentationName()), emptyIfNull(resource.getSymbolicName()), emptyIfNull(resource.getVersion()));
}
table.print(System.out, !noFormat);
}
use of org.apache.felix.bundlerepository.Resource in project felix by apache.
the class ResourceComparator method compare.
public int compare(Object o1, Object o2) {
Resource r1 = (Resource) o1;
Resource r2 = (Resource) o2;
String name1 = r1.getPresentationName();
String name2 = r2.getPresentationName();
if (name1 == null) {
if (name2 == null) {
return 0;
}
return -1;
} else if (name2 == null) {
return 1;
}
return name1.compareToIgnoreCase(name2);
}
use of org.apache.felix.bundlerepository.Resource in project felix by apache.
the class RepositoryAdminTest method testResourceFilterOnCapabilities.
public void testResourceFilterOnCapabilities() throws Exception {
URL url = getClass().getResource("/repo_for_resolvertest.xml");
RepositoryAdminImpl repoAdmin = createRepositoryAdmin();
RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url);
Resource[] resources = repoAdmin.discoverResources("(category<*dummy)");
assertNotNull(resources);
assertEquals(1, resources.length);
resources = repoAdmin.discoverResources("(category*>dummy)");
assertNotNull(resources);
assertEquals(1, resources.length);
}
Aggregations