use of org.glassfish.api.admin.CommandValidationException in project Payara by payara.
the class AdminMain method executeCommand.
public int executeCommand(String[] argv) {
CLICommand cmd = null;
try {
// if the first argument is an option, we're using the new form
if (argv.length > 0 && argv[0].startsWith("-")) {
/*
* Parse all the admin options, stopping at the first
* non-option, which is the command name.
*/
Parser rcp = new Parser(argv, 0, ProgramOptions.getValidOptions(), false);
ParameterMap params = rcp.getOptions();
po = new ProgramOptions(params, env);
readAndMergeOptionsFromAuxInput(po);
List<String> operands = rcp.getOperands();
argv = operands.toArray(new String[operands.size()]);
} else {
po = new ProgramOptions(env);
}
po.toEnvironment(env);
po.setClassPath(classPath);
po.setClassName(className);
po.setCommandName(getCommandName());
if (argv.length == 0) {
if (po.isHelp()) {
argv = new String[] { "help" };
} else {
argv = new String[] { "multimode" };
}
}
command = argv[0];
cliContainer.setEnvironment(env);
cliContainer.setProgramOptions(po);
cmd = CLICommand.getCommand(cliContainer, command);
int result = cmd.execute(argv);
return result;
} catch (CommandValidationException cve) {
logger.severe(cve.getMessage());
if (// error parsing program options
cmd == null) {
printUsage();
} else {
logger.severe(cmd.getUsage());
}
return ERROR;
} catch (InvalidCommandException ice) {
// find closest match with local or remote commands
logger.severe(ice.getMessage());
try {
po.setEcho(false);
CLIUtil.displayClosestMatch(command, CLIUtil.getAllCommands(cliContainer, po, env), strings.get("ClosestMatchedLocalAndRemoteCommands"), logger);
} catch (InvalidCommandException e) {
// not a big deal if we cannot help
}
return ERROR;
} catch (CommandException ce) {
if (ce.getCause() instanceof java.net.ConnectException) {
// find closest match with local commands
logger.severe(ce.getMessage());
try {
CLIUtil.displayClosestMatch(command, CLIUtil.getLocalCommands(cliContainer), strings.get("ClosestMatchedLocalCommands"), logger);
} catch (InvalidCommandException e) {
logger.info(strings.get("InvalidRemoteCommand", command));
}
} else {
logger.severe(ce.getMessage());
}
return ERROR;
}
}
use of org.glassfish.api.admin.CommandValidationException in project Payara by payara.
the class CreateLocalInstanceCommand method validateNodeInstallDirLocal.
private void validateNodeInstallDirLocal(String nodeInstallDir, String installDir) throws CommandValidationException {
String canonicalNodeInstallDir = FileUtils.safeGetCanonicalPath(new File(nodeInstallDir));
String canonicalInstallDir = FileUtils.safeGetCanonicalPath(new File(installDir));
if (canonicalNodeInstallDir == null || canonicalInstallDir == null) {
throw new CommandValidationException(Strings.get("Instance.installdir.null", node, canonicalInstallDir, canonicalNodeInstallDir));
}
if (!canonicalInstallDir.equals(canonicalNodeInstallDir)) {
throw new CommandValidationException(Strings.get("Instance.installdir.mismatch", node, canonicalInstallDir, canonicalNodeInstallDir));
}
}
Aggregations