use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.
the class AbstractInstallationCommand method getFeatureContainer.
public FeatureContainer getFeatureContainer(PmSession session, ProvisioningLayout<FeaturePackLayout> layout) throws ProvisioningException, CommandExecutionException, IOException {
FeatureContainer container;
ProvisioningManager manager = getManager(session);
if (manager.getProvisionedState() == null) {
throw new CommandExecutionException("Specified directory doesn't contain an installation");
}
if (layout == null) {
ProvisioningConfig config = manager.getProvisioningConfig();
try (ProvisioningRuntime runtime = manager.getRuntime(config)) {
container = FeatureContainers.fromProvisioningRuntime(session, runtime);
}
} else {
try (ProvisioningRuntime runtime = manager.getRuntime(layout)) {
container = FeatureContainers.fromProvisioningRuntime(session, runtime);
}
}
return container;
}
use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.
the class ClearHistoryCommand method runCommand.
@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
try {
ProvisioningManager mgr = getManager(invoc.getPmSession());
mgr.clearStateHistory();
} catch (ProvisioningException ex) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.clearHistoryFailed(), ex);
}
}
use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.
the class HelpCommand method runCommand.
@Override
protected void runCommand(PmCommandInvocation session) throws CommandExecutionException {
if (command == null || command.isEmpty()) {
try {
session.println(HelpSupport.buildHelp(registry, registry.getAllCommandNames()));
} catch (CommandNotFoundException e) {
throw new CommandExecutionException(e.getLocalizedMessage());
}
} else {
StringBuilder builder = new StringBuilder();
for (String str : command) {
builder.append(str).append(" ");
}
String cmd = builder.toString().trim();
try {
CommandContainer<?> container = registry.getCommand(command.get(0), null);
if (command.size() > 1) {
if (container.getParser().getChildParser(command.get(1)) == null) {
throw new CommandExecutionException(CliErrors.commandNotFound(cmd));
}
}
} catch (CommandNotFoundException ex) {
throw new CommandExecutionException(CliErrors.commandNotFound(cmd));
}
session.println(session.getHelpInfo(cmd));
}
}
use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.
the class StateInfoUtil method displayInfo.
public static void displayInfo(PmCommandInvocation invoc, Path installation, ProvisioningConfig config, String type, Function<ProvisioningLayout<FeaturePackLayout>, FeatureContainer> supplier) throws CommandExecutionException {
try {
if (!config.hasFeaturePackDeps()) {
return;
}
invoc.println("");
displayFeaturePacks(invoc, installation, config);
if (type != null) {
invoc.println("");
try (ProvisioningLayout<FeaturePackLayout> layout = invoc.getPmSession().getLayoutFactory().newConfigLayout(config)) {
switch(type) {
case ALL:
{
FeatureContainer container = supplier.apply(layout);
if (displayDependencies(invoc, layout)) {
invoc.println("");
}
if (displayPatches(invoc, layout)) {
invoc.println("");
}
if (displayConfigs(invoc, container, layout)) {
invoc.println("");
}
if (displayLayers(invoc, layout)) {
invoc.println("");
}
if (displayOptionalPackages(invoc, container, layout)) {
invoc.println("");
}
if (displayOptions(invoc, layout)) {
invoc.println("");
}
displayUniverses(invoc, config);
break;
}
case CONFIGS:
{
FeatureContainer container = supplier.apply(layout);
String configs = buildConfigs(invoc, container, layout);
if (configs != null) {
invoc.print(configs);
} else {
invoc.println(NO_CONFIGURATIONS);
}
break;
}
case DEPENDENCIES:
{
String deps = buildDependencies(invoc, layout);
if (deps != null) {
invoc.print(deps);
} else {
invoc.println(NO_DEPENDENCIES);
}
break;
}
case LAYERS:
{
String layers = buildLayers(layout);
if (layers != null) {
invoc.print(layers);
} else {
invoc.println(NO_LAYERS);
}
break;
}
case OPTIONS:
{
String options = buildOptions(layout);
if (options != null) {
invoc.print(options);
} else {
invoc.println(NO_OPTIONS);
}
break;
}
case PATCHES:
{
String patches = buildPatches(invoc, layout);
if (patches != null) {
invoc.print(patches);
} else {
invoc.println(NO_PATCHES);
}
break;
}
case UNIVERSES:
{
String universes = buildUniverses(config);
if (universes != null) {
invoc.print(universes);
} else {
invoc.println(NO_UNIVERSES);
}
break;
}
case OPTIONAL_PACKAGES:
{
FeatureContainer container = supplier.apply(layout);
String packages = buildOptionalPackages(invoc.getPmSession(), container, layout);
invoc.print(packages);
break;
}
default:
{
throw new CommandExecutionException(CliErrors.invalidInfoType());
}
}
}
}
} catch (Exception ex) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.infoFailed(), ex);
}
}
use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.
the class StateCdCommand method cdFp.
private void cdFp(PmCommandInvocation session) throws CommandExecutionException, PathParserException, PathConsumerException {
PmSession pm = session.getPmSession();
String currentPath = pm.getCurrentPath();
FeatureContainerPathConsumer consumer = new FeatureContainerPathConsumer(pm.getContainer(), true);
if (path.startsWith("" + PathParser.PATH_SEPARATOR)) {
pm.setCurrentPath(null);
} else if (path.equals("..")) {
if (currentPath == null) {
throw new CommandExecutionException("No path entered");
}
if (currentPath.equals("" + PathParser.PATH_SEPARATOR)) {
return;
}
currentPath = currentPath.substring(0, currentPath.length() - 1);
int i = currentPath.lastIndexOf("" + PathParser.PATH_SEPARATOR);
if (i < 0) {
path = "" + PathParser.PATH_SEPARATOR;
} else {
path = currentPath.substring(0, i);
}
if (path.isEmpty()) {
path = "" + PathParser.PATH_SEPARATOR;
}
pm.setCurrentPath(null);
} else {
path = currentPath + path;
}
PathParser.parse(path, consumer);
Group grp = consumer.getCurrentNode(path);
if (grp == null) {
return;
} else {
if (!path.endsWith("" + PathParser.PATH_SEPARATOR)) {
path += PathParser.PATH_SEPARATOR;
}
pm.setCurrentPath(path);
}
String prompt;
if (FeatureContainerPathConsumer.ROOT.equals(grp.getIdentity().getName())) {
prompt = "" + PathParser.PATH_SEPARATOR;
} else {
prompt = grp.getIdentity().getName() + PathParser.PATH_SEPARATOR;
}
session.setPrompt(session.getPmSession().buildPrompt(prompt));
}
Aggregations