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());
}
}
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;
}
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;
}
}
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;
}
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();
}
Aggregations