diff --git a/src/main/org/apache/tools/ant/taskdefs/Filter.java b/src/main/org/apache/tools/ant/taskdefs/Filter.java
index 5d2042ba3..9af0aa1f6 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Filter.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Filter.java
@@ -54,19 +54,27 @@
package org.apache.tools.ant.taskdefs;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.io.File;
+import java.io.FileInputStream;
+
import org.apache.tools.ant.*;
/**
- * This task set a token filter that is used by the file copy methods
- * of the project to do token substitution.
+ * This task sets a token filter that is used by the file copy methods
+ * of the project to do token substitution, or sets mutiple tokens by
+ * reading these from a file.
*
* @author Stefano Mazzocchi stefano@apache.org
+ * @author Gero Vermaas gero@xs4all.nl
*/
public class Filter extends Task {
private String token;
private String value;
-
+ private File filtersFile;
+
public void setToken(String token) {
this.token = token;
}
@@ -75,11 +83,43 @@ public class Filter extends Task {
this.value = value;
}
+ public void setFiltersfile(File filterFile) {
+ this.filtersFile = filtersFile;
+ }
+
public void execute() throws BuildException {
- if (token == null || value == null) {
- throw new BuildException("token and value are required", location);
+ boolean isFiltersFromFile = filtersFile != null && token == null && value == null;
+ boolean isSingleFilter = filtersFile == null && token != null && value != null;
+
+ if (!isFiltersFromFile && !isSingleFilter) {
+ throw new BuildException("both token and value parameters, or only a filtersFile parameter is required", location);
+ }
+
+ if (isSingleFilter) {
+ project.addFilter(token, value);
}
+
+ if (isFiltersFromFile) {
+ readFilters();
+ }
+ }
+
+ protected void readFilters() throws BuildException {
+ log("Reading filters from " + filtersFile, Project.MSG_VERBOSE);
+ try {
+ Properties props = new Properties();
+ props.load(new FileInputStream(filtersFile));
- project.addFilter(token, value);
+ Project proj = getProject();
+
+ Enumeration enum = props.propertyNames();
+ while (enum.hasMoreElements()) {
+ String strPropName = (String)enum.nextElement();
+ String strValue = props.getProperty(strPropName);
+ proj.addFilter(strPropName, strValue);
+ }
+ } catch (Exception e) {
+ throw new BuildException("Could not read filters from file: " + filtersFile);
+ }
}
}