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);
}
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);
}
}
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);
}
}
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.");
}
}
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());
}
}
Aggregations