Search in sources :

Example 26 with CommandExecutionException

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;
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ProvisioningManager(org.jboss.galleon.ProvisioningManager) ProvisioningRuntime(org.jboss.galleon.runtime.ProvisioningRuntime) FeatureContainer(org.jboss.galleon.cli.model.FeatureContainer) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException)

Example 27 with CommandExecutionException

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

Example 28 with CommandExecutionException

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));
    }
}
Also used : CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) CommandNotFoundException(org.aesh.command.CommandNotFoundException)

Example 29 with CommandExecutionException

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);
    }
}
Also used : FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) FeatureContainer(org.jboss.galleon.cli.model.FeatureContainer) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) PathParserException(org.jboss.galleon.cli.path.PathParserException) PathConsumerException(org.jboss.galleon.cli.path.PathConsumerException) IOException(java.io.IOException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 30 with CommandExecutionException

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));
}
Also used : FeatureContainerPathConsumer(org.jboss.galleon.cli.path.FeatureContainerPathConsumer) Group(org.jboss.galleon.cli.model.Group) PmSession(org.jboss.galleon.cli.PmSession) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException)

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