ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r359262 - in /ant/core/trunk: ./ docs/manual/CoreTypes/ src/etc/testcases/types/ src/main/org/apache/tools/ant/types/ src/testcases/org/apache/tools/ant/types/
Date Tue, 27 Dec 2005 19:02:47 GMT
Author: mbenson
Date: Tue Dec 27 11:02:40 2005
New Revision: 359262

URL: http://svn.apache.org/viewcvs?rev=359262&view=rev
Log:
added the onmissingfiltersfile attribute to filterset. Bugzilla report 19845.

Added:
    ant/core/trunk/src/etc/testcases/types/filtersetd.txt   (with props)
    ant/core/trunk/src/etc/testcases/types/filtersfile1
    ant/core/trunk/src/etc/testcases/types/filtersfile2
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTypes/filterset.html
    ant/core/trunk/src/etc/testcases/types/filterset.xml
    ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java
    ant/core/trunk/src/testcases/org/apache/tools/ant/types/FilterSetTest.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewcvs/ant/core/trunk/WHATSNEW?rev=359262&r1=359261&r2=359262&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Dec 27 11:02:40 2005
@@ -337,6 +337,8 @@
 
 * new resourcesmatch condition.
 
+* added the onmissingfiltersfile attribute to filterset. Bugzilla report 19845.
+
 Changes from Ant 1.6.4 to Ant 1.6.5
 ===================================
 

Modified: ant/core/trunk/docs/manual/CoreTypes/filterset.html
URL: http://svn.apache.org/viewcvs/ant/core/trunk/docs/manual/CoreTypes/filterset.html?rev=359262&r1=359261&r2=359262&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/filterset.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/filterset.html Tue Dec 27 11:02:40 2005
@@ -62,7 +62,7 @@
   <tr>
     <td vAlign=top>filtersfile</td>
     <td vAlign=top>Specify a single filtersfile.</td>
-    <td vAlign=top><i>n/a</i></td>
+    <td vAlign=top><i>none</i></td>
     <td vAlign=top align="center">No</td>
   </tr>
   <tr>
@@ -70,6 +70,13 @@
     <td vAlign=top>Indicates whether the replacement text of tokens
       should be searched for more tokens. <b>Since Ant 1.6.3</b></td>
     <td vAlign=top><i>true</i></td>
+    <td vAlign=top align="center">No</td>
+  </tr>
+  <tr>
+    <td vAlign=top>onmissingfiltersfile</td>
+    <td vAlign=top>Indicate behavior when a nonexistent <i>filtersfile</i>
+      is specified.  One of "fail", "warn", "ignore". <b>Since Ant 1.7</b></td>
+    <td vAlign=top>"fail"</td>
     <td vAlign=top align="center">No</td>
   </tr>
 </table>

Modified: ant/core/trunk/src/etc/testcases/types/filterset.xml
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/types/filterset.xml?rev=359262&r1=359261&r2=359262&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/types/filterset.xml (original)
+++ ant/core/trunk/src/etc/testcases/types/filterset.xml Tue Dec 27 11:02:40 2005
@@ -48,10 +48,82 @@
     </filterset>
   </target>
 
+  <target name="testFiltersFileElement">
+    <copy file="filtersetd.txt" tofile="dest4.txt">
+      <filterset>
+        <filtersfile file="filtersfile1" />
+      </filterset>
+    </copy>
+    <fail>
+      <condition>
+        <not>
+          <resourcesmatch asText="true">
+            <file file="dest4.txt" />
+            <string value="FOO BAR @baz@ @blah@" />
+          </resourcesmatch>
+        </not>
+      </condition>
+    </fail>
+  </target>
+
+  <target name="testFiltersFileAttribute">
+    <copy file="filtersetd.txt" tofile="dest5.txt">
+      <filterset filtersfile="filtersfile1" />
+    </copy>
+    <fail>
+      <condition>
+        <not>
+          <resourcesmatch asText="true">
+            <file file="dest5.txt" />
+            <string value="FOO BAR @baz@ @blah@" />
+          </resourcesmatch>
+        </not>
+      </condition>
+    </fail>
+  </target>
+
+  <target name="testMultipleFiltersFiles">
+    <copy file="filtersetd.txt" tofile="dest6.txt">
+      <filterset filtersfile="filtersfile1">
+        <filtersfile file="filtersfile2" />
+      </filterset>
+    </copy>
+    <fail>
+      <condition>
+        <not>
+          <resourcesmatch asText="true">
+            <file file="dest6.txt" />
+            <string value="FOO BAR BAZ @blah@" />
+          </resourcesmatch>
+        </not>
+      </condition>
+    </fail>
+  </target>
+
+  <target name="testMissingFiltersFile">
+    <copy file="filtersetd.txt" tofile="dest7.txt">
+      <filterset filtersfile="nonexistentfiltersfile" />
+    </copy>
+  </target>
+
+  <target name="testAllowMissingFiltersFile">
+    <copy file="filtersetd.txt" tofile="dest8.txt">
+      <filterset filtersfile="nonexistentfiltersfile"
+                 onmissingfiltersfile="ignore" />
+    </copy>
+    <fail>
+      <condition>
+        <not>
+          <filesmatch file1="filtersetd.txt" file2="dest8.txt" />
+        </not>
+      </condition>
+    </fail>
+  </target>
+
   <target name="cleanup">
-    <delete file="dest1.txt" quiet="true" />
-    <delete file="dest2.txt" quiet="true" />
-    <delete file="dest3.txt" quiet="true" />
+    <delete quiet="true">
+      <fileset dir="." includes="dest?.txt" />
+    </delete>
   </target>
 
 </project>

Added: ant/core/trunk/src/etc/testcases/types/filtersetd.txt
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/types/filtersetd.txt?rev=359262&view=auto
==============================================================================
--- ant/core/trunk/src/etc/testcases/types/filtersetd.txt (added)
+++ ant/core/trunk/src/etc/testcases/types/filtersetd.txt Tue Dec 27 11:02:40 2005
@@ -0,0 +1 @@
+@foo@ @bar@ @baz@ @blah@

Propchange: ant/core/trunk/src/etc/testcases/types/filtersetd.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ant/core/trunk/src/etc/testcases/types/filtersfile1
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/types/filtersfile1?rev=359262&view=auto
==============================================================================
--- ant/core/trunk/src/etc/testcases/types/filtersfile1 (added)
+++ ant/core/trunk/src/etc/testcases/types/filtersfile1 Tue Dec 27 11:02:40 2005
@@ -0,0 +1,2 @@
+foo=FOO
+bar=BAR

Added: ant/core/trunk/src/etc/testcases/types/filtersfile2
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/types/filtersfile2?rev=359262&view=auto
==============================================================================
--- ant/core/trunk/src/etc/testcases/types/filtersfile2 (added)
+++ ant/core/trunk/src/etc/testcases/types/filtersfile2 Tue Dec 27 11:02:40 2005
@@ -0,0 +1 @@
+baz=BAZ

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java?rev=359262&r1=359261&r2=359262&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java Tue Dec 27 11:02:40
2005
@@ -118,7 +118,44 @@
          * @param file the file from which filters will be read.
          */
         public void setFile(File file) {
-           readFiltersFromFile(file);
+           filtersFiles.add(file);
+        }
+    }
+
+    /**
+     * EnumeratedAttribute to set behavior WRT missing filtersfiles:
+     * "fail" (default), "warn", "ignore".
+     * @since Ant 1.7
+     */
+    public static class OnMissing extends EnumeratedAttribute {
+        private static final String[] VALUES
+            = new String[] {"fail", "warn", "ignore"};
+
+        public static final OnMissing FAIL = new OnMissing("fail");
+        public static final OnMissing WARN = new OnMissing("warn");
+        public static final OnMissing IGNORE = new OnMissing("ignore");
+
+        private static final int FAIL_INDEX = 0;
+        private static final int WARN_INDEX = 1;
+        private static final int IGNORE_INDEX = 2;
+
+        /**
+         * Default constructor.
+         */
+        public OnMissing() {
+        }
+
+        /**
+         * Convenience constructor.
+         * @param value the value to set.
+         */
+        public OnMissing(String value) {
+            setValue(value);
+        }
+
+        //inherit doc
+        public String[] getValues() {
+            return VALUES;
         }
     }
 
@@ -138,6 +175,9 @@
 
     private boolean recurse = true;
     private Hashtable filterHash = null;
+    private Vector filtersFiles = new Vector();
+    private OnMissing onMissingFiltersFile = OnMissing.FAIL;
+    private boolean readingFiles = false;
 
     /**
      * List of ordered filters and filter files.
@@ -169,6 +209,15 @@
         if (isReference()) {
             return getRef().getFilters();
         }
+        //silly hack to avoid stack overflow...
+        if (!readingFiles) {
+            readingFiles = true;
+            for (int i = 0, sz = filtersFiles.size(); i < sz; i++) {
+                readFiltersFromFile((File) filtersFiles.get(i));
+            }
+            filtersFiles.clear();
+            readingFiles = false;
+        }
         return filters;
     }
 
@@ -202,13 +251,12 @@
      *
      * @param filtersFile sets the filter file from which to read filters
      *        for this filter set.
-     * @exception BuildException if there is a problem reading the filters.
      */
     public void setFiltersfile(File filtersFile) throws BuildException {
         if (isReference()) {
             throw tooManyAttributes();
         }
-        readFiltersFromFile(filtersFile);
+        filtersFiles.add(filtersFile);
     }
 
     /**
@@ -292,7 +340,7 @@
             throw tooManyAttributes();
         }
         if (!filtersFile.exists()) {
-            throw new BuildException("Could not read filters from file "
+           handleMissingFile("Could not read filters from file "
                                      + filtersFile + " as it doesn't exist.");
         }
         if (filtersFile.isFile()) {
@@ -312,13 +360,14 @@
               }
            } catch (Exception ex) {
               throw new BuildException("Could not read filters from file: "
-                + filtersFile);
+                  + filtersFile);
            } finally {
               FileUtils.close(in);
            }
         } else {
-           throw new BuildException("Must specify a file not a directory in "
-            + "the filtersfile attribute:" + filtersFile);
+           handleMissingFile(
+               "Must specify a file rather than a directory in "
+               + "the filtersfile attribute:" + filtersFile);
         }
         filterHash = null;
     }
@@ -339,6 +388,104 @@
     }
 
     /**
+     * Add a new filter.
+     *
+     * @param filter the filter to be added.
+     */
+    public synchronized void addFilter(Filter filter) {
+        if (isReference()) {
+            throw noChildrenAllowed();
+        }
+        filters.addElement(filter);
+        filterHash = null;
+    }
+
+    /**
+     * Create a new FiltersFile.
+     *
+     * @return The filtersfile that was created.
+     */
+    public FiltersFile createFiltersfile() {
+        if (isReference()) {
+            throw noChildrenAllowed();
+        }
+        return new FiltersFile();
+    }
+
+    /**
+     * Add a new filter made from the given token and value.
+     *
+     * @param token The token for the new filter.
+     * @param value The value for the new filter.
+     */
+    public synchronized void addFilter(String token, String value) {
+        if (isReference()) {
+            throw noChildrenAllowed();
+        }
+        addFilter(new Filter(token, value));
+    }
+
+    /**
+     * Add a Filterset to this filter set.
+     *
+     * @param filterSet the filterset to be added to this filterset
+     */
+    public synchronized void addConfiguredFilterSet(FilterSet filterSet) {
+        if (isReference()) {
+            throw noChildrenAllowed();
+        }
+        for (Enumeration e = filterSet.getFilters().elements(); e.hasMoreElements();) {
+            addFilter((Filter) e.nextElement());
+        }
+    }
+
+    /**
+    * Test to see if this filter set has filters.
+    *
+    * @return Return true if there are filters in this set.
+    */
+    public synchronized boolean hasFilters() {
+        return getFilters().size() > 0;
+    }
+
+    /**
+     * Clone the filterset.
+     *
+     * @return a deep clone of this filterset.
+     *
+     * @throws BuildException if the clone cannot be performed.
+     */
+    public synchronized Object clone() throws BuildException {
+        if (isReference()) {
+            return ((FilterSet) getRef()).clone();
+        }
+        try {
+            FilterSet fs = (FilterSet) super.clone();
+            fs.filters = (Vector) getFilters().clone();
+            fs.setProject(getProject());
+            return fs;
+        } catch (CloneNotSupportedException e) {
+            throw new BuildException(e);
+        }
+    }
+
+    /**
+     * Set the behavior WRT missing filtersfiles.
+     * @param onMissingFiltersFile the OnMissing describing the behavior.
+     */
+    public void setOnMissingFiltersFile(OnMissing onMissingFiltersFile) {
+        this.onMissingFiltersFile = onMissingFiltersFile;
+    }
+
+    /**
+     * Get the onMissingFiltersFile setting.
+     * @return the OnMissing instance.
+     */
+    public OnMissing getOnMissingFiltersFile() {
+        return onMissingFiltersFile;
+    }
+
+    /**
      * Does replacement on the given string with token matching.
      * This uses the defined begintoken and endtoken values which default
      * to @ for both.
@@ -438,87 +585,21 @@
         return value;
     }
 
-    /**
-     * Add a new filter.
-     *
-     * @param filter the filter to be added.
-     */
-    public synchronized void addFilter(Filter filter) {
-        if (isReference()) {
-            throw noChildrenAllowed();
-        }
-        filters.addElement(filter);
-        filterHash = null;
-    }
-
-    /**
-     * Create a new FiltersFile.
-     *
-     * @return The filtersfile that was created.
-     */
-    public FiltersFile createFiltersfile() {
-        if (isReference()) {
-            throw noChildrenAllowed();
-        }
-        return new FiltersFile();
-    }
-
-    /**
-     * Add a new filter made from the given token and value.
-     *
-     * @param token The token for the new filter.
-     * @param value The value for the new filter.
-     */
-    public synchronized void addFilter(String token, String value) {
-        if (isReference()) {
-            throw noChildrenAllowed();
+    private void addFiltersFile(File f) {
+        if (!filtersFiles.contains(f)) {
+            filtersFiles.add(f);
         }
-        addFilter(new Filter(token, value));
     }
 
-    /**
-     * Add a Filterset to this filter set.
-     *
-     * @param filterSet the filterset to be added to this filterset
-     */
-    public synchronized void addConfiguredFilterSet(FilterSet filterSet) {
-        if (isReference()) {
-            throw noChildrenAllowed();
-        }
-        for (Enumeration e = filterSet.getFilters().elements(); e.hasMoreElements();) {
-            addFilter((Filter) e.nextElement());
+    private void handleMissingFile(String message) {
+        switch (onMissingFiltersFile.getIndex()) {
+        case OnMissing.IGNORE_INDEX:
+            return;
+        case OnMissing.FAIL_INDEX:
+            throw new BuildException(message);
+        case OnMissing.WARN_INDEX:
+            log(message, Project.MSG_WARN);
         }
     }
 
-    /**
-    * Test to see if this filter set has filters.
-    *
-    * @return Return true if there are filters in this set.
-    */
-    public synchronized boolean hasFilters() {
-        return getFilters().size() > 0;
-    }
-
-    /**
-     * Clone the filterset.
-     *
-     * @return a deep clone of this filterset.
-     *
-     * @throws BuildException if the clone cannot be performed.
-     */
-    public synchronized Object clone() throws BuildException {
-        if (isReference()) {
-            return ((FilterSet) getRef()).clone();
-        } else {
-            try {
-                FilterSet fs = (FilterSet) super.clone();
-                fs.filters = (Vector) getFilters().clone();
-                fs.setProject(getProject());
-                return fs;
-            } catch (CloneNotSupportedException e) {
-                throw new BuildException(e);
-            }
-        }
-    }
 }
-

Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/types/FilterSetTest.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/types/FilterSetTest.java?rev=359262&r1=359261&r2=359262&view=diff
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/types/FilterSetTest.java (original)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/types/FilterSetTest.java Tue Dec 27
11:02:40 2005
@@ -141,6 +141,27 @@
         assertEquals("value1", filters.get("token1"));
     }
 
+    public void testFiltersFileElement() {
+        executeTarget("testFiltersFileElement");
+    }
+
+    public void testFiltersFileAttribute() {
+        executeTarget("testFiltersFileAttribute");
+    }
+
+    public void testMultipleFiltersFiles() {
+        executeTarget("testMultipleFiltersFiles");
+    }
+
+    public void testMissingFiltersFile() {
+        expectBuildException("testMissingFiltersFile",
+            "should fail due to missing filtersfile");
+    }
+
+    public void testAllowMissingFiltersFile() {
+        executeTarget("testAllowMissingFiltersFile");
+    }
+
     private boolean compareFiles(String name1, String name2) {
         File file1 = new File(System.getProperty("root"), name1);
         File file2 = new File(System.getProperty("root"), name2);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message