diff --git a/WHATSNEW b/WHATSNEW
index 944222ef2..df82bd9aa 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -108,6 +108,8 @@ Other changes:
* New update attribute for The name execon is deprecated and only kept for backwards
+compatibilty. Executes a system command. When the os attribute is specified, then
the command is only executed when Ant is run on one of the specified operating
systems. The files and/or directories of a number of FileSets are passed as arguments to the system
-command. The timestamp of each source file is compared to the
-timestamp of a target file which is defined by a nested mapper element. At least one fileset and exactly
-one mapper element are required.Apply
+Apply/ExecOn
+Description
If you specify a nested mapper and the destdir attribute, +the timestamp of each source file is compared to the timestamp of a +target file which is defined by the nested mapper element and searched +for in the given destdir.
+At least one fileset is required, you must not specify more than +one mapper.
the directory where the <apply> expects the target files will be placed by the command, when it is executed. | -Yes | +Yes, if you specify a nested mapper |
dir | @@ -67,12 +73,6 @@ one mapper element are required. returncode other than 0.No | |
newenvironment | -Do not propagate old environment when new environment - variables are specified. | -No, default is false | -
skipemptyfilesets | Don't run the command, if no source files have @@ -95,6 +95,23 @@ one mapper element are required. the names of directories are considered. | No, default is file |
newenvironment | +Do not propagate old environment when new environment + variables are specified. | +No, default is false | +
vmlauncher | +Run command using the Java VM's execution facilities + where available. If set to false the underlying OS's shell, + either directly or through the antRun scripts, will be used. + Under some operating systems, this gives access to facilities + not normally available through the VM including, under Windows, + being able to execute scripts, rather than their associated + interpreter. | +No, default is true | +
<srcfile>
element between your
<targetfile>
is similar to
<srcfile>
and marks the position of the target
filename on the command line. If omitted, the target filenames will
-not be added to the command line at all.
It is possible to specify environment variables to pass to the
system command via nested <env>
elements. See the
@@ -124,6 +143,34 @@ description in the section about exec
<env>
.
++<apply executable="ls" > + <arg value="-l"/> + <fileset dir="/tmp"> + <patternset> + <exclude name="**/*.txt"/> + </patternset> + </fileset> + <fileset refid="other.files"/> +</apply> +
invokes ls -l
, adding the absolute filenames of all
+files below /tmp
not ending in .txt
and all
+files of the FileSet with id
other.files
to
+the command line.
++<apply executable="somecommand" parallel="false" > + <arg value="arg1"/> + <srfile/> + <arg value="arg2"/> + <fileset dir="/tmp"/> +</apply> +
invokes somecommand arg1 SOURCEFILENAME arg2
for each
+file in /tmp
replacing SOURCEFILENAME with the absolute
+filename of each file in turn. If parallel
had been set
+to true, SOURCEFILENAME would be replaced with the absolute filenames
+of all files separated by spaces.
<apply executable="cc" dest="src/C" parallel="false"> <arg value="-c"/> <arg value="-o"/> diff --git a/docs/manual/CoreTasks/execon.html b/docs/manual/CoreTasks/execon.html deleted file mode 100644 index f00b90f50..000000000 --- a/docs/manual/CoreTasks/execon.html +++ /dev/null @@ -1,156 +0,0 @@ - - - - -Ant User Manual - - - - -ExecOn
-Description
-Executes a system command. When the os attribute is specified, then -the command is only executed when Ant is run on one of the specified operating -systems.
-The files and/or directories of a number of FileSets are passed as arguments to the system -command. At least one nested
-<fileset>
is required.Parameters
--
-- -Attribute -Description -Required -- -executable -the command to execute without any command line - arguments. -Yes -- -dir -the directory in which the command should be executed. -No -- -os -list of Operating Systems on which the command may be - executed. If the current OS's name is contained in this list, the command will - be executed. The OS's name is determined by the Java Virtual machine and is set - in the "os.name" system property. -- -output -the file to which the output of the command should be - redirected. -No -- -timeout -Stop the command if it doesn't finish within the - specified time (given in milliseconds). -No -- -failonerror -Stop the buildprocess if the command exits with a - returncode other than 0. -No -- -newenvironment -Do not propagate old environment when new environment - variables are specified. -No, default is false -- -vmlauncher -Run command using the Java VM's execution facilities - where available. If set to false the underlying OS's shell, - either directly or through the antRun scripts, will be used. - Under some operating systems, this gives access to facilities - not nomrally available through the VM including, under Windows, - being able to execute scripts, rather than their associated - interpreter. -No, default is true -- -skipemptyfilesets -Don't run the command, if no source files have - been found. -No, default is false -- -parallel -Run the command only once, appending all files as - arguments. If false, command will be executed once for every file. - Defaults to false. -No -- -type -One of file, dir or - both. If set to file, only the names of plain - files will be sent to the command. If set to dir, only - the names of directories are considered. -No, default is file -Parameters specified as nested elements
-fileset
-You can use any number of nested
-<fileset>
-elements to define the files for this task and refer to -<fileset>
s defined elsewhere.arg
-Command line arguments should be specified as nested -
-<arg>
elements. See Command line arguments.srcfile
-By default the file names of the source files will be added to the -end of the command line. If you need to place it somewhere different, -use a nested
-<srcfile>
element between your -<arg>
elements to mark the insertion point.env
-It is possible to specify environment variables to pass to the -system command via nested
-<env>
elements. See the -description in the section about execPlease note that the environment of the current Ant process is -not passed to the system command if you specify variables using -
-<env>
.Examples
---<execon executable="ls" > - <arg value="-l"/> - <fileset dir="/tmp"> - <patternset> - <exclude name="**/*.txt"/> - </patternset> - </fileset> - <fileset refid="other.files"/> -</execon> -invokes
-ls -l
, adding the absolute filenames of all -files below/tmp
not ending in.txt
and all -files of the FileSet withid
other.files
to -the command line.--<execon executable="somecommand" parallel="false" > - <arg value="arg1"/> - <srfile/> - <arg value="arg2"/> - <fileset dir="/tmp"/> -</execon> -invokes
-somecommand arg1 SOURCEFILENAME arg2
for each -file in/tmp
replacing SOURCEFILENAME with the absolute -filename of each file in turn. Ifparallel
had been set -to true, SOURCEFILENAME would be replaced with the absolute filenames -of all files separated by spaces.
-Copyright © 2000,2001 Apache Software Foundation. All rights -Reserved.
- - - - diff --git a/docs/manual/coretasklist.html b/docs/manual/coretasklist.html index d4af74027..91c1903b2 100644 --- a/docs/manual/coretasklist.html +++ b/docs/manual/coretasklist.html @@ -23,7 +23,7 @@ Ant
AntCall
AntStructure
-Apply
+Apply/ExecOn
Available
Chmod
Copy
@@ -36,7 +36,6 @@ Ear
Echo
Exec
-ExecOn
Fail
Filter
FixCRLF
diff --git a/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java b/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java index 58bea1cf4..398385a81 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java +++ b/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java @@ -56,7 +56,9 @@ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.*; import org.apache.tools.ant.types.*; +import org.apache.tools.ant.util.*; +import java.util.Hashtable; import java.util.Vector; import java.io.File; import java.io.IOException; @@ -74,6 +76,15 @@ public class ExecuteOn extends ExecTask { protected String type = "file"; protected Commandline.Marker srcFilePos = null; private boolean skipEmpty = false; + protected Commandline.Marker targetFilePos = null; + protected Mapper mapperElement = null; + protected FileNameMapper mapper = null; + protected File destDir = null; + + /** + * Has <srcfile> been specified before <targetfile> + */ + protected boolean srcIsFirst = true; /** * Adds a set of files (nested fileset attribute). @@ -103,6 +114,13 @@ public class ExecuteOn extends ExecTask { skipEmpty = skip; } + /** + * Set the destination directory. + */ + public void setDest(File destDir) { + this.destDir = destDir; + } + /** * Marker that indicates where the name of the source file should * be put on the command line. @@ -116,18 +134,62 @@ public class ExecuteOn extends ExecTask { return srcFilePos; } + /** + * Marker that indicates where the name of the target file should + * be put on the command line. + */ + public Commandline.Marker createTargetfile() { + if (targetFilePos != null) { + throw new BuildException(taskType + " doesn\'t support multiple targetfile elements.", + location); + } + targetFilePos = cmdl.createMarker(); + srcIsFirst = (srcFilePos != null); + return targetFilePos; + } + + /** + * Defines the FileNameMapper to use (nested mapper element). + */ + public Mapper createMapper() throws BuildException { + if (mapperElement != null) { + throw new BuildException("Cannot define more than one mapper", + location); + } + mapperElement = new Mapper(project); + return mapperElement; + } + protected void checkConfiguration() { + if ("execon".equals(taskName)) { + log("!! execon is deprecated. Use apply instead. !!"); + } + super.checkConfiguration(); if (filesets.size() == 0) { throw new BuildException("no filesets specified", location); } + + if (targetFilePos != null || mapperElement != null + || destDir != null) { + + if (mapperElement == null) { + throw new BuildException("no mapper specified", location); + } + if (mapperElement == null) { + throw new BuildException("no dest attribute specified", + location); + } + mapper = mapperElement.getImplementation(); + } } protected void runExec(Execute exe) throws BuildException { try { + Vector fileNames = new Vector(); + Vector baseDirs = new Vector(); for (int i=0; isrcIndex + 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 + System.arraycopy(orig, 0, result, 0, srcIndex); + } + + // fill in source file names for (int i=0; i < srcFiles.length; i++) { - result[index+i] = (new File(baseDir, srcFiles[i])).getAbsolutePath(); + result[srcIndex+i] = + (new File(baseDirs[i], srcFiles[i])).getAbsolutePath(); } - - System.arraycopy(orig, index, result, index+srcFiles.length, - orig.length-index); return result; } @@ -215,23 +348,35 @@ public class ExecuteOn extends ExecTask { * @param baseDir filename is relative to this dir */ protected String[] getCommandline(String srcFile, File baseDir) { - return getCommandline(new String[] {srcFile}, baseDir); + return getCommandline(new String[] {srcFile}, new File[] {baseDir}); } /** * Return the list of files from this DirectoryScanner that should * be included on the command line. */ - protected String[] getFiles(File basedir, DirectoryScanner ds) { - return ds.getIncludedFiles(); + protected String[] getFiles(File baseDir, DirectoryScanner ds) { + if (mapper != null) { + SourceFileScanner sfs = new SourceFileScanner(this); + return sfs.restrict(ds.getIncludedFiles(), baseDir, destDir, + mapper); + } else { + return ds.getIncludedFiles(); + } } /** * Return the list of Directories from this DirectoryScanner that * should be included on the command line. */ - protected String[] getDirs(File basedir, DirectoryScanner ds) { - return ds.getIncludedDirectories(); + protected String[] getDirs(File baseDir, DirectoryScanner ds) { + if (mapper != null) { + SourceFileScanner sfs = new SourceFileScanner(this); + return sfs.restrict(ds.getIncludedDirectories(), baseDir, destDir, + mapper); + } else { + return ds.getIncludedDirectories(); + } } /** diff --git a/src/main/org/apache/tools/ant/taskdefs/Transform.java b/src/main/org/apache/tools/ant/taskdefs/Transform.java index c48928276..7420dd251 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Transform.java +++ b/src/main/org/apache/tools/ant/taskdefs/Transform.java @@ -54,193 +54,9 @@ package org.apache.tools.ant.taskdefs; -import java.io.File; -import java.util.Hashtable; -import java.util.Vector; - -import org.apache.tools.ant.*; -import org.apache.tools.ant.types.*; -import org.apache.tools.ant.util.*; - /** - * Executes a given command, supplying a set of files as arguments. - * - * Only those files that are newer than their corresponding target - * files will be handeled, the rest will be ignored.
+ * Has been merged into ExecuteOn, empty class for backwards compatibility. * * @author Stefan Bodewig */ -public class Transform extends ExecuteOn { - - protected Commandline.Marker targetFilePos = null; - protected Mapper mapperElement = null; - protected FileNameMapper mapper = null; - protected File destDir = null; - - /** - * Has <srcfile> been specified before <targetfile> - */ - protected boolean srcIsFirst = true; - - /** - * Set the destination directory. - */ - public void setDest(File destDir) { - this.destDir = destDir; - } - - /** - * Marker that indicates where the name of the target file should - * be put on the command line. - */ - public Commandline.Marker createTargetfile() { - if (targetFilePos != null) { - throw new BuildException(taskType + " doesn\'t support multiple targetfile elements.", - location); - } - targetFilePos = cmdl.createMarker(); - srcIsFirst = (srcFilePos != null); - return targetFilePos; - } - - /** - * Defines the FileNameMapper to use (nested mapper element). - */ - public Mapper createMapper() throws BuildException { - if (mapperElement != null) { - throw new BuildException("Cannot define more than one mapper", - location); - } - mapperElement = new Mapper(project); - return mapperElement; - } - - protected void checkConfiguration() { - super.checkConfiguration(); - if (mapperElement == null) { - throw new BuildException("no mapper specified", location); - } - if (destDir == null) { - throw new BuildException("no dest attribute specified", location); - } - - mapper = mapperElement.getImplementation(); - } - - /** - * Return the list of files from this DirectoryScanner that should - * be included on the command line - i.e. only those that are - * newer than the corresponding target files. - */ - protected String[] getFiles(File baseDir, DirectoryScanner ds) { - SourceFileScanner sfs = new SourceFileScanner(this); - return sfs.restrict(ds.getIncludedFiles(), baseDir, destDir, mapper); - } - - /** - * Return the list of Directories from this DirectoryScanner that - * should be included on the command line - i.e. only those that - * are newer than the corresponding target files. - */ - protected String[] getDirs(File baseDir, DirectoryScanner ds) { - SourceFileScanner sfs = new SourceFileScanner(this); - return sfs.restrict(ds.getIncludedDirectories(), baseDir, destDir, - mapper); - } - - /** - * Construct the command line for parallel execution. - * - * @param srcFiles The filenames to add to the commandline - * @param baseDir filenames are relative to this dir - */ - protected String[] getCommandline(String[] srcFiles, File baseDir) { - if (targetFilePos == null) { - return super.getCommandline(srcFiles, baseDir); - } - - Vector targets = new Vector(); - Hashtable addedFiles = new Hashtable(); - for (int i=0; isrcIndex - 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; - } - - - for (int i=0; i < srcFiles.length; i++) { - result[srcIndex+i] = - (new File(baseDir, srcFiles[i])).getAbsolutePath(); - } - return result; - - } - - /** - * Construct the command line for serial execution. - * - * @param srcFile The filename to add to the commandline - * @param baseDir filename is relative to this dir - */ - protected String[] getCommandline(String srcFile, File baseDir) { - return getCommandline(new String[] {srcFile}, baseDir); - } - -} +public class Transform extends ExecuteOn {}