use of org.apache.karaf.packages.core.PackageRequirement in project karaf by apache.
the class PackagesMBeanImpl method getImports.
@Override
public TabularData getImports() {
try {
String[] names = new String[] { "PackageName", "Filter", "Optional", "ID", "Bundle Name", "Resolvable" };
CompositeType bundleType = new CompositeType("PackageImports", "Imported packages", names, names, new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.LONG, SimpleType.STRING, SimpleType.BOOLEAN });
TabularType tableType = new TabularType("PackageImports", "Imported packages", bundleType, new String[] { "Filter", "ID" });
TabularData table = new TabularDataSupport(tableType);
List<PackageRequirement> imports = packageService.getImports();
for (PackageRequirement req : imports) {
Object[] data = new Object[] { req.getPackageName(), req.getFilter(), req.isOptional(), req.getBundle().getBundleId(), req.getBundle().getSymbolicName(), req.isResolveable() };
CompositeData comp = new CompositeDataSupport(bundleType, names, data);
try {
table.put(comp);
} catch (KeyAlreadyExistsException e) {
throw new RuntimeException("Id: " + req.getBundle().getBundleId() + ", filter: " + req.getFilter(), e);
}
}
return table;
} catch (RuntimeException e) {
// To avoid the exception gets swallowed by jmx
LOGGER.error(e.getMessage(), e);
throw e;
} catch (OpenDataException e) {
LOGGER.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
}
}
use of org.apache.karaf.packages.core.PackageRequirement in project karaf by apache.
the class Imports method execute.
@Override
public Object execute() throws Exception {
List<PackageRequirement> imports = packageService.getImports();
ShellTable table = new ShellTable();
if (showFilter) {
table.column("Filter");
table.column("Optional");
table.column("ID");
table.column("Bundle Name");
} else {
table.column("Package");
if (!showOnlyName) {
table.column("Version");
table.column("Optional");
table.column("ID");
table.column("Bundle Name");
}
}
for (PackageRequirement req : imports) {
if (matchesFilter(req)) {
Bundle bundle = req.getBundle();
Row row = table.addRow();
if (showFilter) {
row.addContent(req.getFilter());
row.addContent(getOptional(req), bundle.getBundleId(), bundle.getSymbolicName());
} else {
row.addContent(req.getPackageName());
if (!showOnlyName) {
row.addContent(req.getVersionRange());
row.addContent(getOptional(req), bundle.getBundleId(), bundle.getSymbolicName());
}
}
}
}
table.print(System.out, !noFormat);
return null;
}
use of org.apache.karaf.packages.core.PackageRequirement in project karaf by apache.
the class PackageServiceImpl method getImports.
@Override
public List<PackageRequirement> getImports() {
Bundle[] bundles = bundleContext.getBundles();
SortedMap<String, PackageRequirement> requirements = new TreeMap<>();
for (Bundle bundle : bundles) {
BundleRevision rev = bundle.adapt(BundleRevision.class);
if (rev != null) {
List<BundleRequirement> reqs = rev.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
for (BundleRequirement req : reqs) {
PackageRequirement preq = create(req, bundle);
requirements.put(preq.getPackageName() + "|" + preq.getFilter() + "|" + preq.getBundle().getBundleId(), preq);
}
}
}
return new ArrayList<>(requirements.values());
}
use of org.apache.karaf.packages.core.PackageRequirement in project karaf by apache.
the class PackageServiceImpl method getImports.
@Override
public List<String> getImports(long bundleId) {
Bundle bundle = bundleContext.getBundle(bundleId);
BundleRevision rev = bundle.adapt(BundleRevision.class);
List<BundleRequirement> reqs = rev.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE);
List<String> imports = new ArrayList<>();
for (BundleRequirement req : reqs) {
PackageRequirement packageReq = create(req, bundle);
imports.add(packageReq.getPackageName());
}
return imports;
}
Aggregations