Author: bodewig
Date: Fri Dec 5 07:38:38 2008
New Revision: 723766
URL: http://svn.apache.org/viewvc?rev=723766&view=rev
Log:
make <replace> support resource collections. PR 24062.
Added:
ant/core/trunk/src/tests/antunit/taskdefs/replace-test.xml (with props)
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/docs/manual/CoreTasks/replace.html
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=723766&r1=723765&r2=723766&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Dec 5 07:38:38 2008
@@ -598,6 +598,10 @@
collections.
Bugzilla Report 46341.
+ * <replace> now supports arbitrary filesystem based resource
+ collections.
+ Bugzilla Report 24062.
+
Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================
Modified: ant/core/trunk/docs/manual/CoreTasks/replace.html
URL:
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/replace.html?rev=723766&r1=723765&r2=723766&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/replace.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/replace.html Fri Dec 5 07:38:38 2008
@@ -130,6 +130,9 @@
supports all attributes of <code><fileset></code> as well as the
nested <code><include></code>, <code><exclude></code> and
<code><patternset></code> elements.</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>If either the text you want to replace or the replacement text
cross line boundaries, you can use nested elements to specify
them.</p>
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java?rev=723766&r1=723765&r2=723766&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java Fri Dec
5 07:38:38 2008
@@ -32,11 +32,15 @@
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
-import java.util.Enumeration;
+import java.util.Iterator;
import java.util.Properties;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.ResourceCollection;
+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.StringUtils;
@@ -55,7 +59,7 @@
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
- private File src = null;
+ private File sourceFile = null;
private NestedString token = null;
private NestedString value = new NestedString();
@@ -73,6 +77,8 @@
/** The encoding used to read and write files - if null, uses default */
private String encoding = null;
+ private Union resources;
+
/**
* An inline string to use as the replacement text.
*/
@@ -464,9 +470,9 @@
try {
if (replaceFilterFile != null) {
Properties props = getProperties(replaceFilterFile);
- Enumeration e = props.keys();
- while (e.hasMoreElements()) {
- String tok = e.nextElement().toString();
+ Iterator e = props.keySet().iterator();
+ while (e.hasNext()) {
+ String tok = e.next().toString();
Replacefilter replaceFilter = createReplacefilter();
replaceFilter.setToken(tok);
replaceFilter.setValue(props.getProperty(tok));
@@ -483,8 +489,8 @@
fileCount = 0;
replaceCount = 0;
- if (src != null) {
- processFile(src);
+ if (sourceFile != null) {
+ processFile(sourceFile);
}
if (dir != null) {
@@ -497,6 +503,15 @@
}
}
+ if (resources != null) {
+ for (Iterator i = resources.iterator(); i.hasNext(); ) {
+ FileProvider fp =
+ (FileProvider) ((Resource) i.next())
+ .as(FileProvider.class);
+ processFile(fp.getFile());
+ }
+ }
+
if (summary) {
log("Replaced " + replaceCount + " occurrences in "
+ fileCount + " files.", Project.MSG_INFO);
@@ -515,9 +530,9 @@
* mandatory attribute is missing.
*/
public void validateAttributes() throws BuildException {
- if (src == null && dir == null) {
+ if (sourceFile == null && dir == null && resources == null) {
String message = "Either the file or the dir attribute "
- + "must be specified";
+ + "or nested resources must be specified";
throw new BuildException(message, getLocation());
}
if (propertyFile != null && !propertyFile.exists()) {
@@ -704,7 +719,7 @@
* @param file source <code>File</code>.
*/
public void setFile(File file) {
- this.src = file;
+ this.sourceFile = file;
}
/**
@@ -808,6 +823,21 @@
}
/**
+ * 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);
+ }
+
+ /**
* Adds the token and value as first <replacefilter> element.
* The token and value are always processed first.
* @return a nested <code>Replacefilter</code> object to be configured.
Added: ant/core/trunk/src/tests/antunit/taskdefs/replace-test.xml
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/replace-test.xml?rev=723766&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/replace-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/taskdefs/replace-test.xml Fri Dec 5
07:38:38 2008
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
+ <import file="../antunit-base.xml" />
+
+ <target name="testRCSupport">
+ <mkdir dir="${output}"/>
+ <echo file="${output}/text.txt"><![CDATA[
+Hello, world!
+]]></echo>
+ <replace token="world" value="Ant">
+ <file file="${output}/text.txt"/>
+ </replace>
+ <au:assertResourceContains
+ resource="${output}/text.txt" value="Hello, Ant!"/>
+ </target>
+</project>
Propchange: ant/core/trunk/src/tests/antunit/taskdefs/replace-test.xml
------------------------------------------------------------------------------
svn:eol-style = native