Search in sources :

Example 6 with Row

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

the class TablesCommand method execute.

@Override
public Object execute() throws Exception {
    ShellTable table = new ShellTable();
    Map<String, List<String>> map = this.getJdbcService().tables(datasource);
    int rowCount = 0;
    for (String column : map.keySet()) {
        table.column(column);
        rowCount = map.get(column).size();
    }
    for (int i = 0; i < rowCount; i++) {
        Row row = table.addRow();
        for (String column : map.keySet()) {
            row.addContent(map.get(column).get(i));
        }
    }
    table.print(System.out);
    return null;
}
Also used : ShellTable(org.apache.karaf.shell.support.table.ShellTable) List(java.util.List) Row(org.apache.karaf.shell.support.table.Row)

Example 7 with Row

use of org.apache.karaf.shell.support.table.Row 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)

Example 8 with Row

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

the class RepoListCommand method doExecute.

protected void doExecute(FeaturesService featuresService) throws Exception {
    if (reload) {
        reloadAllRepos(featuresService);
    }
    ShellTable table = new ShellTable();
    table.column("Repository");
    table.column("URL");
    if (showBlacklisted) {
        table.column("Blacklisted");
    }
    table.emptyTableText("No repositories available");
    Repository[] repos = featuresService.listRepositories();
    for (Repository repo : repos) {
        if (repo != null) {
            if (showBlacklisted || !repo.isBlacklisted()) {
                Row row = table.addRow();
                row.addContent(repo.getName(), repo.getURI().toString());
                if (showBlacklisted) {
                    row.addContent(repo.isBlacklisted() ? "yes" : "no");
                }
            }
        }
    }
    table.print(System.out, !noFormat);
}
Also used : Repository(org.apache.karaf.features.Repository) ShellTable(org.apache.karaf.shell.support.table.ShellTable) Row(org.apache.karaf.shell.support.table.Row)

Example 9 with Row

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

the class HttpProxyListCommand method doAction.

@Override
public void doAction(String prefix, Dictionary<String, Object> config) throws Exception {
    System.out.println();
    if (mavenSettings != null && mavenSettings.getProxies() != null && mavenSettings.getProxies().size() > 0) {
        ShellTable table = new ShellTable();
        table.column("ID");
        table.column("Host");
        table.column("Port");
        table.column("Non-proxy hosts");
        table.column("Username");
        if (showPasswords) {
            table.column("Password");
        }
        for (Proxy _p : mavenSettings.getProxies()) {
            Row row = table.addRow();
            row.addContent(_p.getId(), _p.getHost(), _p.getPort(), _p.getNonProxyHosts());
            row.addContent(_p.getUsername() != null ? _p.getUsername() : "");
            if (showPasswords) {
                addPasswordInfo(row, proxyPasswords, _p.getId(), _p.getPassword());
            }
        }
        table.print(System.out);
    } else {
        System.out.print("No HTTP proxies configured");
        if (settings != null && settings.value != null) {
            System.out.print(" in " + settings.value);
        }
        System.out.println();
    }
    System.out.println();
}
Also used : Proxy(org.apache.maven.settings.Proxy) ShellTable(org.apache.karaf.shell.support.table.ShellTable) Row(org.apache.karaf.shell.support.table.Row)

Example 10 with Row

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

the class SummaryCommand method addRow.

/**
 * Helper to add row to {@link ShellTable}
 * @param table
 * @param label
 * @param value
 * @param descriptionText
 */
private <T> void addRow(ShellTable table, String label, SourceAnd<T> value, String descriptionText) {
    Row row = table.addRow();
    row.addContent(label, value.val());
    if (source) {
        row.addContent(value.source);
    }
    if (description) {
        row.addContent(descriptionText);
    }
}
Also used : Row(org.apache.karaf.shell.support.table.Row)

Aggregations

Row (org.apache.karaf.shell.support.table.Row)11 ShellTable (org.apache.karaf.shell.support.table.ShellTable)10 List (java.util.List)2 Repository (org.apache.karaf.features.Repository)2 Bundle (org.osgi.framework.Bundle)2 Attribute (ddf.catalog.data.Attribute)1 Result (ddf.catalog.data.Result)1 SortByImpl (ddf.catalog.filter.impl.SortByImpl)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 SourceResponse (ddf.catalog.operation.SourceResponse)1 QueryImpl (ddf.catalog.operation.impl.QueryImpl)1 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)1 AccessControlContext (java.security.AccessControlContext)1 Principal (java.security.Principal)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Subject (javax.security.auth.Subject)1 BundleInfo (org.apache.karaf.bundle.core.BundleInfo)1