Methods Summary |
---|
public void | add(org.apache.tools.ant.util.FileNameMapper fileNameMapper)Add a nested FileNameMapper.
createMapper().add(fileNameMapper);
|
public void | add(org.apache.tools.ant.types.ResourceCollection rc)Add a collection of resources upon which to operate.
if (resources == null) {
resources = new Union();
}
resources.add(rc);
|
public void | addDirset(org.apache.tools.ant.types.DirSet set)Add a set of directories upon which to operate.
filesets.addElement(set);
|
public void | addFilelist(org.apache.tools.ant.types.FileList list)Add a list of source files upon which to operate.
add(list);
|
public void | addFileset(org.apache.tools.ant.types.FileSet set)Add a set of files upon which to operate.
// CheckStyle:VisibilityModifier ON
filesets.addElement(set);
|
protected void | checkConfiguration()Check the configuration of this ExecuteOn instance.
// * @TODO using taskName here is brittle, as a user could override it.
// * this should probably be modified to use the classname instead.
if ("execon".equals(getTaskName())) {
log("!! execon is deprecated. Use apply instead. !!");
}
super.checkConfiguration();
if (filesets.size() == 0 && resources == null) {
throw new BuildException("no resources specified",
getLocation());
}
if (targetFilePos != null && mapperElement == null) {
throw new BuildException("targetfile specified without mapper",
getLocation());
}
if (destDir != null && mapperElement == null) {
throw new BuildException("dest specified without mapper",
getLocation());
}
if (mapperElement != null) {
mapper = mapperElement.getImplementation();
}
|
protected ExecuteStreamHandler | createHandler()Create the ExecuteStreamHandler instance that will be used
during execution.
//if we have a RedirectorElement, return a decoy
return (redirectorElement == null)
? super.createHandler() : new PumpStreamHandler();
|
public org.apache.tools.ant.types.Mapper | createMapper()Create a nested Mapper element to use for mapping
source files to target files.
if (mapperElement != null) {
throw new BuildException("Cannot define more than one mapper",
getLocation());
}
mapperElement = new Mapper(getProject());
return mapperElement;
|
public Commandline.Marker | createSrcfile()Create a placeholder indicating where on the command line
the name of the source file should be inserted.
if (srcFilePos != null) {
throw new BuildException(getTaskType() + " doesn\'t support multiple "
+ "srcfile elements.", getLocation());
}
srcFilePos = cmdl.createMarker();
return srcFilePos;
|
public Commandline.Marker | createTargetfile()Create a placeholder indicating where on the command line
the name of the target file should be inserted.
if (targetFilePos != null) {
throw new BuildException(getTaskType() + " doesn\'t support multiple "
+ "targetfile elements.", getLocation());
}
targetFilePos = cmdl.createMarker();
srcIsFirst = (srcFilePos != null);
return targetFilePos;
|
protected java.lang.String[] | getCommandline(java.lang.String[] srcFiles, java.io.File[] baseDirs)Construct the command line for parallel execution.
final char fileSeparator = File.separatorChar;
Vector targets = new Vector();
if (targetFilePos != null) {
Hashtable addedFiles = new Hashtable();
for (int i = 0; i < srcFiles.length; i++) {
String[] subTargets = mapper.mapFileName(srcFiles[i]);
if (subTargets != null) {
for (int j = 0; j < subTargets.length; j++) {
String name = null;
if (!relative) {
name = (new File(destDir, subTargets[j])).getAbsolutePath();
} else {
name = subTargets[j];
}
if (forwardSlash && fileSeparator != '/") {
name = name.replace(fileSeparator, '/");
}
if (!addedFiles.contains(name)) {
targets.addElement(name);
addedFiles.put(name, name);
}
}
}
}
}
String[] targetFiles = new String[targets.size()];
targets.copyInto(targetFiles);
if (!addSourceFile) {
srcFiles = new String[0];
}
String[] orig = cmdl.getCommandline();
String[] result
= new String[orig.length + srcFiles.length + targetFiles.length];
int srcIndex = orig.length;
if (srcFilePos != null) {
srcIndex = srcFilePos.getPosition();
}
if (targetFilePos != null) {
int targetIndex = targetFilePos.getPosition();
if (srcIndex < targetIndex
|| (srcIndex == targetIndex && srcIsFirst)) {
// 0 --> srcIndex
System.arraycopy(orig, 0, result, 0, srcIndex);
// srcIndex --> targetIndex
System.arraycopy(orig, srcIndex, result,
srcIndex + srcFiles.length,
targetIndex - srcIndex);
// targets are already absolute file names
System.arraycopy(targetFiles, 0, result,
targetIndex + srcFiles.length,
targetFiles.length);
// targetIndex --> end
System.arraycopy(orig, targetIndex, result,
targetIndex + srcFiles.length + targetFiles.length,
orig.length - targetIndex);
} else {
// 0 --> targetIndex
System.arraycopy(orig, 0, result, 0, targetIndex);
// targets are already absolute file names
System.arraycopy(targetFiles, 0, result,
targetIndex,
targetFiles.length);
// targetIndex --> srcIndex
System.arraycopy(orig, targetIndex, result,
targetIndex + targetFiles.length,
srcIndex - targetIndex);
// srcIndex --> end
System.arraycopy(orig, srcIndex, result,
srcIndex + srcFiles.length + targetFiles.length,
orig.length - srcIndex);
srcIndex += targetFiles.length;
}
} else { // no targetFilePos
// 0 --> srcIndex
System.arraycopy(orig, 0, result, 0, srcIndex);
// srcIndex --> end
System.arraycopy(orig, srcIndex, result,
srcIndex + srcFiles.length,
orig.length - srcIndex);
}
// fill in source file names
for (int i = 0; i < srcFiles.length; i++) {
if (!relative) {
result[srcIndex + i] =
(new File(baseDirs[i], srcFiles[i])).getAbsolutePath();
} else {
result[srcIndex + i] = srcFiles[i];
}
if (forwardSlash && fileSeparator != '/") {
result[srcIndex + i] =
result[srcIndex + i].replace(fileSeparator, '/");
}
}
return result;
|
protected java.lang.String[] | getCommandline(java.lang.String srcFile, java.io.File baseDir)Construct the command line for serial execution.
return getCommandline(new String[] {srcFile}, new File[] {baseDir});
|
protected java.lang.String[] | getDirs(java.io.File baseDir, org.apache.tools.ant.DirectoryScanner ds)Return the list of Directories from this DirectoryScanner that
should be included on the command line.
return restrict(ds.getIncludedDirectories(), baseDir);
|
protected java.lang.String[] | getFiles(java.io.File baseDir, org.apache.tools.ant.DirectoryScanner ds)Return the list of files from this DirectoryScanner that should
be included on the command line.
return restrict(ds.getIncludedFiles(), baseDir);
|
protected java.lang.String[] | getFilesAndDirs(org.apache.tools.ant.types.FileList list)Return the list of files or directories from this FileList that
should be included on the command line.
return restrict(list.getFiles(getProject()), list.getDir(getProject()));
|
private java.lang.String[] | restrict(java.lang.String[] s, java.io.File baseDir)
return (mapper == null || force) ? s
: new SourceFileScanner(this).restrict(s, baseDir, destDir, mapper);
|
protected void | runExec(Execute exe)Run the specified Execute object.
int totalFiles = 0;
int totalDirs = 0;
boolean haveExecuted = false;
try {
Vector fileNames = new Vector();
Vector baseDirs = new Vector();
for (int i = 0; i < filesets.size(); i++) {
String currentType = type;
AbstractFileSet fs = (AbstractFileSet) filesets.elementAt(i);
if (fs instanceof DirSet) {
if (!FileDirBoth.DIR.equals(type)) {
log("Found a nested dirset but type is " + type + ". "
+ "Temporarily switching to type=\"dir\" on the"
+ " assumption that you really did mean"
+ " <dirset> not <fileset>.", Project.MSG_DEBUG);
currentType = FileDirBoth.DIR;
}
}
File base = fs.getDir(getProject());
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
if (!FileDirBoth.DIR.equals(currentType)) {
String[] s = getFiles(base, ds);
for (int j = 0; j < s.length; j++) {
totalFiles++;
fileNames.addElement(s[j]);
baseDirs.addElement(base);
}
}
if (!FileDirBoth.FILE.equals(currentType)) {
String[] s = getDirs(base, ds);
for (int j = 0; j < s.length; j++) {
totalDirs++;
fileNames.addElement(s[j]);
baseDirs.addElement(base);
}
}
if (fileNames.size() == 0 && skipEmpty) {
int includedCount
= ((!FileDirBoth.DIR.equals(currentType))
? ds.getIncludedFilesCount() : 0)
+ ((!FileDirBoth.FILE.equals(currentType))
? ds.getIncludedDirsCount() : 0);
log("Skipping fileset for directory " + base + ". It is "
+ ((includedCount > 0) ? "up to date." : "empty."),
Project.MSG_INFO);
continue;
}
if (!parallel) {
String[] s = new String[fileNames.size()];
fileNames.copyInto(s);
for (int j = 0; j < s.length; j++) {
String[] command = getCommandline(s[j], base);
log(Commandline.describeCommand(command),
Project.MSG_VERBOSE);
exe.setCommandline(command);
if (redirectorElement != null) {
setupRedirector();
redirectorElement.configure(redirector, s[j]);
}
if (redirectorElement != null || haveExecuted) {
// need to reset the stream handler to restart
// reading of pipes;
// go ahead and do it always w/ nested redirectors
exe.setStreamHandler(redirector.createHandler());
}
runExecute(exe);
haveExecuted = true;
}
fileNames.removeAllElements();
baseDirs.removeAllElements();
}
}
if (resources != null) {
Iterator iter = resources.iterator();
while (iter.hasNext()) {
Resource res = (Resource) iter.next();
if (!res.isExists() && ignoreMissing) {
continue;
}
File base = null;
String name = res.getName();
if (res instanceof FileResource) {
FileResource fr = (FileResource) res;
base = fr.getBaseDir();
if (base == null) {
name = fr.getFile().getAbsolutePath();
}
}
if (restrict(new String[] {name}, base).length == 0) {
continue;
}
if ((!res.isDirectory() || !res.isExists())
&& !FileDirBoth.DIR.equals(type)) {
totalFiles++;
} else if (res.isDirectory()
&& !FileDirBoth.FILE.equals(type)) {
totalDirs++;
} else {
continue;
}
baseDirs.add(base);
fileNames.add(name);
if (!parallel) {
String[] command = getCommandline(name, base);
log(Commandline.describeCommand(command),
Project.MSG_VERBOSE);
exe.setCommandline(command);
if (redirectorElement != null) {
setupRedirector();
redirectorElement.configure(redirector, name);
}
if (redirectorElement != null || haveExecuted) {
// need to reset the stream handler to restart
// reading of pipes;
// go ahead and do it always w/ nested redirectors
exe.setStreamHandler(redirector.createHandler());
}
runExecute(exe);
haveExecuted = true;
fileNames.removeAllElements();
baseDirs.removeAllElements();
}
}
}
if (parallel && (fileNames.size() > 0 || !skipEmpty)) {
runParallel(exe, fileNames, baseDirs);
haveExecuted = true;
}
if (haveExecuted) {
log("Applied " + cmdl.getExecutable() + " to "
+ totalFiles + " file"
+ (totalFiles != 1 ? "s" : "") + " and "
+ totalDirs + " director"
+ (totalDirs != 1 ? "ies" : "y") + ".",
verbose ? Project.MSG_INFO : Project.MSG_VERBOSE);
}
} catch (IOException e) {
throw new BuildException("Execute failed: " + e, e, getLocation());
} finally {
// close the output file if required
logFlush();
redirector.setAppendProperties(false);
redirector.setProperties();
}
|
protected void | runParallel(Execute exe, java.util.Vector fileNames, java.util.Vector baseDirs)Run the command in "parallel" mode, making sure that at most
maxParallel sourcefiles get passed on the command line.
String[] s = new String[fileNames.size()];
fileNames.copyInto(s);
File[] b = new File[baseDirs.size()];
baseDirs.copyInto(b);
if (maxParallel <= 0
|| s.length == 0 /* this is skipEmpty == false */) {
String[] command = getCommandline(s, b);
log(Commandline.describeCommand(command), Project.MSG_VERBOSE);
exe.setCommandline(command);
runExecute(exe);
} else {
int stillToDo = fileNames.size();
int currentOffset = 0;
while (stillToDo > 0) {
int currentAmount = Math.min(stillToDo, maxParallel);
String[] cs = new String[currentAmount];
System.arraycopy(s, currentOffset, cs, 0, currentAmount);
File[] cb = new File[currentAmount];
System.arraycopy(b, currentOffset, cb, 0, currentAmount);
String[] command = getCommandline(cs, cb);
log(Commandline.describeCommand(command), Project.MSG_VERBOSE);
exe.setCommandline(command);
if (redirectorElement != null) {
setupRedirector();
redirectorElement.configure(redirector, null);
}
if (redirectorElement != null || currentOffset > 0) {
// need to reset the stream handler to restart
// reading of pipes;
// go ahead and do it always w/ nested redirectors
exe.setStreamHandler(redirector.createHandler());
}
runExecute(exe);
stillToDo -= currentAmount;
currentOffset += currentAmount;
}
}
|
public void | setAddsourcefile(boolean b)Set whether to send the source file name on the command line.
Defaults to true .
addSourceFile = b;
|
public void | setDest(java.io.File destDir)Specify the directory where target files are to be placed.
this.destDir = destDir;
|
public void | setForce(boolean b)Set whether to bypass timestamp comparisons for target files.
force = b;
|
public void | setForwardslash(boolean forwardSlash)Set whether the source and target file names on Windows and OS/2
must use the forward slash as file separator.
this.forwardSlash = forwardSlash;
|
public void | setIgnoremissing(boolean b)Set whether to ignore nonexistent files from filelists.
ignoreMissing = b;
|
public void | setMaxParallel(int max)Limit the command line length by passing at maximum this many
sourcefiles at once to the command.
Set to <= 0 for unlimited - this is the default.
maxParallel = max;
|
public void | setParallel(boolean parallel)Set whether to execute in parallel mode.
If true, run the command only once, appending all files as arguments.
If false, command will be executed once for every file. Defaults to false.
this.parallel = parallel;
|
public void | setRelative(boolean relative)Set whether the filenames should be passed on the command line as
absolute or relative pathnames. Paths are relative to the base
directory of the corresponding fileset for source files or the
dest attribute for target files.
this.relative = relative;
|
public void | setSkipEmptyFilesets(boolean skip)Set whether empty filesets will be skipped. If true and
no source files have been found or are newer than their
corresponding target files, the command will not be run.
skipEmpty = skip;
|
public void | setType(org.apache.tools.ant.taskdefs.ExecuteOn$FileDirBoth type)Set whether the command works only on files, directories or both.
this.type = type.getValue();
|
public void | setVerbose(boolean b)Set whether to operate in verbose mode.
If true, a verbose summary will be printed after execution.
verbose = b;
|
protected void | setupRedirector()Set up the I/O Redirector.
super.setupRedirector();
redirector.setAppendProperties(true);
|