You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by an...@apache.org on 2006/06/06 10:23:02 UTC
svn commit: r412040 - in /ant/core/trunk: ./ docs/manual/CoreTypes/
src/etc/testcases/filters/ src/etc/testcases/filters/input/
src/main/org/apache/tools/ant/filters/
src/testcases/org/apache/tools/ant/filters/
Author: antoine
Date: Tue Jun 6 01:23:01 2006
New Revision: 412040
URL: http://svn.apache.org/viewvc?rev=412040&view=rev
Log:
ReplaceTokens should allow properties files.
Bugzilla 39688
Added:
ant/core/trunk/src/etc/testcases/filters/input/sample.properties
Modified:
ant/core/trunk/CONTRIBUTORS
ant/core/trunk/WHATSNEW
ant/core/trunk/contributors.xml
ant/core/trunk/docs/manual/CoreTypes/filterchain.html
ant/core/trunk/src/etc/testcases/filters/build.xml
ant/core/trunk/src/main/org/apache/tools/ant/filters/ReplaceTokens.java
ant/core/trunk/src/testcases/org/apache/tools/ant/filters/ReplaceTokensTest.java
Modified: ant/core/trunk/CONTRIBUTORS
URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=412040&r1=412039&r2=412040&view=diff
==============================================================================
Binary files - no diff available.
Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=412040&r1=412039&r2=412040&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Jun 6 01:23:01 2006
@@ -424,6 +424,8 @@
* new <antversion> condition. Bugzilla report 32804.
+* ReplaceTokens should allow properties files. Bugzilla report 39688.
+
Changes from Ant 1.6.4 to Ant 1.6.5
===================================
Modified: ant/core/trunk/contributors.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?rev=412040&r1=412039&r2=412040&view=diff
==============================================================================
--- ant/core/trunk/contributors.xml (original)
+++ ant/core/trunk/contributors.xml Tue Jun 6 01:23:01 2006
@@ -927,6 +927,10 @@
</name>
<name>
<first>Tom</first>
+ <last>Cunningham</last>
+ </name>
+ <name>
+ <first>Tom</first>
<last>Dimock</last>
</name>
<name>
Modified: ant/core/trunk/docs/manual/CoreTypes/filterchain.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/filterchain.html?rev=412040&r1=412039&r2=412040&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/filterchain.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/filterchain.html Tue Jun 6 01:23:01 2006
@@ -470,9 +470,15 @@
<tr>
<td vAlign=top>token</td>
<td vAlign=top>User defined String.</td>
- <td vAlign=top>User defined search String</td>
+ <td vAlign=top>User defined search String.</td>
<td vAlign=top align="center">Yes</td>
</tr>
+ <tr>
+ <td vAlign=top>propertiesfile</td>
+ <td vAlign=top>Not applicable.</td>
+ <td vAlign=top>Properties file to take tokens from.</td>
+ <td vAlign=top align="center">No</td>
+ </tr>
</table>
<p>
@@ -501,6 +507,18 @@
</replacetokens>
</filterchain>
</loadfile>
+</pre></blockquote>
+
+This will treat each properties file entry in sample.properties as a token/key pair :
+<blockquote><pre>
+<loadfile srcfile="${src.file}" property="${src.file.replaced}">
+ <filterchain>
+ <filterreader classname="org.apache.tools.ant.filters.ReplaceTokens">
+ <param type="propertiesfile" value="sample.properties"/>
+ </filterreader>
+ </filterchain>
+</loadfile>
+</filterchain>
</pre></blockquote>
<h3><a name="stripjavacomments">StripJavaComments</a></h3>
Modified: ant/core/trunk/src/etc/testcases/filters/build.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/filters/build.xml?rev=412040&r1=412039&r2=412040&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/filters/build.xml (original)
+++ ant/core/trunk/src/etc/testcases/filters/build.xml Tue Jun 6 01:23:01 2006
@@ -79,6 +79,17 @@
</copy>
</target>
+ <target name="testReplaceTokensPropertyFile" depends="init">
+ <copy tofile="result/replacetokensPropertyFile.test">
+ <fileset dir="input" includes="replacetokens.test" />
+ <filterchain>
+ <filterreader classname="org.apache.tools.ant.filters.ReplaceTokens">
+ <param type="propertiesfile" value="${basedir}/input/sample.properties"/>
+ </filterreader>
+ </filterchain>
+ </copy>
+ </target>
+
<target name="testNoAddNewLine" depends="init">
<concat destfile="result/nonl">This has no new lines</concat>
<copy file="result/nonl" tofile="result/nonl-copyfilter">
Added: ant/core/trunk/src/etc/testcases/filters/input/sample.properties
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/filters/input/sample.properties?rev=412040&view=auto
==============================================================================
--- ant/core/trunk/src/etc/testcases/filters/input/sample.properties (added)
+++ ant/core/trunk/src/etc/testcases/filters/input/sample.properties Tue Jun 6 01:23:01 2006
@@ -0,0 +1 @@
+foo=
Modified: ant/core/trunk/src/main/org/apache/tools/ant/filters/ReplaceTokens.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/filters/ReplaceTokens.java?rev=412040&r1=412039&r2=412040&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/filters/ReplaceTokens.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/filters/ReplaceTokens.java Tue Jun 6 01:23:01 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2005 The Apache Software Foundation
+ * Copyright 2002-2006 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.
@@ -16,9 +16,12 @@
*/
package org.apache.tools.ant.filters;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.Reader;
+import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Properties;
import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.BuildException;
@@ -219,6 +222,21 @@
}
/**
+ * Returns properties from a specified properties file.
+ *
+ * @param fileName The file to load properties from.
+ */
+ private Properties getPropertiesFromFile (String fileName) {
+ Properties props = new Properties();
+ try {
+ props.load(new FileInputStream(fileName));
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
+ return props;
+ }
+
+ /**
* Sets the map of tokens to replace.
*
* @param hash A map (String->String) of token keys to replacement
@@ -286,6 +304,13 @@
final String name = params[i].getName();
final String value = params[i].getValue();
hash.put(name, value);
+ } else if ("propertiesfile".equals(type)) {
+ Properties props = getPropertiesFromFile(params[i].getValue());
+ for (Enumeration e = props.keys(); e.hasMoreElements();) {
+ String key = (String) e.nextElement();
+ String value = props.getProperty(key);
+ hash.put(key, value);
+ }
}
}
}
Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/filters/ReplaceTokensTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/testcases/org/apache/tools/ant/filters/ReplaceTokensTest.java?rev=412040&r1=412039&r2=412040&view=diff
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/filters/ReplaceTokensTest.java (original)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/filters/ReplaceTokensTest.java Tue Jun 6 01:23:01 2006
@@ -26,7 +26,7 @@
/**
*/
public class ReplaceTokensTest extends BuildFileTest {
-
+
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
public ReplaceTokensTest(String name) {
@@ -45,6 +45,13 @@
executeTarget("testReplaceTokens");
File expected = FILE_UTILS.resolveFile(getProject().getBaseDir(),"expected/replacetokens.test");
File result = FILE_UTILS.resolveFile(getProject().getBaseDir(),"result/replacetokens.test");
+ assertTrue(FILE_UTILS.contentEquals(expected, result));
+ }
+
+ public void testReplaceTokensPropertyFile() throws IOException {
+ executeTarget("testReplaceTokensPropertyFile");
+ File expected = FILE_UTILS.resolveFile(getProjectDir(), "expected/replacetokens.test");
+ File result = FILE_UTILS.resolveFile(getProjectDir(), "result/replacetokensPropertyFile.test");
assertTrue(FILE_UTILS.contentEquals(expected, result));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org