Search in sources :

Example 1 with PackageRequirement

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);
    }
}
Also used : PackageRequirement(org.apache.karaf.packages.core.PackageRequirement) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) KeyAlreadyExistsException(javax.management.openmbean.KeyAlreadyExistsException) TabularData(javax.management.openmbean.TabularData) OpenDataException(javax.management.openmbean.OpenDataException) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeType(javax.management.openmbean.CompositeType)

Example 2 with PackageRequirement

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;
}
Also used : ShellTable(org.apache.karaf.shell.support.table.ShellTable) PackageRequirement(org.apache.karaf.packages.core.PackageRequirement) Bundle(org.osgi.framework.Bundle) Row(org.apache.karaf.shell.support.table.Row)

Example 3 with PackageRequirement

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());
}
Also used : Bundle(org.osgi.framework.Bundle) PackageRequirement(org.apache.karaf.packages.core.PackageRequirement) BundleRevision(org.osgi.framework.wiring.BundleRevision) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) BundleRequirement(org.osgi.framework.wiring.BundleRequirement)

Example 4 with PackageRequirement

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;
}
Also used : Bundle(org.osgi.framework.Bundle) PackageRequirement(org.apache.karaf.packages.core.PackageRequirement) BundleRevision(org.osgi.framework.wiring.BundleRevision) ArrayList(java.util.ArrayList) BundleRequirement(org.osgi.framework.wiring.BundleRequirement)

Aggregations

PackageRequirement (org.apache.karaf.packages.core.PackageRequirement)4 Bundle (org.osgi.framework.Bundle)3 ArrayList (java.util.ArrayList)2 BundleRequirement (org.osgi.framework.wiring.BundleRequirement)2 BundleRevision (org.osgi.framework.wiring.BundleRevision)2 TreeMap (java.util.TreeMap)1 CompositeData (javax.management.openmbean.CompositeData)1 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)1 CompositeType (javax.management.openmbean.CompositeType)1 KeyAlreadyExistsException (javax.management.openmbean.KeyAlreadyExistsException)1 OpenDataException (javax.management.openmbean.OpenDataException)1 TabularData (javax.management.openmbean.TabularData)1 TabularDataSupport (javax.management.openmbean.TabularDataSupport)1 TabularType (javax.management.openmbean.TabularType)1 Row (org.apache.karaf.shell.support.table.Row)1 ShellTable (org.apache.karaf.shell.support.table.ShellTable)1