AdminTaskpublic class AdminTask extends AppServerAdmin This task enables arbitrary administrative commands and scripts to be
executed on the Sun ONE Application Server 7. This is useful for cases where
a specific Ant task hasn't been developed or a set of related commands has
been composed in a single script.
In addition to the server-based attributes, this task introduces three
attribute:
- command -- The command to execute. If the "user", "password", "passwordfile",
"host", "port" or "instance" attributes are also
specified, they will automatically be inserted into
the command before it is exectuted. If any of
these options is specified in the command string,
the corresponding attribute value will be ignored
- commandfile -- The command script to execute. If the "user",
"password", "passwordfile", "host", "port" or "instance"
attributes are also specified, they will
automatically be inserted into the command
environment before the script is exectuted
- explicitcommand -- The exact command to execute. No
processing of the command is done, and all
other attributes are ignored
|
Fields Summary |
---|
private String | command | private String | explicitCommand | private File | commandFile | LocalStringsManager | lsm |
Methods Summary |
---|
private void | checkCommandCount()Verifies that one and only one of the command attributes (command,
commandfile, and explicitcommand) has been set.
int commandCount = 0;
if (command != null) { commandCount++; }
if (explicitCommand != null) { commandCount++; }
if (commandFile != null) { commandCount++; }
if (commandCount != 1) {
final String msg = lsm.getString("ExactlyOneCommandAttribute");
throw new BuildException(msg, getLocation());
}
| protected void | checkConfiguration(Server aServer)
// No error checking is done for this task
| private boolean | commandIncludes(java.lang.StringBuffer cmd, java.lang.String[] options)Utility method that determines if command options have already been
specified in the command line
for (int i = 0; i < options.length; i++) {
if (cmd.indexOf(options[i]) > 0) {
return true;
}
}
return false;
| public void | execute()
checkCommandCount();
if ((command != null) && (servers.size() == 0) && (server == null)) {
// No other attributes or server elements -- treat as explicitCommand // FIXME -- this will no longer ever happen
explicitCommand = command;
command = null;
}
if (explicitCommand != null) {
// Normal execution process is skipped and command is run immediately
execAdminCommand(explicitCommand);
} else {
super.execute();
}
| protected void | execute(Server aServer)
/*
* "command" and "commandfile" attributes are processed in this method.
* See the execute() method for "explicitcommand" processing.
*/
final String userOption[] = {"--user ", "-u "};
final String passwordOption[] = {"--password ", "-w ", "--passwordfile "};
final String hostOption[] = {"--host ", "-H "};
final String portOption[] = {"--port ", "-p "};
final String instanceOption[] = {"--instance ", "-i "};
final String secureOption[] = {"--secure ", "-s "};
StringBuffer cmd;
if (command != null) {
cmd = new StringBuffer(command);
if (!commandIncludes(cmd, userOption)) {
insertCommandOption(cmd, " --user " + aServer.getUser());
}
if ((aServer.hasPassword())
&& (!commandIncludes(cmd, passwordOption))) {
insertCommandOption(cmd, aServer.getPasswordCommand());
}
if (!commandIncludes(cmd, hostOption)) {
String theHost = aServer.getHost();
if (theHost == null) {
theHost = Server.DEFAULT_HOST;
}
insertCommandOption(cmd, " --host " + theHost);
}
if (!commandIncludes(cmd, portOption)) {
String thePort = (aServer.getPort() == 0) ?
Server.DEFAULT_PORT :
String.valueOf(aServer.getPort());
insertCommandOption(cmd, " --port " + thePort);
}
if ((aServer.getInstance() != null)
&& (!commandIncludes(cmd, instanceOption))) {
insertCommandOption(cmd, " --instance " + aServer.getInstance());
}
if (aServer.getSecure() != null &&
!commandIncludes(cmd, secureOption)) {
insertCommandOption(cmd, " --secure=" + aServer.getSecure());
}
} else {
String filename;
try
{
filename = commandFile.getCanonicalPath();
}
catch(Exception e)
{
filename = commandFile.getAbsolutePath();
}
// passing in '\\' for Windows would make CLI choke!
filename = filename.replace('\\", '/");
cmd = new StringBuffer("multimode --file " + filename + " ");
}
execAdminCommand(cmd.toString());
| private void | insertCommandOption(java.lang.StringBuffer cmdLine, java.lang.String commandOption)Utility method that inserts a string into the current command line. The
string is inserted after the command name.
int index = cmdLine.indexOf(" ");
index = (index >= 0) ? index : cmdLine.length();
cmdLine.insert(index, commandOption).append(' ");
| public void | setCommand(java.lang.String command)Sets the command to be executed. The task will automatically add user,
password or passwordfile, host, port, and instance parameters if they're not specified in
the command.
this.command = command.trim();
| public void | setCommandfile(java.io.File commandFile)Sets the command file which contains zero or more administrative commands
which will be read and executed. The user, password or passwordfile, host, port, and
instance parameters will automatically be added to the environment when
the command is executed
final String msg = lsm.getString("DeprecatedAttribute",
new Object[] {"commandfile",
"- 'multimode --file <commandfile>'"});
log(msg, Project.MSG_WARN);
this.commandFile = commandFile;
| public void | setExplicitcommand(java.lang.String explicitCommand)Sets the command to be executed. The task will execute the command as
specified and will NOT automatically add user, password or passwordfile, host, port and
instance parameters
this.explicitCommand = explicitCommand;
|
|