use of org.osgi.framework.Bundle in project karaf by apache.
the class ObrCommandSupport method searchRepository.
protected Resource[] searchRepository(RepositoryAdmin admin, String targetId, String targetVersion) throws InvalidSyntaxException {
// Try to see if the targetId is a bundle ID.
try {
Bundle bundle = bundleContext.getBundle(Long.parseLong(targetId));
targetId = bundle.getSymbolicName();
} catch (NumberFormatException ex) {
// It was not a number, so ignore.
}
// The targetId may be a bundle name or a bundle symbolic name,
// so create the appropriate LDAP query.
StringBuffer sb = new StringBuffer("(|(presentationname=");
sb.append(targetId);
sb.append(")(symbolicname=");
sb.append(targetId);
sb.append("))");
if (targetVersion != null) {
sb.insert(0, "(&");
sb.append("(version=");
sb.append(targetVersion);
sb.append("))");
}
return admin.discoverResources(sb.toString());
}
use of org.osgi.framework.Bundle in project karaf by apache.
the class Converters method convertBundle.
private Object convertBundle(Object in) {
String s = in.toString();
try {
long id = Long.parseLong(s);
return context.getBundle(id);
} catch (NumberFormatException nfe) {
// Ignore
}
Bundle[] bundles = context.getBundles();
for (Bundle b : bundles) {
if (b.getLocation().equals(s)) {
return b;
}
if (b.getSymbolicName().equals(s)) {
return b;
}
}
return null;
}
use of org.osgi.framework.Bundle in project karaf by apache.
the class BundleHelpProvider method getHelp.
@Override
public String getHelp(Session session, String path) {
if (path.indexOf('|') > 0) {
if (path.startsWith("bundle|")) {
path = path.substring("bundle|".length());
} else {
return null;
}
}
if (path.matches("[0-9]*")) {
long id = Long.parseLong(path);
BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
Bundle bundle = bundleContext.getBundle(id);
if (bundle != null) {
String title = ShellUtil.getBundleName(bundle);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
ps.println("\n" + title);
ps.println(ShellUtil.getUnderlineString(title));
URL bundleInfo = bundle.getEntry("OSGI-INF/bundle.info");
if (bundleInfo != null) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(bundleInfo.openStream()))) {
int maxSize = 80;
Terminal terminal = session.getTerminal();
if (terminal != null) {
maxSize = terminal.getWidth();
}
WikiVisitor visitor = new AnsiPrintingWikiVisitor(ps, maxSize);
WikiParser parser = new WikiParser(visitor);
parser.parse(reader);
} catch (Exception e) {
// ignore
}
}
ps.close();
return baos.toString();
}
}
return null;
}
use of org.osgi.framework.Bundle in project karaf by apache.
the class ShowBundleTree method createNodeForImport.
/*
* Create a child node for a given import (by finding a matching export in the currently installed bundles)
*/
private void createNodeForImport(Node<Bundle> node, Bundle bundle, Clause i) {
VersionRange range = VersionRange.parseVersionRange(i.getAttribute(Constants.VERSION_ATTRIBUTE));
boolean foundMatch = false;
for (Bundle b : bundleContext.getBundles()) {
BundleWiring wiring = b.adapt(BundleWiring.class);
if (wiring != null) {
List<BundleCapability> caps = wiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE);
if (caps != null) {
for (BundleCapability cap : caps) {
String n = getAttribute(cap, BundleRevision.PACKAGE_NAMESPACE);
String v = getAttribute(cap, Constants.VERSION_ATTRIBUTE);
if (i.getName().equals(n) && range.contains(VersionTable.getVersion(v))) {
boolean existing = tree.flatten().contains(b);
System.out.printf("- import %s: resolved using %s%n", i, b);
foundMatch = true;
if (!node.hasChild(b)) {
Node<Bundle> child = node.addChild(b);
if (!existing) {
createNode(child);
}
}
}
}
}
}
}
if (!foundMatch) {
System.out.printf("- import %s: WARNING - unable to find matching export%n", i);
}
}
use of org.osgi.framework.Bundle in project karaf by apache.
the class ShowBundleTree method createNode.
/*
* Creates a node in the bundle tree
*/
private void createNode(Node<Bundle> node) {
Bundle bundle = node.getValue();
Collection<Bundle> exporters = new HashSet<>();
exporters.addAll(bundleService.getWiredBundles(bundle).values());
for (Bundle exporter : exporters) {
if (node.hasAncestor(exporter)) {
LOGGER.debug(format("Skipping %s (already exists in the current branch)", exporter));
} else {
boolean existing = tree.flatten().contains(exporter);
LOGGER.debug(format("Adding %s as a dependency for %s", exporter, bundle));
Node<Bundle> child = node.addChild(exporter);
if (existing) {
LOGGER.debug(format("Skipping children of %s (already exists in another branch)", exporter));
} else {
createNode(child);
}
}
}
}
Aggregations