ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r724610 - /ant/core/trunk/src/main/org/apache/tools/ant/filters/ReplaceTokens.java
Date Tue, 09 Dec 2008 05:19:00 GMT
Author: bodewig
Date: Mon Dec  8 21:18:59 2008
New Revision: 724610

URL: http://svn.apache.org/viewvc?rev=724610&view=rev
Log:
allow tokens in replacetokens filter to be read from a resource.  PR 42702

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/filters/ReplaceTokens.java

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=724610&r1=724609&r2=724610&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 Mon Dec  8 21:18:59
2008
@@ -17,7 +17,8 @@
  */
 package org.apache.tools.ant.filters;
 
-import java.io.FileInputStream;
+import java.io.File;
+import java.io.InputStream;
 import java.io.IOException;
 import java.io.Reader;
 import java.util.Enumeration;
@@ -25,6 +26,8 @@
 import java.util.Properties;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.types.Parameter;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.resources.FileResource;
 import org.apache.tools.ant.util.FileUtils;
 
 /**
@@ -214,6 +217,16 @@
     }
 
     /**
+     * A resource containing properties, each of which is interpreted
+     * as a token/value pair.
+     *
+     * @since Ant 1.8.0
+     */
+    public void setPropertiesResource(Resource r) {
+        makeTokensFromProperties(r);
+    }
+
+    /**
      * Adds a token element to the map of tokens to replace.
      *
      * @param token The token to add to the map of replacements.
@@ -228,11 +241,11 @@
      *
      * @param fileName The file to load properties from.
      */
-    private Properties getPropertiesFromFile (String fileName) {
-        FileInputStream in = null;
+    private Properties getProperties(Resource r) {
+        InputStream in = null;
         Properties props = new Properties();
         try {
-            in = new FileInputStream(fileName);
+            in = r.getInputStream();
             props.load(in);
         } catch (IOException ioe) {
             ioe.printStackTrace();
@@ -312,18 +325,23 @@
                         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);
-                        }
+                        makeTokensFromProperties(
+                            new FileResource(new File(params[i].getValue())));
                     }
                 }
             }
         }
     }
 
+    private void makeTokensFromProperties(Resource r) {
+        Properties props = getProperties(r);
+        for (Enumeration e = props.keys(); e.hasMoreElements();) {
+            String key = (String) e.nextElement();
+            String value = props.getProperty(key);
+            hash.put(key, value);
+        }
+    }
+
     /**
      * Holds a token
      */



Mime
View raw message