Fields Summary |
---|
private static final org.apache.tools.ant.util.FileUtils | FILE_UTILS |
protected org.apache.tools.ant.Task | ownerowner project |
protected org.apache.tools.ant.taskdefs.Execute | executableexecutable |
protected org.apache.tools.ant.types.Commandline | commandLinewhat is the command line |
protected String | titletitle of the command |
protected String | programactual program to invoke |
protected boolean | traceCommandLinetrace flag |
protected boolean | failOnErrorflag to control action on execution trouble |
private File | directorythe directory to execute the command in. When null, the current
directory is used. |
private boolean | useResponseFileflag to set to to use @file based command cache |
private File | temporaryCommandFilename of a temp file; may be null |
private int | automaticResponseFileThresholdinternal threshold for auto-switch |
Methods Summary |
---|
public void | addArgument(java.lang.String argument1, java.lang.String argument2)concatenate two strings together and add them as a single argument,
but only if argument2 is non-null and non-zero length
if (argument2 != null && argument2.length() != 0) {
commandLine.createArgument().setValue(argument1 + argument2);
}
|
public void | addArgument(java.lang.String argument)add an argument to a command line; do nothing if the arg is null or
empty string
if (argument != null && argument.length() != 0) {
commandLine.createArgument().setValue(argument);
}
|
public void | addArguments(java.lang.String[] arguments)add an argument to a command line; do nothing if the arg is null or
empty string
if (arguments != null && arguments.length != 0) {
for (int i = 0; i < arguments.length; i++) {
addArgument(arguments[i]);
}
}
|
public int | getAutomaticResponseFileThreshold()getter for threshold
return automaticResponseFileThreshold;
|
public boolean | getFailFailOnError()query fail on error flag
return failOnError;
|
public boolean | isUseResponseFile()getter
return useResponseFile;
|
protected void | logError(java.lang.String msg)error text log
owner.getProject().log(msg, Project.MSG_ERR);
|
protected void | logVerbose(java.lang.String msg)verbose text log
owner.getProject().log(msg, Project.MSG_VERBOSE);
|
protected void | prepareExecutor()set up the command sequence..
// default directory to the project's base directory
if (owner == null) {
throw new RuntimeException("no owner");
}
if (owner.getProject() == null) {
throw new RuntimeException("Owner has no project");
}
File dir = owner.getProject().getBaseDir();
if (directory != null) {
dir = directory;
}
ExecuteStreamHandler handler = new LogStreamHandler(owner,
Project.MSG_INFO, Project.MSG_WARN);
executable = new Execute(handler, null);
executable.setAntRun(owner.getProject());
executable.setWorkingDirectory(dir);
|
public void | runCommand()Run the command using the given Execute instance.
prepareExecutor();
int err = -1;
// assume the worst
try {
if (traceCommandLine) {
owner.log("In directory " + executable.getWorkingDirectory());
owner.log(commandLine.describeCommand());
} else {
//in verbose mode we always log stuff
logVerbose("In directory " + executable.getWorkingDirectory());
logVerbose(commandLine.describeCommand());
}
setExecutableCommandLine();
err = executable.execute();
if (Execute.isFailure(err)) {
if (failOnError) {
throw new BuildException(title + " returned: " + err, owner.getLocation());
} else {
owner.log(title + " Result: " + err, Project.MSG_ERR);
}
}
} catch (IOException e) {
throw new BuildException(title + " failed: " + e, e, owner.getLocation());
} finally {
if (temporaryCommandFile != null) {
temporaryCommandFile.delete();
}
}
|
public int | scanOneFileset(org.apache.tools.ant.DirectoryScanner scanner, java.util.Hashtable filesToBuild, long outputTimestamp)scan through one fileset for files to include
int filesOutOfDate = 0;
String[] dependencies = scanner.getIncludedFiles();
File base = scanner.getBasedir();
//add to the list
for (int i = 0; i < dependencies.length; i++) {
File targetFile = new File(base, dependencies[i]);
if (filesToBuild.get(targetFile) == null) {
filesToBuild.put(targetFile, targetFile);
if (targetFile.lastModified() > outputTimestamp) {
filesOutOfDate++;
owner.log(targetFile.toString() + " is out of date",
Project.MSG_VERBOSE);
} else {
owner.log(targetFile.toString(),
Project.MSG_VERBOSE);
}
}
}
return filesOutOfDate;
|
public void | setAutomaticResponseFileThreshold(int automaticResponseFileThreshold)set threshold for automatically using response files -use 0 for off
this.automaticResponseFileThreshold = automaticResponseFileThreshold;
|
public void | setDirectory(java.io.File directory)set the directory to run from, if the default is inadequate
this.directory = directory;
|
private void | setExecutableCommandLine()set the executable command line
String[] commands = commandLine.getCommandline();
//always trigger file mode if commands are big enough
if (automaticResponseFileThreshold > 0
&& commands.length > automaticResponseFileThreshold) {
useResponseFile = true;
}
if (!useResponseFile || commands.length <= 1) {
//the simple action is to send the command line in as is
executable.setCommandline(commands);
} else {
//but for big operations, we save all the params to a temp file
//and set @tmpfile as the command -then we remember to delete the tempfile
//afterwards
FileOutputStream fos = null;
temporaryCommandFile = FILE_UTILS.createTempFile("cmd", ".txt", null);
owner.log("Using response file " + temporaryCommandFile, Project.MSG_VERBOSE);
try {
fos = new FileOutputStream(temporaryCommandFile);
PrintWriter out = new PrintWriter(new BufferedOutputStream(fos));
//start at 1 because element 0 is the executable name
for (int i = 1; i < commands.length; ++i) {
out.println(commands[i]);
}
out.flush();
out.close();
} catch (IOException ex) {
throw new BuildException("saving command stream to " + temporaryCommandFile, ex);
}
String[] newCommandLine = new String[2];
newCommandLine[0] = commands[0];
newCommandLine[1] = "@" + temporaryCommandFile.getAbsolutePath();
logVerbose(Commandline.describeCommand(newCommandLine));
executable.setCommandline(newCommandLine);
}
|
public void | setFailOnError(boolean b)set fail on error flag
failOnError = b;
|
public void | setTraceCommandLine(boolean b)turn tracing on or off
traceCommandLine = b;
|
public void | setUseResponseFile(boolean useResponseFile)set this to true to always use the response file
this.useResponseFile = useResponseFile;
|