Search in sources :

Example 6 with Col

use of org.apache.karaf.shell.support.table.Col in project karaf by apache.

the class List method execute.

@Override
public Object execute() throws Exception {
    ShellTable table = new ShellTable();
    table.column(new Col("ID"));
    table.column(new Col("State"));
    table.column(new Col("Web-State"));
    table.column(new Col("Level"));
    table.column(new Col("Web-ContextPath"));
    table.column(new Col("Name"));
    java.util.List<WebBundle> webBundles = webContainerService.list();
    if (webBundles != null && !webBundles.isEmpty()) {
        for (WebBundle webBundle : webBundles) {
            table.addRow().addContent(webBundle.getBundleId(), webBundle.getState(), webBundle.getWebState(), webBundle.getLevel(), webBundle.getContextPath(), webBundle.getName());
        }
    }
    table.print(System.out, !noFormat);
    return null;
}
Also used : Col(org.apache.karaf.shell.support.table.Col) ShellTable(org.apache.karaf.shell.support.table.ShellTable) WebBundle(org.apache.karaf.web.WebBundle)

Example 7 with Col

use of org.apache.karaf.shell.support.table.Col in project karaf by apache.

the class List method doExecute.

@Override
protected Object doExecute(java.util.List<Bundle> bundles) throws Exception {
    if (noFormat) {
        noEllipsis = true;
    }
    determineBundleLevelThreshold();
    // Display active start level.
    FrameworkStartLevel fsl = this.bundleContext.getBundle(0).adapt(FrameworkStartLevel.class);
    if (fsl != null) {
        System.out.println("START LEVEL " + fsl.getStartLevel() + " , List Threshold: " + bundleLevelThreshold);
    }
    ShellTable table = new ShellTable();
    if (!noEllipsis && terminal != null && terminal.getWidth() > 0) {
        table.size(terminal.getWidth() - 1);
    }
    table.column("ID").alignRight();
    table.column("State");
    table.column("Lvl").alignRight();
    table.column("Version");
    boolean effectiveShowName = showName || (!showLocation && !showSymbolic && !showUpdate && !showRevisions);
    if (effectiveShowName) {
        table.column("Name");
    }
    if (showLocation) {
        table.column(new Col("Location") {

            @Override
            protected String cut(String value, int size) {
                if (showLocation && value.length() > size) {
                    String[] parts = value.split("/");
                    String cut = "";
                    int c = parts[0].length() + 4;
                    for (int idx = parts.length - 1; idx > 0; idx--) {
                        if (cut.length() + c + parts[idx].length() + 1 < size) {
                            cut = "/" + parts[idx] + cut;
                        } else {
                            break;
                        }
                    }
                    cut = parts[0] + "/..." + cut;
                    return cut;
                } else {
                    return super.cut(value, size);
                }
            }
        });
    }
    if (showSymbolic) {
        table.column("Symbolic name");
    }
    if (showUpdate) {
        table.column("Update location");
    }
    if (showRevisions) {
        table.column("Revisions");
    }
    for (Bundle bundle : bundles) {
        BundleInfo info = this.bundleService.getInfo(bundle);
        if (info.getStartLevel() >= bundleLevelThreshold) {
            String version = info.getVersion();
            ArrayList<Object> rowData = new ArrayList<>();
            rowData.add(info.getBundleId());
            rowData.add(getStateString(info.getState()));
            rowData.add(info.getStartLevel());
            rowData.add(version);
            if (effectiveShowName) {
                String bundleName = (info.getName() == null) ? info.getSymbolicName() : info.getName();
                bundleName = (bundleName == null) ? info.getUpdateLocation() : bundleName;
                String name = bundleName + printFragments(info) + printHosts(info);
                rowData.add(name);
            }
            if (showLocation) {
                rowData.add(info.getUpdateLocation());
            }
            if (showSymbolic) {
                rowData.add(info.getSymbolicName() == null ? "<no symbolic name>" : info.getSymbolicName());
            }
            if (showUpdate) {
                rowData.add(info.getUpdateLocation());
            }
            if (showRevisions) {
                rowData.add(info.getRevisions());
            }
            Row row = table.addRow();
            row.addContent(rowData);
        }
    }
    table.print(System.out, !noFormat);
    return null;
}
Also used : Col(org.apache.karaf.shell.support.table.Col) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) FrameworkStartLevel(org.osgi.framework.startlevel.FrameworkStartLevel) ShellTable(org.apache.karaf.shell.support.table.ShellTable) BundleInfo(org.apache.karaf.bundle.core.BundleInfo) Row(org.apache.karaf.shell.support.table.Row)

Aggregations

Col (org.apache.karaf.shell.support.table.Col)7 ShellTable (org.apache.karaf.shell.support.table.ShellTable)7 Bundle (org.osgi.framework.Bundle)2 Provider (java.security.Provider)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 BundleInfo (org.apache.karaf.bundle.core.BundleInfo)1 ServletInfo (org.apache.karaf.http.core.ServletInfo)1 PackageVersion (org.apache.karaf.packages.core.PackageVersion)1 Terminal (org.apache.karaf.shell.api.console.Terminal)1 Row (org.apache.karaf.shell.support.table.Row)1 WebBundle (org.apache.karaf.web.WebBundle)1 FrameworkStartLevel (org.osgi.framework.startlevel.FrameworkStartLevel)1 CredentialSource (org.wildfly.security.credential.source.CredentialSource)1 CredentialStore (org.wildfly.security.credential.store.CredentialStore)1