Search in sources :

Example 6 with CommandExecutionException

use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.

the class AbstractDynamicCommand method validateOptions.

private void validateOptions(PmCommandInvocation invoc) throws CommandExecutionException {
    // Check validity of provided options
    Set<String> providedOptions = getValues().keySet();
    List<ProcessedOption> sOptions = cmd.getOptions(false);
    if (optimizeRetrieval) {
        // check values
        for (String o : providedOptions) {
            for (ProcessedOption opt : sOptions) {
                if (opt.name().equals(o)) {
                    String val = (String) getValue(opt.name());
                    if (opt.hasValue() && (val == null || val.isEmpty())) {
                        throw new CommandExecutionException("Option --" + opt.name() + " was specified, but no value was given");
                    }
                }
            }
        }
        // check required
        for (ProcessedOption opt : sOptions) {
            if (opt.isRequired() && !providedOptions.contains(opt.name())) {
                throw new CommandExecutionException("Option --" + opt.name() + " is required for this command.");
            }
        }
    } else {
        List<ProcessedOption> dOptions = cmd.getOptions(true);
        for (String o : providedOptions) {
            boolean found = false;
            if (!ARGUMENT_NAME.equals(o)) {
                // first find in static options
                for (ProcessedOption opt : sOptions) {
                    if (opt.name().equals(o)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    // then in dynamic ones
                    for (ProcessedOption opt : dOptions) {
                        if (opt.name().equals(o)) {
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        throw new CommandExecutionException("Unknown option --" + o);
                    }
                }
            }
        }
    }
    doValidateOptions(invoc);
}
Also used : ProcessedOption(org.aesh.command.impl.internal.ProcessedOption) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException)

Example 7 with CommandExecutionException

use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.

the class GetInfoCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    try {
        Function<ProvisioningLayout<FeaturePackLayout>, FeatureContainer> supplier = new Function<ProvisioningLayout<FeaturePackLayout>, FeatureContainer>() {

            public FeatureContainer apply(ProvisioningLayout<FeaturePackLayout> layout) {
                try {
                    return getFeatureContainer(invoc.getPmSession(), layout);
                } catch (CommandExecutionException | ProvisioningException | IOException ex) {
                    throw new RuntimeException(ex);
                }
            }
        };
        ProvisioningManager mgr = getManager(invoc.getPmSession());
        StateInfoUtil.displayInfo(invoc, mgr.getInstallationHome(), mgr.getProvisioningConfig(), type, supplier);
    } catch (ProvisioningException | CommandExecutionException ex) {
        throw new CommandExecutionException(invoc.getPmSession(), CliErrors.infoFailed(), ex);
    }
}
Also used : Function(java.util.function.Function) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) ProvisioningManager(org.jboss.galleon.ProvisioningManager) ProvisioningException(org.jboss.galleon.ProvisioningException) FeatureContainer(org.jboss.galleon.cli.model.FeatureContainer) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) IOException(java.io.IOException) ProvisioningLayout(org.jboss.galleon.layout.ProvisioningLayout)

Example 8 with CommandExecutionException

use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.

the class InstallCommand method getId.

@Override
protected String getId(PmSession session) throws CommandExecutionException {
    String filePath = (String) getValue(FILE_OPTION_NAME);
    if (filePath == null) {
        filePath = getOptionValue(FILE_OPTION_NAME);
        if (filePath == null) {
            return super.getId(session);
        }
    }
    Path path;
    try {
        path = Util.resolvePath(session.getAeshContext(), filePath);
    } catch (IOException ex) {
        throw new CommandExecutionException(ex.getMessage());
    }
    if (!Files.exists(path)) {
        return null;
    }
    try {
        return FeaturePackDescriber.readSpec(path).getFPID().toString();
    } catch (ProvisioningException ex) {
        throw new CommandExecutionException(session, CliErrors.retrieveFeaturePackID(), ex);
    }
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) IOException(java.io.IOException)

Example 9 with CommandExecutionException

use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.

the class InstallCommand method doValidateOptions.

@Override
protected void doValidateOptions(PmCommandInvocation invoc) throws CommandExecutionException {
    String filePath = (String) getValue(FILE_OPTION_NAME);
    if (filePath == null) {
        super.doValidateOptions(invoc);
        return;
    }
    String arg = (String) getValue(ARGUMENT_NAME);
    if (arg != null) {
        throw new CommandExecutionException("Only one of file or Feature-pack location is allowed.");
    }
    Path p;
    try {
        p = Util.resolvePath(invoc.getConfiguration().getAeshContext(), filePath);
    } catch (IOException ex) {
        throw new CommandExecutionException(ex.getMessage());
    }
    if (!Files.exists(p)) {
        throw new CommandExecutionException(p + " doesn't exist.");
    }
}
Also used : Path(java.nio.file.Path) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) IOException(java.io.IOException)

Example 10 with CommandExecutionException

use of org.jboss.galleon.cli.CommandExecutionException in project galleon by wildfly.

the class ListFeaturePacksCommand method runCommand.

@Override
public void runCommand(PmCommandInvocation invoc) throws CommandExecutionException {
    Map<UniverseSpec, Table> tables = new HashMap<>();
    Map<UniverseSpec, Set<String>> exceptions = new HashMap<>();
    // Search for an installation in the context
    Path installation = null;
    try {
        installation = Util.lookupInstallationDir(invoc.getConfiguration().getAeshContext(), null);
    } catch (ProvisioningException ex) {
    // XXX OK, no installation.
    }
    Path finalPath = installation;
    UniverseVisitor visitor = new UniverseVisitor() {

        @Override
        public void visit(Producer<?> producer, FeaturePackLocation loc) {
            if (loc.getFrequency() == null) {
                return;
            }
            if (allFrequencies || loc.getFrequency().equals(producer.getDefaultFrequency())) {
                Table table = tables.get(loc.getUniverse());
                if (table == null) {
                    table = new Table(Headers.PRODUCT, Headers.UPDATE_CHANNEL, Headers.LATEST_BUILD);
                    tables.put(loc.getUniverse(), table);
                }
                loc = invoc.getPmSession().getExposedLocation(finalPath, loc);
                table.addLine(producer.getName(), StateInfoUtil.formatChannel(loc), (loc.getBuild() == null ? NONE : loc.getBuild()));
            }
        }

        @Override
        public void exception(UniverseSpec spec, Exception ex) {
            Set<String> set = exceptions.get(spec);
            if (set == null) {
                set = new HashSet<>();
                exceptions.put(spec, set);
            }
            set.add(ex.getLocalizedMessage() == null ? ex.getMessage() : ex.getLocalizedMessage());
        }
    };
    try {
        if (fromUniverse != null) {
            invoc.getPmSession().getUniverse().visitUniverse(UniverseSpec.fromString(fromUniverse), visitor, true);
        } else {
            invoc.getPmSession().getUniverse().visitAllUniverses(visitor, true, finalPath);
        }
    } catch (ProvisioningException ex) {
        throw new CommandExecutionException(invoc.getPmSession(), CliErrors.resolvedUniverseFailed(), ex);
    }
    FindCommand.printExceptions(invoc, exceptions);
    for (Entry<UniverseSpec, Table> entry : tables.entrySet()) {
        Table table = entry.getValue();
        table.sort(Table.SortType.ASCENDANT);
        invoc.println(table.build());
    }
}
Also used : Path(java.nio.file.Path) Table(org.jboss.galleon.cli.cmd.Table) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) ProvisioningException(org.jboss.galleon.ProvisioningException) Producer(org.jboss.galleon.universe.Producer) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) UniverseSpec(org.jboss.galleon.universe.UniverseSpec) UniverseVisitor(org.jboss.galleon.cli.UniverseManager.UniverseVisitor)

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