use of org.apache.felix.bundlerepository.Resource in project aries by apache.
the class FelixResourceAdapterTest method testGetCapabilitiesWithNullNamespace.
@Test
public void testGetCapabilitiesWithNullNamespace() {
Resource resource = EasyMock.createNiceMock(Resource.class);
Capability capability = EasyMock.createNiceMock(Capability.class);
EasyMock.expect(capability.getName()).andReturn(Capability.PACKAGE);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(Capability.PACKAGE, "org.foo.bar");
EasyMock.expect(capability.getPropertiesAsMap()).andReturn(properties);
Capability[] capabilities = new Capability[] { capability };
EasyMock.expect(resource.getCapabilities()).andReturn(capabilities);
EasyMock.replay(resource);
FelixResourceAdapter adapter = new FelixResourceAdapter(resource);
List<org.osgi.resource.Capability> caps = adapter.getCapabilities(null);
// osgi.identity, osgi.content. osgi.wiring.host, and osgi.wiring.package
assertEquals("Null namespace should return all capabilities", 4, caps.size());
}
use of org.apache.felix.bundlerepository.Resource 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.");
}
}
}
use of org.apache.felix.bundlerepository.Resource in project karaf by apache.
the class SourceCommand method doExecute.
protected void doExecute(RepositoryAdmin admin) throws Exception {
for (String bundle : bundles) {
String[] target = getTarget(bundle);
Resource resource = selectNewestVersion(searchRepository(admin, target[0], target[1]));
if (resource == null) {
System.err.println("Unknown bundle and/or version: " + target[0]);
} else {
URI srcURL = (URI) resource.getProperties().get(Resource.SOURCE_URI);
if (srcURL != null) {
FileUtil.downloadSource(System.out, System.err, srcURL.toURL(), localDir, extract);
} else {
System.err.println("Missing source URL: " + target[0]);
}
}
}
}
use of org.apache.felix.bundlerepository.Resource in project karaf by apache.
the class ObrMBeanImpl method getBundles.
public TabularData getBundles() throws MBeanException {
try {
CompositeType bundleType = new CompositeType("OBR Resource", "Bundle available in the OBR", new String[] { "presentationname", "symbolicname", "version" }, new String[] { "Presentation Name", "Symbolic Name", "Version" }, new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING });
TabularType tableType = new TabularType("OBR Resources", "Table of all resources/bundles available in the OBR", bundleType, new String[] { "symbolicname", "version" });
TabularData table = new TabularDataSupport(tableType);
Resource[] resources = repositoryAdmin.discoverResources("(|(presentationname=*)(symbolicname=*))");
for (Resource resource : resources) {
try {
CompositeData data = new CompositeDataSupport(bundleType, new String[] { "presentationname", "symbolicname", "version" }, new Object[] { resource.getPresentationName(), resource.getSymbolicName(), resource.getVersion().toString() });
table.put(data);
} catch (Exception e) {
e.printStackTrace();
}
}
return table;
} catch (Exception e) {
throw new MBeanException(null, e.toString());
}
}
use of org.apache.felix.bundlerepository.Resource in project felix by apache.
the class FelixBundleRepositoryRenderHelper method toJSON.
private final void toJSON(JSONWriter writer, Resource resource, Bundle[] bundles, boolean details) throws IOException {
final String symbolicName = resource.getSymbolicName();
final Version version = resource.getVersion();
String installed = "";
for (int i = 0; symbolicName != null && installed.length() == 0 && bundles != null && i < bundles.length; i++) {
final Version ver = bundles[i].getVersion();
if (symbolicName.equals(bundles[i].getSymbolicName())) {
installed = ver.toString();
}
}
writer.object();
// $NON-NLS-1$
writer.key("id");
writer.value(resource.getId());
// $NON-NLS-1$
writer.key("presentationname");
writer.value(resource.getPresentationName());
// $NON-NLS-1$
writer.key("symbolicname");
writer.value(symbolicName);
// $NON-NLS-1$
writer.key("url");
writer.value(resource.getURI());
// $NON-NLS-1$
writer.key("version");
writer.value(version);
// $NON-NLS-1$
writer.key("categories");
writer.value(resource.getCategories());
// $NON-NLS-1$
writer.key("installed");
writer.value(installed);
if (details) {
Capability[] caps = resource.getCapabilities();
if (caps != null) {
// $NON-NLS-1$
writer.key("capabilities");
writer.array();
for (int i = 0; i < caps.length; i++) {
writer.object();
// $NON-NLS-1$
writer.key("name");
writer.value(caps[i].getName());
// $NON-NLS-1$
writer.key("properties");
toJSON(writer, caps[i].getProperties());
writer.endObject();
}
writer.endArray();
}
Requirement[] reqs = resource.getRequirements();
if (reqs != null) {
// $NON-NLS-1$
writer.key("requirements");
writer.array();
for (int i = 0; i < reqs.length; i++) {
writer.object();
// $NON-NLS-1$
writer.key("name");
writer.value(reqs[i].getName());
// $NON-NLS-1$
writer.key("filter");
writer.value(reqs[i].getFilter());
// $NON-NLS-1$
writer.key("optional");
writer.value(reqs[i].isOptional());
writer.endObject();
}
writer.endArray();
}
final RepositoryAdmin admin = (RepositoryAdmin) getRepositoryAdmin();
Resolver resolver = admin.resolver();
resolver.add(resource);
resolver.resolve(Resolver.NO_OPTIONAL_RESOURCES);
Resource[] required = resolver.getRequiredResources();
if (required != null) {
// $NON-NLS-1$
writer.key("required");
writer.array();
for (int i = 0; required != null && i < required.length; i++) {
toJSON(writer, required[i], bundles, false);
}
writer.endArray();
}
Resource[] optional = resolver.getOptionalResources();
if (optional != null) {
// $NON-NLS-1$
writer.key("optional");
writer.array();
for (int i = 0; optional != null && i < optional.length; i++) {
toJSON(writer, optional[i], bundles, false);
}
writer.endArray();
}
Reason[] unsatisfied = resolver.getUnsatisfiedRequirements();
if (unsatisfied != null) {
// $NON-NLS-1$
writer.key("unsatisfied");
writer.array();
for (int i = 0; unsatisfied != null && i < unsatisfied.length; i++) {
writer.object();
// $NON-NLS-1$
writer.key("name");
writer.value(unsatisfied[i].getRequirement().getName());
// $NON-NLS-1$
writer.key("filter");
writer.value(unsatisfied[i].getRequirement().getFilter());
// $NON-NLS-1$
writer.key("optional");
writer.value(unsatisfied[i].getRequirement().isOptional());
writer.endObject();
}
writer.endArray();
}
}
writer.endObject();
}
Aggregations