Search in sources :

Example 31 with CommandExecutionException

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);
        }
    }
}
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 32 with CommandExecutionException

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);
    }
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) Function(java.util.function.Function) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) FeatureContainer(org.jboss.galleon.cli.model.FeatureContainer) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ProvisioningLayout(org.jboss.galleon.layout.ProvisioningLayout) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException)

Example 33 with CommandExecutionException

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);
    }
}
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 34 with CommandExecutionException

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

Example 35 with CommandExecutionException

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
    }
}
Also used : ProvisioningManager(org.jboss.galleon.ProvisioningManager) Updates(org.jboss.galleon.cli.cmd.maingrp.CheckUpdatesCommand.Updates) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) IOException(java.io.IOException) KeyAction(org.aesh.readline.action.KeyAction) Key(org.aesh.readline.terminal.Key)

Aggregations

CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)37 ProvisioningException (org.jboss.galleon.ProvisioningException)25 IOException (java.io.IOException)18 Path (java.nio.file.Path)11 ProvisioningManager (org.jboss.galleon.ProvisioningManager)8 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)7 FeatureContainer (org.jboss.galleon.cli.model.FeatureContainer)6 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)6 State (org.jboss.galleon.cli.model.state.State)5 FeaturePackLayout (org.jboss.galleon.layout.FeaturePackLayout)5 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)4 ArrayList (java.util.ArrayList)3 Group (org.jboss.galleon.cli.model.Group)3 FeatureContainerPathConsumer (org.jboss.galleon.cli.path.FeatureContainerPathConsumer)3 PathConsumerException (org.jboss.galleon.cli.path.PathConsumerException)3 PathParserException (org.jboss.galleon.cli.path.PathParserException)3 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2