use of org.apache.karaf.packages.core.PackageVersion in project karaf by apache.
the class Exports method checkDuplicateExports.
private void checkDuplicateExports() {
Bundle[] bundles = bundleContext.getBundles();
SortedMap<String, PackageVersion> packageVersionMap = getDuplicatePackages(bundles);
ShellTable table = new ShellTable();
table.column(new Col("Package Name"));
table.column(new Col("Version"));
table.column(new Col("Exporting bundles (ID)"));
for (String key : packageVersionMap.keySet()) {
PackageVersion pVer = packageVersionMap.get(key);
if (pVer.getBundles().size() > 1) {
String pBundles = getBundlesSt(pVer.getBundles());
table.addRow().addContent(pVer.getPackageName(), pVer.getVersion().toString(), pBundles);
}
}
table.print(System.out, !noFormat);
}
use of org.apache.karaf.packages.core.PackageVersion in project karaf by apache.
the class PackageTest method duplicatePackageTest.
@Test
@Ignore
public void duplicatePackageTest() throws Exception {
// Leaving out version to make test easier to manage
// We currently expect no duplicate package exports
Map<String, Integer> expectedDups = new HashMap<>();
List<PackageVersion> packageVersionMap = packageService.getExports();
for (PackageVersion pVer : packageVersionMap) {
if (pVer.getBundles().size() > 1) {
String packageName = pVer.getPackageName();
int expectedNum = expectedDups.getOrDefault(packageName, 0);
Assert.assertEquals("Expecting number of duplicates for package " + packageName, expectedNum, pVer.getBundles().size());
}
}
}
use of org.apache.karaf.packages.core.PackageVersion in project karaf by apache.
the class PackageServiceImpl method getExports.
public List<PackageVersion> getExports() {
Bundle[] bundles = bundleContext.getBundles();
SortedMap<String, PackageVersion> packageVersionMap = new TreeMap<>();
for (Bundle bundle : bundles) {
BundleRevision rev = bundle.adapt(BundleRevision.class);
if (rev != null) {
List<BundleCapability> caps = rev.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);
for (BundleCapability cap : caps) {
Map<String, Object> attr = cap.getAttributes();
String packageName = (String) attr.get(BundleRevision.PACKAGE_NAMESPACE);
Version version = (Version) attr.get("version");
String key = packageName + ":" + version.toString();
PackageVersion pVer = packageVersionMap.computeIfAbsent(key, k -> new PackageVersion(packageName, version));
pVer.addBundle(bundle);
}
}
}
return new ArrayList<>(packageVersionMap.values());
}
use of org.apache.karaf.packages.core.PackageVersion in project karaf by apache.
the class PackagesMBeanImpl method getExports.
public TabularData getExports() {
try {
String[] names = new String[] { "Name", "Version", "ID", "Bundle Name" };
CompositeType bundleType = new CompositeType("PackageExport", "Exported packages", names, new String[] { "Package name", "Version of the Package", "ID of the Bundle", "Bundle symbolic name" }, new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.LONG, SimpleType.STRING });
TabularType tableType = new TabularType("PackageExports", "Exported packages", bundleType, new String[] { "Name", "Version", "ID" });
TabularData table = new TabularDataSupport(tableType);
List<PackageVersion> exports = packageService.getExports();
for (PackageVersion export : exports) {
for (Bundle bundle : export.getBundles()) {
Object[] data = new Object[] { export.getPackageName(), export.getVersion().toString(), bundle.getBundleId(), bundle.getSymbolicName() };
CompositeData comp = new CompositeDataSupport(bundleType, names, data);
LOGGER.debug("Adding CompositeDataSupport {}", comp);
table.put(comp);
}
}
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.PackageVersion in project karaf by apache.
the class Exports method showExports.
private void showExports() {
List<PackageVersion> exports = packageService.getExports();
ShellTable table = new ShellTable();
table.column("Package Name");
if (!showOnlyName) {
table.column("Version");
table.column("ID");
table.column("Bundle Name");
}
for (PackageVersion pVer : exports) {
for (Bundle bundle : pVer.getBundles()) {
if (matchesFilter(pVer, bundle)) {
if (!showOnlyName) {
table.addRow().addContent(pVer.getPackageName(), pVer.getVersion().toString(), bundle.getBundleId(), bundle.getSymbolicName());
} else {
table.addRow().addContent(pVer.getPackageName());
}
}
}
}
table.print(System.out, !noFormat);
}
Aggregations