Method from org.apache.tools.ant.taskdefs.Java Detail: |
public void addAssertions(Assertions asserts) {
if (getCommandLine().getAssertions() != null) {
throw new BuildException("Only one assertion declaration is allowed");
}
getCommandLine().setAssertions(asserts);
}
Add assertions to enable in this program (if fork=true). |
public void addConfiguredRedirector(RedirectorElement redirectorElement) {
if (this.redirectorElement != null) {
throw new BuildException("cannot have > 1 nested redirectors");
}
this.redirectorElement = redirectorElement;
incompatibleWithSpawn = true;
}
Add a RedirectorElement to this task. |
public void addEnv(Variable var) {
env.addVariable(var);
}
|
public void addSysproperty(Variable sysp) {
getCommandLine().addSysproperty(sysp);
}
|
public void addSyspropertyset(PropertySet sysp) {
getCommandLine().addSyspropertyset(sysp);
}
Add a set of properties as system properties. |
protected void checkConfiguration() throws BuildException {
String classname = getCommandLine().getClassname();
if (classname == null && getCommandLine().getJar() == null) {
throw new BuildException("Classname must not be null.");
}
if (!fork && getCommandLine().getJar() != null) {
throw new BuildException("Cannot execute a jar in non-forked mode."
+ " Please set fork='true'. ");
}
if (spawn && !fork) {
throw new BuildException("Cannot spawn a java process in non-forked mode."
+ " Please set fork='true'. ");
}
if (getCommandLine().getClasspath() != null
&& getCommandLine().getJar() != null) {
log("When using 'jar' attribute classpath-settings are ignored. "
+ "See the manual for more information.", Project.MSG_VERBOSE);
}
if (spawn && incompatibleWithSpawn) {
getProject().log("spawn does not allow attributes related to input, "
+ "output, error, result", Project.MSG_ERR);
getProject().log("spawn also does not allow timeout", Project.MSG_ERR);
getProject().log("finally, spawn is not compatible "
+ "with a nested I/O < redirector >", Project.MSG_ERR);
throw new BuildException("You have used an attribute "
+ "or nested element which is not compatible with spawn");
}
if (getCommandLine().getAssertions() != null && !fork) {
log("Assertion statements are currently ignored in non-forked mode");
}
if (fork) {
if (perm != null) {
log("Permissions can not be set this way in forked mode.", Project.MSG_WARN);
}
log(getCommandLine().describeCommand(), Project.MSG_VERBOSE);
} else {
if (getCommandLine().getVmCommand().size() > 1) {
log("JVM args ignored when same JVM is used.",
Project.MSG_WARN);
}
if (dir != null) {
log("Working directory ignored when same JVM is used.",
Project.MSG_WARN);
}
if (newEnvironment || null != env.getVariables()) {
log("Changes to environment variables are ignored when same "
+ "JVM is used.", Project.MSG_WARN);
}
if (getCommandLine().getBootclasspath() != null) {
log("bootclasspath ignored when same JVM is used.",
Project.MSG_WARN);
}
if (perm == null) {
perm = new Permissions(true);
log("running " + this.getCommandLine().getClassname()
+ " with default permissions (exit forbidden)", Project.MSG_VERBOSE);
}
log("Running in same VM " + getCommandLine().describeJavaCommand(),
Project.MSG_VERBOSE);
}
setupRedirector();
}
|
public void clearArgs() {
getCommandLine().clearJavaArgs();
}
Clear out the arguments to this java task. |
public Argument createArg() {
return getCommandLine().createArgument();
}
Add a command-line argument. |
public Path createBootclasspath() {
return getCommandLine().createBootclasspath(getProject()).createPath();
}
Add a path to the bootclasspath. |
public Path createClasspath() {
return getCommandLine().createClasspath(getProject()).createPath();
}
Add a path to the classpath. |
public Argument createJvmarg() {
return getCommandLine().createVmArgument();
}
|
public Permissions createPermissions() {
perm = (perm == null) ? new Permissions() : perm;
return perm;
}
Set the permissions for the application run inside the same JVM. |
protected ExecuteWatchdog createWatchdog() throws BuildException {
if (timeout == null) {
return null;
}
return new ExecuteWatchdog(timeout.longValue());
}
Create the Watchdog to kill a runaway process. |
public void execute() throws BuildException {
File savedDir = dir;
Permissions savedPermissions = perm;
int err = -1;
try {
checkConfiguration();
err = executeJava();
if (err != 0) {
if (failOnError) {
throw new ExitStatusException("Java returned: " + err,
err,
getLocation());
} else {
log("Java Result: " + err, Project.MSG_ERR);
}
}
maybeSetResultPropertyValue(err);
} finally {
dir = savedDir;
perm = savedPermissions;
}
}
|
public int executeJava() throws BuildException {
return executeJava(getCommandLine());
}
Do the execution and return a return code. |
protected int executeJava(CommandlineJava commandLine) {
try {
if (fork) {
if (!spawn) {
return fork(commandLine.getCommandline());
} else {
spawn(commandLine.getCommandline());
return 0;
}
} else {
try {
run(commandLine);
return 0;
} catch (ExitException ex) {
return ex.getStatus();
}
}
} catch (BuildException e) {
if (e.getLocation() == null && getLocation() != null) {
e.setLocation(getLocation());
}
if (failOnError) {
throw e;
} else {
if (TIMEOUT_MESSAGE.equals(e.getMessage())) {
log(TIMEOUT_MESSAGE);
} else {
log(e);
}
return -1;
}
} catch (ThreadDeath t) {
throw t; // cf. NB #47191
} catch (Throwable t) {
if (failOnError) {
throw new BuildException(t, getLocation());
} else {
log(t);
return -1;
}
}
}
Execute the specified CommandlineJava. |
public CommandlineJava getCommandLine() {
return cmdl;
}
Accessor to the command line. |
public SysProperties getSysProperties() {
return getCommandLine().getSystemProperties();
}
Get the system properties of the command line. |
protected void handleErrorFlush(String output) {
if (redirector.getErrorStream() != null) {
redirector.handleErrorFlush(output);
} else {
super.handleErrorOutput(output);
}
}
Handle output sent to System.err and flush the stream. |
protected void handleErrorOutput(String output) {
if (redirector.getErrorStream() != null) {
redirector.handleErrorOutput(output);
} else {
super.handleErrorOutput(output);
}
}
Handle output sent to System.err. |
protected void handleFlush(String output) {
if (redirector.getOutputStream() != null) {
redirector.handleFlush(output);
} else {
super.handleFlush(output);
}
}
Pass output sent to System.out to specified output file. |
public int handleInput(byte[] buffer,
int offset,
int length) throws IOException {
// Should work whether or not redirector.inputStream == null:
return redirector.handleInput(buffer, offset, length);
}
Handle an input request by this task. |
protected void handleOutput(String output) {
if (redirector.getOutputStream() != null) {
redirector.handleOutput(output);
} else {
super.handleOutput(output);
}
}
Pass output sent to System.out to specified output file. |
protected void maybeSetResultPropertyValue(int result) {
String res = Integer.toString(result);
if (resultProperty != null) {
getProject().setNewProperty(resultProperty, res);
}
}
Helper method to set result property to the
passed in value if appropriate. |
protected void run(String classname,
Vector args) throws BuildException {
CommandlineJava cmdj = new CommandlineJava();
cmdj.setClassname(classname);
for (int i = 0; i < args.size(); i++) {
cmdj.createArgument().setValue((String) args.elementAt(i));
}
run(cmdj);
}
Executes the given classname with the given arguments as if it
were a command line application. |
public void setAppend(boolean append) {
redirector.setAppend(append);
incompatibleWithSpawn = true;
}
If true, append output to existing file. |
public void setArgs(String s) {
log("The args attribute is deprecated. "
+ "Please use nested arg elements.", Project.MSG_WARN);
getCommandLine().createArgument().setLine(s);
}
Deprecated: use nested arg instead.
Set the command line arguments for the class. |
public void setClassname(String s) throws BuildException {
if (getCommandLine().getJar() != null) {
throw new BuildException("Cannot use 'jar' and 'classname' "
+ "attributes in same command");
}
getCommandLine().setClassname(s);
}
Set the Java class to execute. |
public void setClasspath(Path s) {
createClasspath().append(s);
}
Set the classpath to be used when running the Java class. |
public void setClasspathRef(Reference r) {
createClasspath().setRefid(r);
}
Set the classpath to use by reference. |
public void setCloneVm(boolean cloneVm) {
getCommandLine().setCloneVm(cloneVm);
}
|
public void setDir(File d) {
this.dir = d;
}
Set the working directory of the process. |
public void setError(File error) {
this.error = error;
incompatibleWithSpawn = true;
}
Set the File to which the error stream of the process is redirected. |
public void setErrorProperty(String errorProperty) {
redirector.setErrorProperty(errorProperty);
incompatibleWithSpawn = true;
}
Set the property name whose value should be set to the error of
the process. |
public void setFailonerror(boolean fail) {
failOnError = fail;
incompatibleWithSpawn |= fail;
}
If true, then fail if the command exits with a
returncode other than zero. |
public void setFork(boolean s) {
this.fork = s;
}
If true, execute in a new VM. |
public void setInput(File input) {
if (inputString != null) {
throw new BuildException("The \"input\" and \"inputstring\" "
+ "attributes cannot both be specified");
}
this.input = input;
incompatibleWithSpawn = true;
}
Set the input to use for the task. |
public void setInputString(String inputString) {
if (input != null) {
throw new BuildException("The \"input\" and \"inputstring\" "
+ "attributes cannot both be specified");
}
this.inputString = inputString;
incompatibleWithSpawn = true;
}
Set the string to use as input. |
public void setJVMVersion(String value) {
getCommandLine().setVmversion(value);
}
|
public void setJar(File jarfile) throws BuildException {
if (getCommandLine().getClassname() != null) {
throw new BuildException("Cannot use 'jar' and 'classname' "
+ "attributes in same command.");
}
getCommandLine().setJar(jarfile.getAbsolutePath());
}
Set the location of the JAR file to execute. |
public void setJvm(String s) {
getCommandLine().setVm(s);
}
Set the command used to start the VM (only if forking). |
public void setJvmargs(String s) {
log("The jvmargs attribute is deprecated. "
+ "Please use nested jvmarg elements.", Project.MSG_WARN);
getCommandLine().createVmArgument().setLine(s);
}
Set the command line arguments for the JVM. |
public void setLogError(boolean logError) {
redirector.setLogError(logError);
incompatibleWithSpawn |= logError;
}
Set whether error output of exec is logged. This is only useful
when output is being redirected and error output is desired in the
Ant log. |
public void setMaxmemory(String max) {
getCommandLine().setMaxmemory(max);
}
Corresponds to -mx or -Xmx depending on VM version. |
public void setNewenvironment(boolean newenv) {
newEnvironment = newenv;
}
|
public void setOutput(File out) {
this.output = out;
incompatibleWithSpawn = true;
}
Set the File to which the output of the process is redirected. |
public void setOutputproperty(String outputProp) {
redirector.setOutputProperty(outputProp);
incompatibleWithSpawn = true;
}
Set the property name whose value should be set to the output of
the process. |
public void setResultProperty(String resultProperty) {
this.resultProperty = resultProperty;
incompatibleWithSpawn = true;
}
Set the name of the property in which the return code of the
command should be stored. Only of interest if failonerror=false. |
public void setSpawn(boolean spawn) {
this.spawn = spawn;
}
Set whether or not you want the process to be spawned;
default is not spawned. |
public void setTimeout(Long value) {
timeout = value;
incompatibleWithSpawn |= timeout != null;
}
Set the timeout in milliseconds after which the process will be killed. |
protected void setupRedirector() {
redirector.setInput(input);
redirector.setInputString(inputString);
redirector.setOutput(output);
redirector.setError(error);
if (redirectorElement != null) {
redirectorElement.configure(redirector);
}
if (!spawn && input == null && inputString == null) {
// #24918: send standard input to the process by default.
redirector.setInputStream(
new KeepAliveInputStream(getProject().getDefaultInputStream()));
}
}
Set up properties on the redirector that we needed to store locally. |