use of org.jboss.galleon.cli.CommandExecutionException 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.CommandExecutionException in project galleon by wildfly.
the class StateGetInfoCommand method runCommand.
@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
try {
ProvisioningConfig config = invoc.getPmSession().getContainer().getProvisioningConfig();
Function<ProvisioningLayout<FeaturePackLayout>, FeatureContainer> supplier = new Function<ProvisioningLayout<FeaturePackLayout>, FeatureContainer>() {
public FeatureContainer apply(ProvisioningLayout<FeaturePackLayout> layout) {
return invoc.getPmSession().getState().getContainer();
}
};
StateInfoUtil.displayInfo(invoc, null, config, type, supplier);
} 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 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);
}
}
use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.
the class StateIncludePackageCommand method runCommand.
@Override
protected void runCommand(PmCommandInvocation invoc, State session, FeaturePackConfig config) throws IOException, ProvisioningException, CommandExecutionException {
try {
int i = getPackage().indexOf("/");
String name = getPackage().substring(i + 1);
// but no transitive dependency has been created yet.
if (config == null) {
session.includePackageInNewTransitive(invoc.getPmSession(), getProducer(invoc.getPmSession()), name);
} else {
session.includePackage(invoc.getPmSession(), name, config);
}
} catch (Exception ex) {
throw new CommandExecutionException(invoc.getPmSession(), CliErrors.includeFailed(), ex);
}
}
use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.
the class UpdateCommand method doRunCommand.
@Override
protected void doRunCommand(PmCommandInvocation session, Map<String, String> options) throws CommandExecutionException {
try {
ProvisioningManager mgr = getManager(session);
Updates updates = CheckUpdatesCommand.getUpdatesTable(mgr, session, allDependencies(), getFP());
if (updates.plan.isEmpty()) {
session.println(UP_TO_DATE);
} else {
session.println(UPDATES_AVAILABLE);
session.println(updates.t.build());
if (!noConfirm()) {
try {
Key k = null;
while (k == null || (!Key.y.equals(k) && !Key.n.equals(k))) {
session.print("Proceed with latest updates [y/n]?");
KeyAction a = session.input();
k = Key.findStartKey(a.buffer().array());
}
if (Key.n.equals(k)) {
return;
}
} finally {
session.println("");
}
}
mgr.apply(updates.plan, options);
}
} catch (ProvisioningException | IOException ex) {
throw new CommandExecutionException(session.getPmSession(), CliErrors.updateFailed(), ex);
} catch (InterruptedException ignored) {
// Just exit the command smoothly
}
}
Aggregations