Search in sources :

Example 1 with State

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);
}
Also used : State(org.jboss.galleon.cli.model.state.State) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException)

Example 2 with State

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");
    }
}
Also used : Path(java.nio.file.Path) State(org.jboss.galleon.cli.model.state.State) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) IOException(java.io.IOException)

Example 3 with State

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);
}
Also used : State(org.jboss.galleon.cli.model.state.State) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) IOException(java.io.IOException)

Example 4 with State

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);
        }
    }
}
Also used : Path(java.nio.file.Path) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) State(org.jboss.galleon.cli.model.state.State) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PrintWriter(java.io.PrintWriter)

Example 5 with State

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);
    }
}
Also used : State(org.jboss.galleon.cli.model.state.State) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) IOException(java.io.IOException)

Aggregations

CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)5 State (org.jboss.galleon.cli.model.state.State)5 IOException (java.io.IOException)3 ProvisioningException (org.jboss.galleon.ProvisioningException)3 Path (java.nio.file.Path)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)1