Search in sources :

Example 1 with Table

use of org.jboss.galleon.cli.cmd.Table in project galleon by wildfly.

the class ListFeaturePacksCommand method runCommand.

@Override
public void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    Map<UniverseSpec, Table> tables = new HashMap<>();
    Map<UniverseSpec, Set<String>> exceptions = new HashMap<>();
    // Search for an installation in the context
    Path installation = null;
    try {
        installation = Util.lookupInstallationDir(invoc.getConfiguration().getAeshContext(), null);
    } catch (ProvisioningException ex) {
    // XXX OK, no installation.
    }
    Path finalPath = installation;
    UniverseVisitor visitor = new UniverseVisitor() {

        @Override
        public void visit(Producer<?> producer, FeaturePackLocation loc) {
            if (loc.getFrequency() == null) {
                return;
            }
            if (allFrequencies || loc.getFrequency().equals(producer.getDefaultFrequency())) {
                Table table = tables.get(loc.getUniverse());
                if (table == null) {
                    table = new Table(Headers.PRODUCT, Headers.UPDATE_CHANNEL, Headers.LATEST_BUILD);
                    tables.put(loc.getUniverse(), table);
                }
                loc = invoc.getPmSession().getExposedLocation(finalPath, loc);
                table.addLine(producer.getName(), StateInfoUtil.formatChannel(loc), (loc.getBuild() == null ? NONE : loc.getBuild()));
            }
        }

        @Override
        public void exception(UniverseSpec spec, Exception ex) {
            Set<String> set = exceptions.get(spec);
            if (set == null) {
                set = new HashSet<>();
                exceptions.put(spec, set);
            }
            set.add(ex.getLocalizedMessage() == null ? ex.getMessage() : ex.getLocalizedMessage());
        }
    };
    try {
        if (fromUniverse != null) {
            invoc.getPmSession().getUniverse().visitUniverse(UniverseSpec.fromString(fromUniverse), visitor, true);
        } else {
            invoc.getPmSession().getUniverse().visitAllUniverses(visitor, true, finalPath);
        }
    } catch (ProvisioningException ex) {
        throw new CommandExecutionException(invoc.getPmSession(), CliErrors.resolvedUniverseFailed(), ex);
    }
    FindCommand.printExceptions(invoc, exceptions);
    for (Entry<UniverseSpec, Table> entry : tables.entrySet()) {
        Table table = entry.getValue();
        table.sort(Table.SortType.ASCENDANT);
        invoc.println(table.build());
    }
}
Also used : Path(java.nio.file.Path) Table(org.jboss.galleon.cli.cmd.Table) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ProvisioningException(org.jboss.galleon.ProvisioningException) Producer(org.jboss.galleon.universe.Producer) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) UniverseSpec(org.jboss.galleon.universe.UniverseSpec) UniverseVisitor(org.jboss.galleon.cli.UniverseManager.UniverseVisitor)

Example 2 with Table

use of org.jboss.galleon.cli.cmd.Table in project galleon by wildfly.

the class StateInfoUtil method buildDependencies.

public static String buildDependencies(List<FeaturePackLocation> dependencies, Map<FPID, FeaturePackConfig> configs) {
    if (!dependencies.isEmpty()) {
        boolean showPatches = configs == null ? false : showPatches(configs.values());
        List<String> headers = new ArrayList<>();
        headers.add(Headers.DEPENDENCY);
        headers.add(Headers.BUILD);
        if (showPatches) {
            headers.add(Headers.PATCHES);
        }
        headers.add(Headers.UPDATE_CHANNEL);
        Table table = new Table(headers);
        for (FeaturePackLocation d : dependencies) {
            List<Cell> line = new ArrayList<>();
            line.add(new Cell(d.getProducerName()));
            line.add(new Cell(d.getBuild()));
            if (showPatches) {
                FeaturePackConfig config = configs.get(d.getFPID());
                if (config != null && config.hasPatches()) {
                    Cell patches = new Cell();
                    for (FPID p : config.getPatches()) {
                        patches.addLine(p.getBuild());
                    }
                    line.add(patches);
                }
            }
            line.add(new Cell(formatChannel(d)));
            table.addCellsLine(line);
        }
        table.sort(Table.SortType.ASCENDANT);
        return table.build();
    }
    return null;
}
Also used : Table(org.jboss.galleon.cli.cmd.Table) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ArrayList(java.util.ArrayList) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) Cell(org.jboss.galleon.cli.cmd.Table.Cell) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 3 with Table

use of org.jboss.galleon.cli.cmd.Table in project galleon by wildfly.

the class StateInfoUtil method buildFeaturePacks.

private static String buildFeaturePacks(PmCommandInvocation commandInvocation, Path installation, Collection<FeaturePackConfig> fps) {
    boolean showPatches = showPatches(fps);
    List<String> headers = new ArrayList<>();
    headers.add(Headers.PRODUCT);
    headers.add(Headers.BUILD);
    if (showPatches) {
        headers.add(Headers.PATCHES);
    }
    headers.add(Headers.UPDATE_CHANNEL);
    Table t = new Table(headers);
    for (FeaturePackConfig c : fps) {
        FeaturePackLocation loc = commandInvocation.getPmSession().getExposedLocation(installation, c.getLocation());
        List<Cell> line = new ArrayList<>();
        line.add(new Cell(loc.getProducer().getName()));
        line.add(new Cell(loc.getBuild()));
        if (showPatches) {
            if (c.hasPatches()) {
                Cell patches = new Cell();
                for (FPID p : c.getPatches()) {
                    patches.addLine(p.getBuild());
                }
                line.add(patches);
            }
        }
        line.add(new Cell(formatChannel(loc)));
        t.addCellsLine(line);
    }
    if (!t.isEmpty()) {
        t.sort(Table.SortType.ASCENDANT);
        return t.build();
    } else {
        return null;
    }
}
Also used : Table(org.jboss.galleon.cli.cmd.Table) FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ArrayList(java.util.ArrayList) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) Cell(org.jboss.galleon.cli.cmd.Table.Cell) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 4 with Table

use of org.jboss.galleon.cli.cmd.Table in project galleon by wildfly.

the class StateInfoUtil method buildConfigs.

public static String buildConfigs(Map<String, List<ConfigInfo>> configs, ProvisioningLayout<FeaturePackLayout> pLayout) throws ProvisioningException, IOException {
    if (!configs.isEmpty()) {
        boolean hasLayers = false;
        List<Table.Node> nodes = new ArrayList<>();
        Map<String, Map<String, Set<String>>> layers = LayersConfigBuilder.getAllLayers(pLayout);
        for (Entry<String, List<ConfigInfo>> entry : configs.entrySet()) {
            if (!entry.getValue().isEmpty()) {
                Table.Node model = new Table.Node(entry.getKey());
                nodes.add(model);
                for (ConfigInfo name : entry.getValue()) {
                    Table.Node nameNode = new Table.Node(name.getName());
                    model.addNext(nameNode);
                    // Compute the direct dependencies only, remove dependencies of dependencies.
                    for (ConfigId id : name.getlayers()) {
                        Map<String, Set<String>> map = layers.get(entry.getKey());
                        boolean foundAsDependency = false;
                        if (map != null) {
                            for (ConfigId l : name.getlayers()) {
                                if (l.getName().equals(id.getName())) {
                                    continue;
                                }
                                Set<String> deps = map.get(l.getName());
                                if (deps != null) {
                                    if (deps.contains(id.getName())) {
                                        foundAsDependency = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (!foundAsDependency) {
                            hasLayers = true;
                            nameNode.addNext(new Table.Node(id.getName()));
                        }
                    }
                    ConfigModel m = pLayout.getConfig().getDefinedConfig(name.getId());
                    if (m != null) {
                        if (m.hasExcludedLayers()) {
                            for (String ex : m.getExcludedLayers()) {
                                hasLayers = true;
                                nameNode.addNext(new Table.Node(ex + "(excluded)"));
                            }
                        }
                    }
                }
            }
        }
        Table.Tree table;
        if (hasLayers) {
            table = new Table.Tree(Headers.CONFIGURATION, Headers.NAME, Headers.LAYERS);
        } else {
            table = new Table.Tree(Headers.CONFIGURATION, Headers.NAME);
        }
        table.addAll(nodes);
        return "Configurations" + Config.getLineSeparator() + table.build();
    }
    return null;
}
Also used : Table(org.jboss.galleon.cli.cmd.Table) Set(java.util.Set) ArrayList(java.util.ArrayList) ConfigInfo(org.jboss.galleon.cli.model.ConfigInfo) ConfigModel(org.jboss.galleon.config.ConfigModel) List(java.util.List) ArrayList(java.util.ArrayList) ConfigId(org.jboss.galleon.config.ConfigId) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with Table

use of org.jboss.galleon.cli.cmd.Table in project galleon by wildfly.

the class StateInfoUtil method buildUniverses.

private static String buildUniverses(ProvisioningConfig config) throws ProvisioningException {
    UniverseSpec defaultUniverse = config.getDefaultUniverse();
    StringBuilder builder = new StringBuilder();
    if (defaultUniverse != null || !config.getUniverseNamedSpecs().isEmpty()) {
        builder.append("Universes").append(Config.getLineSeparator());
        Table t = new Table(Headers.NAME, Headers.UNIVERSE_FACTORY, Headers.UNIVERSE_LOCATION);
        if (defaultUniverse != null) {
            t.addLine("<default>", defaultUniverse.getFactory(), defaultUniverse.getLocation());
        }
        for (Entry<String, UniverseSpec> entry : config.getUniverseNamedSpecs().entrySet()) {
            t.addLine(entry.getKey(), entry.getValue().getFactory(), entry.getValue().getLocation());
        }
        t.sort(Table.SortType.ASCENDANT);
        builder.append(t.build());
    }
    return builder.length() == 0 ? null : builder.toString();
}
Also used : Table(org.jboss.galleon.cli.cmd.Table) UniverseSpec(org.jboss.galleon.universe.UniverseSpec)

Aggregations

Table (org.jboss.galleon.cli.cmd.Table)10 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)5 ArrayList (java.util.ArrayList)4 Cell (org.jboss.galleon.cli.cmd.Table.Cell)4 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)4 HashMap (java.util.HashMap)2 Set (java.util.Set)2 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)2 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)2 UniverseSpec (org.jboss.galleon.universe.UniverseSpec)2 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 ProvisioningException (org.jboss.galleon.ProvisioningException)1 ProvisioningOption (org.jboss.galleon.ProvisioningOption)1 UniverseVisitor (org.jboss.galleon.cli.UniverseManager.UniverseVisitor)1 MavenConfig (org.jboss.galleon.cli.config.mvn.MavenConfig)1 MavenRemoteRepository (org.jboss.galleon.cli.config.mvn.MavenRemoteRepository)1 ConfigInfo (org.jboss.galleon.cli.model.ConfigInfo)1