use of com.sun.enterprise.admin.cli.ProgramOptions in project Payara by payara.
the class RemoteDeploymentFacility method prepareRemoteCommandProgramOptions.
protected ProgramOptions prepareRemoteCommandProgramOptions(Environment env) throws CommandException {
/*
* Add the authentication information from the
* caller-provided connection identifier.
*/
ServerConnectionIdentifier targetDAS = getTargetDAS();
ProgramOptions po = new ProgramOptions(env);
po.setHost(targetDAS.getHostName());
po.setPort(targetDAS.getHostPort());
po.setUser(targetDAS.getUserName());
po.setSecure(targetDAS.isSecure());
po.setPassword(getTargetDAS().getPassword() != null ? getTargetDAS().getPassword().toCharArray() : null, ProgramOptions.PasswordLocation.LOCAL_PASSWORD);
po.setOptionsSet(true);
return po;
}
use of com.sun.enterprise.admin.cli.ProgramOptions in project Payara by payara.
the class LocalOSGiShellCommand method executeCommands.
/**
* Read commands from the specified BufferedReader
* and execute them. If printPrompt is set, prompt first.
*
* @return the exit code of the last command executed
*/
private int executeCommands(ConsoleReader reader) throws CommandException, CommandValidationException, IOException {
String line = null;
int rc = 0;
/*
* Any program options we start with are copied to the environment
* to serve as defaults for commands we run, and then we give each
* command an empty program options.
*/
programOpts.toEnvironment(env);
String sessionId = startSession();
try {
for (; ; ) {
if (printPrompt) {
line = reader.readLine(shellType + "$ ");
} else {
line = reader.readLine();
}
if (line == null) {
if (printPrompt) {
System.out.println();
}
break;
}
if (// ignore comment lines
line.trim().startsWith("#")) {
continue;
}
String[] args = null;
try {
args = getArgs(line);
} catch (ArgumentTokenizer.ArgumentException ex) {
logger.info(ex.getMessage());
continue;
}
if (args.length == 0) {
continue;
}
String command = args[0];
if (command.trim().length() == 0) {
continue;
}
// XXX - care about their arguments?
if (command.equals("exit") || command.equals("quit")) {
break;
}
ProgramOptions po = null;
try {
/*
* Every command gets its own copy of program options
* so that any program options specified in its
* command line options don't effect other commands.
* But all commands share the same environment.
*/
po = new ProgramOptions(env);
// copy over AsadminMain info
po.setClassPath(programOpts.getClassPath());
po.setClassName(programOpts.getClassName());
// remove the old one and replace it
atomicReplace(locator, po);
args = prepareArguments(sessionId, args);
args = enhanceForTarget(args);
String output = cmd.executeAndReturnOutput(args).trim();
if (output != null && output.length() > 0) {
logger.info(output);
}
} catch (CommandValidationException cve) {
logger.severe(cve.getMessage());
logger.severe(cmd.getUsage());
rc = ERROR;
} catch (InvalidCommandException ice) {
// find closest match with local or remote commands
logger.severe(ice.getMessage());
} catch (CommandException ce) {
logger.severe(ce.getMessage());
rc = ERROR;
} finally {
// restore the original program options
// XXX - is this necessary?
atomicReplace(locator, programOpts);
}
CLIUtil.writeCommandToDebugLog(name, env, args, rc);
}
} finally {
// what if something breaks on the wire?
rc = stopSession(sessionId);
}
return rc;
}
use of com.sun.enterprise.admin.cli.ProgramOptions in project Payara by payara.
the class LocalOSGiShellCommand method atomicReplace.
private static void atomicReplace(ServiceLocator locator, ProgramOptions options) {
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
DynamicConfiguration config = dcs.createDynamicConfiguration();
config.addUnbindFilter(BuilderHelper.createContractFilter(ProgramOptions.class.getName()));
ActiveDescriptor<ProgramOptions> desc = BuilderHelper.createConstantDescriptor(options, null, ProgramOptions.class);
config.addActiveDescriptor(desc);
config.commit();
}
Aggregations