use of org.jboss.galleon.cli.model.ConfigInfo in project galleon by wildfly.
the class FeatureContainerPathConsumer method enterConfigurationName.
// @Override
public void enterConfigurationName(String name) throws PathConsumerException {
List<ConfigInfo> configs = info.getFinalConfigs().get(configModel);
for (ConfigInfo c : configs) {
if (c.getName().equals(name)) {
config = c;
break;
}
}
if (config == null) {
if (completion) {
if (inError) {
throw new PathConsumerException("no config for name " + name);
} else {
inError = true;
}
} else {
throw new PathConsumerException("no config for name " + name);
}
}
configName = name;
configModel = null;
}
use of org.jboss.galleon.cli.model.ConfigInfo in project galleon by wildfly.
the class GetInfoCommand method displayConfigs.
private boolean displayConfigs(PmCommandInvocation commandInvocation, ProvisioningLayout<FeaturePackLayout> pLayout) throws ProvisioningException, IOException {
Map<String, List<ConfigInfo>> configs = new HashMap<>();
try (ProvisioningRuntime rt = ProvisioningRuntimeBuilder.newInstance(commandInvocation.getPmSession().getMessageWriter(false)).initRtLayout(pLayout.transform(ProvisioningRuntimeBuilder.FP_RT_FACTORY)).build()) {
for (ProvisionedConfig m : rt.getConfigs()) {
String model = m.getModel();
List<ConfigInfo> names = configs.get(model);
if (names == null) {
names = new ArrayList<>();
configs.put(model, names);
}
if (m.getName() != null) {
names.add(new ConfigInfo(model, m.getName(), m.getLayers()));
}
}
String str = StateInfoUtil.buildConfigs(configs, pLayout);
if (str != null) {
commandInvocation.print(str);
}
return str != null;
}
}
use of org.jboss.galleon.cli.model.ConfigInfo 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.model.ConfigInfo in project galleon by wildfly.
the class StateAddFeatureCommand method getConfiguration.
private ConfigInfo getConfiguration(State state) throws PathParserException, PathConsumerException, ProvisioningException {
@SuppressWarnings("unchecked") List<String> args = (List<String>) getValue(ARGUMENT_NAME);
String config = args.get(0);
String path = FeatureContainerPathConsumer.FINAL_CONFIGS_PATH + config + PathParser.PATH_SEPARATOR;
FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(state.getContainer(), false);
PathParser.parse(path, consumer);
ConfigInfo ci = consumer.getConfig();
if (ci == null) {
throw new ProvisioningException("Not a valid config " + config);
}
return ci;
}
use of org.jboss.galleon.cli.model.ConfigInfo in project galleon by wildfly.
the class StateRemoveFeatureCommand method runCommand.
@Override
protected void runCommand(PmCommandInvocation invoc, State session) throws IOException, ProvisioningException, CommandExecutionException {
try {
String path = FeatureContainerPathConsumer.FINAL_CONFIGS_PATH + (feature.endsWith("" + PathParser.PATH_SEPARATOR) ? feature : feature + PathParser.PATH_SEPARATOR);
FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(session.getContainer(), false);
PathParser.parse(path, consumer);
ConfigInfo ci = consumer.getConfig();
if (ci == null) {
throw new ProvisioningException("Not a valid configuration " + feature);
}
Group grp = consumer.getCurrentNode(path);
if (grp == null) {
throw new ProvisioningException("Not a valid feature " + feature);
}
FeatureInfo fi = grp.getFeature();
if (fi == null) {
throw new ProvisioningException("Not a valid feature " + feature);
}
session.removeFeature(invoc.getPmSession(), ci, fi);
} catch (Exception ex) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.removeFeatureFailed(), ex);
}
}
Aggregations