mbenson 2005/01/26 13:50:45
Modified: . Tag: ANT_16_BRANCH WHATSNEW
src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH
ExecuteOn.java
src/testcases/org/apache/tools/ant/taskdefs Tag:
ANT_16_BRANCH ExecuteOnTest.java
src/etc/testcases/taskdefs/exec Tag: ANT_16_BRANCH apply.xml
Log:
Merge apply changes from HEAD.
Revision Changes Path
No revision
No revision
1.503.2.164 +12 -0 ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/ant/WHATSNEW,v
retrieving revision 1.503.2.163
retrieving revision 1.503.2.164
diff -u -r1.503.2.163 -r1.503.2.164
--- WHATSNEW 26 Jan 2005 19:28:16 -0000 1.503.2.163
+++ WHATSNEW 26 Jan 2005 21:46:28 -0000 1.503.2.164
@@ -54,6 +54,12 @@
* Overloaded FileUtils.createNewFile with a boolean mkdirs attribute
to create nonexistent parent directories.
+* <apply> has a new "force" attribute that, when true, disables
+ checking of target files.
+
+* Made the dest attribute of the apply task optional; mapped target
+ filenames will be interpreted as absolute pathnames when dest is omitted.
+
Fixed bugs:
-----------
@@ -142,6 +148,12 @@
* DependScanner.getResource() always returned nonexistent resources,
even when the resource actually existed. Bugzilla Report 30558.
+* <apply> was broken with classfilesets. Bugzilla Report 30567.
+
+* <available> returned false positives when checking a file
+ passed in with the current basedir leading twice:
+ e.g. ${basedir}${file.separator}${basedir}${file.separator}foo .
+
Changes from Ant 1.6.1 to Ant 1.6.2
===================================
No revision
No revision
1.46.2.7 +119 -96 ant/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java
Index: ExecuteOn.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java,v
retrieving revision 1.46.2.6
retrieving revision 1.46.2.7
diff -u -r1.46.2.6 -r1.46.2.7
--- ExecuteOn.java 23 Jun 2004 19:17:12 -0000 1.46.2.6
+++ ExecuteOn.java 26 Jan 2005 21:47:39 -0000 1.46.2.7
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation.
+ * Copyright 2000-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,18 +43,6 @@
*/
public class ExecuteOn extends ExecTask {
- private class ExtendedDirectoryScanner extends DirectoryScanner {
- public int getIncludedFilesCount() {
- if (filesIncluded == null) throw new IllegalStateException();
- return filesIncluded.size();
- }
-
- public int getIncludedDirsCount() {
- if (dirsIncluded == null) throw new IllegalStateException();
- return dirsIncluded.size();
- }
- }
-
protected Vector filesets = new Vector(); // contains AbstractFileSet
// (both DirSet and FileSet)
private Vector filelists = new Vector();
@@ -72,6 +60,7 @@
private boolean addSourceFile = true;
private boolean verbose = false;
private boolean ignoreMissing = true;
+ private boolean force = false;
/**
* Has <srcfile> been specified before <targetfile>
@@ -79,14 +68,15 @@
protected boolean srcIsFirst = true;
/**
- * Source files to operate upon.
+ * Add a set of files upon which to operate.
+ * @param set the FileSet to add.
*/
public void addFileset(FileSet set) {
filesets.addElement(set);
}
/**
- * Adds directories to operate on.
+ * Add a set of directories upon which to operate.
*
* @param set the DirSet to add.
*
@@ -95,18 +85,21 @@
public void addDirset(DirSet set) {
filesets.addElement(set);
}
+
/**
- * Source files to operate upon.
+ * Add a list of source files upon which to operate.
+ * @param list the FileList to add.
*/
public void addFilelist(FileList list) {
filelists.addElement(list);
}
/**
- * Whether the filenames should be passed on the command line as
+ * 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.
+ * @param relative whether to pass relative pathnames.
*/
public void setRelative(boolean relative) {
this.relative = relative;
@@ -114,38 +107,45 @@
/**
+ * 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.
+ * @param parallel whether to run in parallel.
*/
public void setParallel(boolean parallel) {
this.parallel = parallel;
}
/**
- * Whether the command works only on files, directories or both?
+ * Set whether the command works only on files, directories or both.
+ * @param type a FileDirBoth EnumeratedAttribute.
*/
public void setType(FileDirBoth type) {
this.type = type.getValue();
}
/**
- * If no source files have been found or are newer than their
- * corresponding target files, do not run the command.
+ * 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.
+ * @param skip whether to skip empty filesets.
*/
public void setSkipEmptyFilesets(boolean skip) {
skipEmpty = skip;
}
/**
- * The directory where target files are to be placed.
+ * Specify the directory where target files are to be placed.
+ * @param destDir the File object representing the destination directory.
*/
public void setDest(File destDir) {
this.destDir = destDir;
}
/**
- * The source and target file names on Windows and OS/2 must use
- * forward slash as file separator.
+ * Set whether the source and target file names on Windows and OS/2
+ * must use the forward slash as file separator.
+ * @param forwardSlash whether the forward slash will be forced.
*/
public void setForwardslash(boolean forwardSlash) {
this.forwardSlash = forwardSlash;
@@ -157,6 +157,9 @@
*
* <p>Set to <= 0 for unlimited - this is the default.</p>
*
+ * @param max <code>int</code> maximum number of sourcefiles
+ * passed to the executable.
+ *
* @since Ant 1.6
*/
public void setMaxParallel(int max) {
@@ -164,10 +167,12 @@
}
/**
- * Whether to send the source file name on the command line.
+ * Set whether to send the source file name on the command line.
*
* <p>Defaults to <code>true</code>.
*
+ * @param b whether to add the source file to the command line.
+ *
* @since Ant 1.6
*/
public void setAddsourcefile(boolean b) {
@@ -175,7 +180,9 @@
}
/**
- * Whether to print a verbose summary after execution.
+ * Set whether to operate in verbose mode.
+ * If true, a verbose summary will be printed after execution.
+ * @param b whether to operate in verbose mode.
*
* @since Ant 1.6
*/
@@ -184,7 +191,8 @@
}
/**
- * Whether to ignore nonexistent files from filelists.
+ * Set whether to ignore nonexistent files from filelists.
+ * @param b whether to ignore missing files.
*
* @since Ant 1.6.2
*/
@@ -193,8 +201,19 @@
}
/**
- * Marker that indicates where the name of the source file should
- * be put on the command line.
+ * Set whether to bypass timestamp comparisons for target files.
+ * @param b whether to bypass timestamp comparisons.
+ *
+ * @since Ant 1.6.3
+ */
+ public void setForce(boolean b) {
+ force = b;
+ }
+
+ /**
+ * Create a placeholder indicating where on the command line
+ * the name of the source file should be inserted.
+ * @return <code>Commandline.Marker</code>.
*/
public Commandline.Marker createSrcfile() {
if (srcFilePos != null) {
@@ -206,8 +225,9 @@
}
/**
- * Marker that indicates where the name of the target file should
- * be put on the command line.
+ * Create a placeholder indicating where on the command line
+ * the name of the target file should be inserted.
+ * @return <code>Commandline.Marker</code>.
*/
public Commandline.Marker createTargetfile() {
if (targetFilePos != null) {
@@ -220,7 +240,10 @@
}
/**
- * Mapper to use for mapping source files to target files.
+ * Create a nested Mapper element to use for mapping
+ * source files to target files.
+ * @return <code>Mapper</code>.
+ * @throws BuildException if more than one mapper is defined.
*/
public Mapper createMapper() throws BuildException {
if (mapperElement != null) {
@@ -232,51 +255,71 @@
}
/**
- * @todo using taskName here is brittle, as a user could override it.
- * this should probably be modified to use the classname instead.
+ * Add a nested FileNameMapper.
+ * @param fileNameMapper the mapper to add.
+ * @since Ant 1.6.3
+ */
+ public void add(FileNameMapper fileNameMapper) {
+ createMapper().add(fileNameMapper);
+ }
+
+ /**
+ * Check the configuration of this ExecuteOn instance.
*/
protected void checkConfiguration() {
+// * @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 && filelists.size() == 0) {
throw new BuildException("no filesets and no filelists
specified",
getLocation());
}
-
- if (targetFilePos != null || mapperElement != null
- || destDir != null) {
-
- if (mapperElement == null) {
- throw new BuildException("no mapper specified",
getLocation());
- }
- if (destDir == null) {
- throw new BuildException("no dest attribute 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();
}
}
+ /**
+ * Create the ExecuteStreamHandler instance that will be used
+ * during execution.
+ * @return <code>ExecuteStreamHandler</code>.
+ * @throws BuildException on error.
+ */
protected ExecuteStreamHandler createHandler() throws BuildException {
//if we have a RedirectorElement, return a decoy
return (redirectorElement == null)
? super.createHandler() : new PumpStreamHandler();
}
+ /**
+ * Set up the I/O Redirector.
+ */
protected void setupRedirector() {
super.setupRedirector();
redirector.setAppendProperties(true);
}
+ /**
+ * Run the specified Execute object.
+ * @param exe the Execute instance representing the external process.
+ * @throws BuildException on error
+ */
protected void runExec(Execute exe) throws BuildException {
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++) {
@@ -293,10 +336,7 @@
}
File base = fs.getDir(getProject());
- ExtendedDirectoryScanner ds = new ExtendedDirectoryScanner();
- fs.setupDirectoryScanner(ds, getProject());
- ds.setFollowSymlinks(fs.isFollowSymlinks());
- ds.scan();
+ DirectoryScanner ds = fs.getDirectoryScanner(getProject());
if (!"dir".equals(currentType)) {
String[] s = getFiles(base, ds);
@@ -306,7 +346,6 @@
baseDirs.addElement(base);
}
}
-
if (!"file".equals(currentType)) {
String[] s = getDirs(base, ds);
for (int j = 0; j < s.length; j++) {
@@ -315,7 +354,6 @@
baseDirs.addElement(base);
}
}
-
if (fileNames.size() == 0 && skipEmpty) {
int includedCount
= ((!"dir".equals(currentType))
@@ -328,7 +366,6 @@
Project.MSG_INFO);
continue;
}
-
if (!parallel) {
String[] s = new String[fileNames.size()];
fileNames.copyInto(s);
@@ -342,7 +379,6 @@
setupRedirector();
redirectorElement.configure(redirector, s[j]);
}
-
if (redirectorElement != null || haveExecuted) {
// need to reset the stream handler to restart
// reading of pipes;
@@ -356,7 +392,6 @@
baseDirs.removeAllElements();
}
}
-
for (int i = 0; i < filelists.size(); i++) {
FileList list = (FileList) filelists.elementAt(i);
File base = list.getDir(getProject());
@@ -372,14 +407,12 @@
} else {
totalDirs++;
}
-
fileNames.addElement(names[j]);
baseDirs.addElement(base);
}
}
-
if (fileNames.size() == 0 && skipEmpty) {
- ExtendedDirectoryScanner ds = new
ExtendedDirectoryScanner();
+ DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(base);
ds.setIncludes(list.getFiles(getProject()));
ds.scan();
@@ -391,7 +424,6 @@
Project.MSG_INFO);
continue;
}
-
if (!parallel) {
String[] s = new String[fileNames.size()];
fileNames.copyInto(s);
@@ -405,7 +437,6 @@
setupRedirector();
redirectorElement.configure(redirector, s[j]);
}
-
if (redirectorElement != null || haveExecuted) {
// need to reset the stream handler to restart
// reading of pipes;
@@ -419,12 +450,10 @@
baseDirs.removeAllElements();
}
}
-
if (parallel && (fileNames.size() > 0 || !skipEmpty)) {
runParallel(exe, fileNames, baseDirs);
haveExecuted = true;
}
-
if (haveExecuted) {
log("Applied " + cmdl.getExecutable() + " to "
+ totalFiles + " file"
@@ -433,7 +462,6 @@
+ (totalDirs != 1 ? "ies" : "y") + ".",
verbose ? Project.MSG_INFO : Project.MSG_VERBOSE);
}
-
} catch (IOException e) {
throw new BuildException("Execute failed: " + e, e,
getLocation());
} finally {
@@ -447,8 +475,9 @@
/**
* Construct the command line for parallel execution.
*
- * @param srcFiles The filenames to add to the commandline
- * @param baseDirs filenames are relative to this dir
+ * @param srcFiles The filenames to add to the commandline.
+ * @param baseDirs filenames are relative to this dir.
+ * @return the command line in the form of a String[].
*/
protected String[] getCommandline(String[] srcFiles, File[] baseDirs) {
final char fileSeparator = File.separatorChar;
@@ -482,7 +511,6 @@
if (!addSourceFile) {
srcFiles = new String[0];
}
-
String[] orig = cmdl.getCommandline();
String[] result
= new String[orig.length + srcFiles.length + targetFiles.length];
@@ -491,7 +519,6 @@
if (srcFilePos != null) {
srcIndex = srcFilePos.getPosition();
}
-
if (targetFilePos != null) {
int targetIndex = targetFilePos.getPosition();
@@ -544,9 +571,7 @@
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) {
@@ -566,8 +591,9 @@
/**
* Construct the command line for serial execution.
*
- * @param srcFile The filename to add to the commandline
- * @param baseDir filename is relative to this dir
+ * @param srcFile The filename to add to the commandline.
+ * @param baseDir filename is relative to this dir.
+ * @return the command line in the form of a String[].
*/
protected String[] getCommandline(String srcFile, File baseDir) {
return getCommandline(new String[] {srcFile}, new File[] {baseDir});
@@ -576,52 +602,50 @@
/**
* Return the list of files from this DirectoryScanner that should
* be included on the command line.
+ * @param baseDir the File base directory.
+ * @param ds the DirectoryScanner to use for file scanning.
+ * @return a String[] containing the filenames.
*/
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 restrict(ds.getIncludedFiles(), baseDir);
}
/**
* Return the list of Directories from this DirectoryScanner that
* should be included on the command line.
+ * @param baseDir the File base directory.
+ * @param ds the DirectoryScanner to use for file scanning.
+ * @return a String[] containing the directory names.
*/
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();
- }
+ return restrict(ds.getIncludedDirectories(), baseDir);
}
/**
* Return the list of files or directories from this FileList that
* should be included on the command line.
+ * @param list the FileList to check.
+ * @return a String[] containing the directory names.
*
* @since Ant 1.6.2
*/
protected String[] getFilesAndDirs(FileList list) {
- if (mapper != null) {
- SourceFileScanner sfs = new SourceFileScanner(this);
- return sfs.restrict(list.getFiles(getProject()),
- list.getDir(getProject()), destDir,
- mapper);
- } else {
- return list.getFiles(getProject());
- }
+ return restrict(list.getFiles(getProject()),
list.getDir(getProject()));
+ }
+
+ private String[] restrict(String[] s, File baseDir) {
+ return (mapper == null || force) ? s
+ : new SourceFileScanner(this).restrict(s, baseDir, destDir,
mapper);
}
/**
- * Runs the command in "parallel" mode, making sure that at most
+ * Run the command in "parallel" mode, making sure that at most
* maxParallel sourcefiles get passed on the command line.
- *
+ * @param exe the Executable to use.
+ * @param fileNames the Vector of filenames.
+ * @param baseDirs the Vector of base directories corresponding to
fileNames.
+ * @throws IOException on I/O errors.
+ * @throws BuildException on other errors.
* @since Ant 1.6
*/
protected void runParallel(Execute exe, Vector fileNames,
@@ -654,7 +678,6 @@
setupRedirector();
redirectorElement.configure(redirector, null);
}
-
if (redirectorElement != null || currentOffset > 0) {
// need to reset the stream handler to restart
// reading of pipes;
No revision
No revision
1.6.2.2 +10 -2
ant/src/testcases/org/apache/tools/ant/taskdefs/ExecuteOnTest.java
Index: ExecuteOnTest.java
===================================================================
RCS file:
/home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/ExecuteOnTest.java,v
retrieving revision 1.6.2.1
retrieving revision 1.6.2.2
diff -u -r1.6.2.1 -r1.6.2.2
--- ExecuteOnTest.java 23 Jun 2004 19:30:14 -0000 1.6.2.1
+++ ExecuteOnTest.java 26 Jan 2005 21:48:36 -0000 1.6.2.2
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 The Apache Software Foundation.
+ * Copyright 2004-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -554,13 +554,21 @@
executeTarget("ignoremissing");
}
+ public void testForce() {
+ executeTarget("force");
+ }
+
+ public void testNoDest() {
+ executeTarget("testNoDest");
+ }
+
//borrowed from TokenFilterTest
private String getFileString(String filename) throws IOException {
String result = null;
FileReader reader = null;
try {
reader = new FileReader(getProject().resolveFile(filename));
- result = FileUtils.newFileUtils().readFully(reader);
+ result = FileUtils.readFully(reader);
} finally {
if (reader != null) {
try {
No revision
No revision
1.3.2.4 +57 -4 ant/src/etc/testcases/taskdefs/exec/apply.xml
Index: apply.xml
===================================================================
RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/exec/apply.xml,v
retrieving revision 1.3.2.3
retrieving revision 1.3.2.4
diff -u -r1.3.2.3 -r1.3.2.4
--- apply.xml 13 Jul 2004 16:11:27 -0000 1.3.2.3
+++ apply.xml 26 Jan 2005 21:49:13 -0000 1.3.2.4
@@ -313,10 +313,7 @@
</apply>
</target>
- <target name="ignoremissing" depends="init,xyz" if="echo.can.run">
- <filelist id="xylist" dir="${basedir}" files="x,y" />
- <delete file="z" />
-
+ <target name="pad">
<condition property="pad" value="">
<or>
<not>
@@ -341,6 +338,12 @@
</and>
</condition>
+ </target>
+
+ <target name="ignoremissing" depends="init,xyz,pad" if="echo.can.run">
+ <filelist id="xylist" dir="${basedir}" files="x,y" />
+ <delete file="z" />
+
<pathconvert property="xy" pathsep="${pad}${line.separator}">
<path>
<filelist refid="xylist" />
@@ -375,6 +378,56 @@
</fail>
</target>
+ <target name="force" depends="init,xyz,pad" if="echo.can.run">
+ <presetdef name="ekko">
+ <apply executable="echo" append="true" dest="${basedir}">
+ <filelist refid="xyzlist" />
+ <mapper type="identity" />
+ </apply>
+ </presetdef>
+
+ <pathconvert property="xyz" pathsep="${pad}${line.separator}">
+ <path>
+ <filelist refid="xyzlist" />
+ </path>
+ </pathconvert>
+
+ <ekko outputproperty="foo" />
+ <ekko outputproperty="bar" force="true" />
+ <fail>
+ <condition>
+ <not>
+ <and>
+ <equals arg1="${foo}" arg2="" />
+ <equals arg1="${bar}" arg2="${xyz}" />
+ </and>
+ </not>
+ </condition>
+ </fail>
+ </target>
+
+ <target name="testNoDest" depends="init,xyz" if="echo.can.run">
+ <presetdef name="ekko">
+ <apply executable="echo" addsourcefile="false" force="true">
+ <filelist dir="${basedir}" files="x" />
+ <globmapper from="*" to="${basedir}/*" />
+ <targetfile />
+ </apply>
+ </presetdef>
+ <ekko outputproperty="dest" dest="${basedir}" />
+ <ekko outputproperty="nodest" />
+ <fail>
+ <condition>
+ <or>
+ <available file="${dest}" />
+ <not>
+ <available file="${nodest}" />
+ </not>
+ </or>
+ </condition>
+ </fail>
+ </target>
+
<target name="cleanup">
<delete>
<fileset refid="xyz" />
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]