Author: bodewig
Date: Thu Dec 4 12:47:15 2008
New Revision: 723432
URL: http://svn.apache.org/viewvc?rev=723432&view=rev
Log:
Add resource collection support to replaceregexp. PR 46341.
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/docs/manual/OptionalTasks/replaceregexp.html
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=723432&r1=723431&r2=723432&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Dec 4 12:47:15 2008
@@ -594,6 +594,10 @@
all deleted targets and give a hint as to why it deleted them.
Bugzilla Report 13681.
+ * <replaceregexp> now supports arbitrary filesystem based resource
+ collections.
+ Bugzilla Report 46341.
+
Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================
Modified: ant/core/trunk/docs/manual/OptionalTasks/replaceregexp.html
URL:
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/OptionalTasks/replaceregexp.html?rev=723432&r1=723431&r2=723432&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/OptionalTasks/replaceregexp.html (original)
+++ ant/core/trunk/docs/manual/OptionalTasks/replaceregexp.html Thu Dec 4
12:47:15 2008
@@ -103,6 +103,9 @@
<h3>Parameters specified as nested elements</h3>
<p>This task supports a nested <a href="../CoreTypes/fileset.html">FileSet</a>
element.</p>
+<p>Since Ant 1.8.0 this task supports any filesystem
+ based <a href="../CoreTypes/resources.html#collection">resource
+ collections</a> as nested elements.</p>
<p>This task supports a nested <i><a
href="../CoreTypes/regexp.html">Regexp</a></i> element to specify
the regular expression. You can use this element to refer to a previously
defined regular expression datatype instance.</p>
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java?rev=723432&r1=723431&r2=723432&view=diff
==============================================================================
---
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
(original)
+++
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
Thu Dec 4 12:47:15 2008
@@ -30,14 +30,18 @@
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
-import java.util.Vector;
+import java.util.Iterator;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.RegularExpression;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.Substitution;
+import org.apache.tools.ant.types.resources.FileProvider;
+import org.apache.tools.ant.types.resources.Union;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.regexp.Regexp;
@@ -117,7 +121,7 @@
private File file;
private String flags;
private boolean byline;
- private Vector filesets; // Keep jdk 1.1 compliant so others can use this
+ private Union resources;
private RegularExpression regex;
private Substitution subs;
@@ -132,7 +136,6 @@
public ReplaceRegExp() {
super();
this.file = null;
- this.filesets = new Vector();
this.flags = "";
this.byline = false;
@@ -251,9 +254,23 @@
* @param set the fileset element
*/
public void addFileset(FileSet set) {
- filesets.addElement(set);
+ addConfigured(set);
}
+ /**
+ * Support arbitrary file system based resource collections.
+ *
+ * @since Ant 1.8.0
+ */
+ public void addConfigured(ResourceCollection rc) {
+ if (!rc.isFilesystemOnly()) {
+ throw new BuildException("only filesystem resources are
supported");
+ }
+ if (resources == null) {
+ resources = new Union();
+ }
+ resources.add(rc);
+ }
/**
* A regular expression.
@@ -475,9 +492,10 @@
throw new BuildException("Nothing to replace expression with.");
}
- if (file != null && filesets.size() > 0) {
+ if (file != null && resources != null) {
throw new BuildException("You cannot supply the 'file' attribute "
- + "and filesets at the same time.");
+ + "and resource collections at the same "
+ + "time.");
}
int options = 0;
@@ -511,16 +529,11 @@
+ file.getAbsolutePath() + "'", Project.MSG_ERR);
}
- int sz = filesets.size();
-
- for (int i = 0; i < sz; i++) {
- FileSet fs = (FileSet) (filesets.elementAt(i));
- DirectoryScanner ds = fs.getDirectoryScanner(getProject());
-
- String[] files = ds.getIncludedFiles();
-
- for (int j = 0; j < files.length; j++) {
- File f = new File(fs.getDir(getProject()), files[j]);
+ if (resources != null) {
+ for (Iterator i = resources.iterator(); i.hasNext(); ) {
+ FileProvider fp =
+ (FileProvider) ((Resource)
i.next()).as(FileProvider.class);
+ File f = fp.getFile();
if (f.exists()) {
try {