use of org.jboss.galleon.cli.model.state.State in project galleon by wildfly.
the class StateNewCommand method runCommand.
@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
State state;
try {
state = new State(invoc.getPmSession());
} catch (Exception ex) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.newStateFailed(), ex);
}
invoc.getPmSession().setState(state);
invoc.setPrompt(invoc.getPmSession().buildPrompt(state.getPath()));
invoc.println(WELCOME_STATE_MSG);
}
use of org.jboss.galleon.cli.model.state.State in project galleon by wildfly.
the class StateProvisionCommand method doRunCommand.
@Override
protected void doRunCommand(PmCommandInvocation invoc, Map<String, String> options) throws CommandExecutionException {
State state = invoc.getPmSession().getState();
try {
getManager(invoc).provision(state.getConfig(), options);
} catch (ProvisioningException | IOException ex) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.provisioningFailed(), ex);
}
Path home = getInstallationDirectory(invoc.getConfiguration().getAeshContext());
if (home != null && Files.exists(home)) {
try {
invoc.println("Installation done in " + home.toFile().getCanonicalPath());
} catch (IOException ex) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.retrievePath(), ex);
}
} else {
invoc.println("Nothing to install");
}
}
use of org.jboss.galleon.cli.model.state.State in project galleon by wildfly.
the class StateEditCommand method runCommand.
@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
State state;
try {
state = new State(invoc.getPmSession(), getInstallationHome(invoc.getConfiguration().getAeshContext()));
} catch (ProvisioningException | IOException ex) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.readContentFailed(), ex);
}
invoc.getPmSession().setState(state);
invoc.setPrompt(invoc.getPmSession().buildPrompt(state.getPath()));
invoc.println(WELCOME_STATE_MSG);
}
use of org.jboss.galleon.cli.model.state.State in project galleon by wildfly.
the class StateExportCommand method runCommand.
@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
if (file != null) {
final Path targetFile = file.toPath();
State session = invoc.getPmSession().getState();
try {
session.export(targetFile);
} catch (Exception ex) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), ex);
}
invoc.println("Provisioning file generated in " + targetFile);
} else {
ByteArrayOutputStream output = null;
try {
ProvisioningConfig config = invoc.getPmSession().getState().getConfig();
output = new ByteArrayOutputStream();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8));
ProvisioningXmlWriter.getInstance().write(config, writer);
} catch (Exception e) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e);
}
try {
invoc.println(output.toString(StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException e) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.exportProvisionedFailed(), e);
}
}
}
use of org.jboss.galleon.cli.model.state.State in project galleon by wildfly.
the class StateUndoCommand method runCommand.
@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
try {
State state = invoc.getPmSession().getState();
if (!state.hasActions()) {
throw new ProvisioningException(Errors.historyIsEmpty());
}
state.pop(invoc.getPmSession());
} catch (ProvisioningException | IOException ex) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.undoFailed(), ex);
}
}
Aggregations