DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=8656>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=8656 Add the possibility to specify a URL in the Filter task Summary: Add the possibility to specify a URL in the Filter task Product: Ant Version: 1.4.1 Platform: Other OS/Version: Other Status: NEW Severity: Enhancement Priority: Other Component: Core tasks AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] Hi, I want to use the filter task where the properties file describing the filters can be given as an URL. For example, I would like to use the filter task like this: <filter filtersurl="http://myhost.org/deploy_env.properties"/> I've made some changes to the code which does this. I'll include the necessary patches in this enhancement request. It's up to you guys whether you find this interesting or not... Here are the patches (3): cvs diff -u Filter.java Index: Filter.java =================================================================== RCS file: /home/cvspublic/jakarta- ant/src/main/org/apache/tools/ant/taskdefs/Filter.java,v retrieving revision 1.16 diff -u -r1.16 Filter.java --- Filter.java 15 Apr 2002 15:33:08 -0000 1.16 +++ Filter.java 30 Apr 2002 13:10:23 -0000 @@ -55,6 +55,7 @@ package org.apache.tools.ant.taskdefs; import java.io.File; +import java.net.URL; import org.apache.tools.ant.Task; import org.apache.tools.ant.BuildException; @@ -79,6 +80,7 @@ private String token; private String value; private File filtersFile; + private URL filtersUrl; public void setToken(String token) { this.token = token; @@ -91,17 +93,26 @@ public void setFiltersfile(File filtersFile) { this.filtersFile = filtersFile; } + + public void setFiltersurl(URL filtersUrl) { + this.filtersUrl = filtersUrl; + } public void execute() throws BuildException { boolean isFiltersFromFile = - filtersFile != null && token == null && value == null; + filtersFile != null && filtersUrl == null + && token == null && value == null; + boolean isFiltersFromUrl = + filtersUrl != null && filtersFile == null + && token == null && value == null; boolean isSingleFilter = - filtersFile == null && token != null && value != null; + filtersFile == null && filtersUrl == null + && token != null && value != null; - if (!isFiltersFromFile && !isSingleFilter) { + if (!isFiltersFromFile && !isFiltersFromUrl && !isSingleFilter) { throw new BuildException("both token and value parameters, or " - + "only a filtersFile parameter is " - + "required", location); + + "only a filtersFile or filtersUrl " + + "parameter is required", location); } if (isSingleFilter) { @@ -109,12 +120,21 @@ } if (isFiltersFromFile) { - readFilters(); + readFiltersFromFile(); + } + + if (isFiltersFromUrl) { + readFiltersFromUrl(); } } - protected void readFilters() throws BuildException { + protected void readFiltersFromFile() throws BuildException { log("Reading filters from " + filtersFile, Project.MSG_VERBOSE); project.getGlobalFilterSet().readFiltersFromFile(filtersFile); + } + + protected void readFiltersFromUrl() throws BuildException { + log("Reading filters from " + filtersUrl, Project.MSG_VERBOSE); + project.getGlobalFilterSet().readFiltersFromUrl(filtersUrl); } } cvs diff -u FilterSet.java Index: FilterSet.java =================================================================== RCS file: /home/cvspublic/jakarta- ant/src/main/org/apache/tools/ant/types/FilterSet.java,v retrieving revision 1.13 diff -u -r1.13 FilterSet.java --- FilterSet.java 15 Apr 2002 14:56:34 -0000 1.13 +++ FilterSet.java 30 Apr 2002 13:11:13 -0000 @@ -56,8 +56,12 @@ // java io classes import java.io.File; import java.io.FileInputStream; +import java.io.InputStream; import java.io.IOException; +// java net classes +import java.net.URL; + // java util classes import java.util.Enumeration; import java.util.Hashtable; @@ -293,19 +297,10 @@ if (filtersFile.isFile()) { log("Reading filters from " + filtersFile, Project.MSG_VERBOSE); - FileInputStream in = null; + InputStream in = null; try { - Properties props = new Properties(); - in = new FileInputStream(filtersFile); - props.load(in); - - Enumeration enum = props.propertyNames(); - Vector filters = getFilters(); - while (enum.hasMoreElements()) { - String strPropName = (String) enum.nextElement(); - String strValue = props.getProperty(strPropName); - filters.addElement(new Filter(strPropName, strValue)); - } + in = new FileInputStream(filtersFile); + readFiltersFromInputStream(in); } catch (Exception e) { throw new BuildException("Could not read filters from file: " + filtersFile); @@ -322,6 +317,41 @@ + "the filtersfile attribute:" + filtersFile); } } + + public void readFiltersFromUrl(URL filtersUrl) throws BuildException { + if (isReference()) { + throw tooManyAttributes(); + } + + log("Reading filters from " + filtersUrl, Project.MSG_VERBOSE); + InputStream in = null; + try { + in = filtersUrl.openStream(); + readFiltersFromInputStream(in); + } catch (Exception e) { + throw new BuildException("Could not read filters from url: " + + filtersUrl); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException ioex) { + } + } + } + } + + private void readFiltersFromInputStream(InputStream in) throws Exception { + Properties props = new Properties(); + props.load(in); + + Enumeration enum = props.propertyNames(); + while (enum.hasMoreElements()) { + String strPropName = (String) enum.nextElement(); + String strValue = props.getProperty(strPropName); + addFilter(new Filter(strPropName, strValue)); + } + } /** * Does replacement on the given string with token matching. cvs diff -u filter.html Index: filter.html =================================================================== RCS file: /home/cvspublic/jakarta-ant/docs/manual/CoreTasks/filter.html,v retrieving revision 1.8 diff -u -r1.8 filter.html --- filter.html 12 Apr 2002 15:26:22 -0000 1.8 +++ filter.html 30 Apr 2002 13:11:57 -0000 @@ -15,7 +15,7 @@ through the Project commodity methods.</p> <p>Note 1: the token string must not contain the separators chars (@).<br> Note 2: Either token and value attributes must be provided, or only the -filtersfile attribute.</p> +filtersfile or filtersurl attribute.</p> <h3>Parameters</h3> <table border="1" cellpadding="2" cellspacing="0"> @@ -40,6 +40,11 @@ <td valign="top">The file from which the filters must be read. This file must be a formatted as a property file. </td> <td align="center" valign="top">Yes*</td> </tr> + <tr> + <td valign="top">filtersurl</td> + <td valign="top">The url from which the filters must be read. This result of this url must be a formatted as a property file. </td> + <td align="center" valign="top">Yes*</td> + </tr> </table> <p>* see notes 1 and 2 above parameters table.</p> <h3>Examples</h3> @@ -52,6 +57,9 @@ with <i>2000.</i></p> <pre> <filter filtersfile="deploy_env.properties"/></pre> will read all property entries from the <i>deploy_env.properties</i> file +and set these as filters. +<pre> <filter filtersurl="http://myhost.org/deploy_env.properties"/></pre> +will read all property entries from the given url and set these as filters. <hr> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
