ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/filters ConcatFilterTest.java
Date Fri, 19 Sep 2003 09:24:13 GMT
jhm         2003/09/19 02:24:13

  Modified:    docs/manual/CoreTypes filterchain.html
               src/etc/testcases/filters concat.xml
               src/main/org/apache/tools/ant/filters ConcatFilter.java
               src/testcases/org/apache/tools/ant/filters
                        ConcatFilterTest.java
  Log:
  ConcatFilter: rename attributes after->append and before->prepend; added documentation.
  
  Revision  Changes    Path
  1.13      +45 -1     ant/docs/manual/CoreTypes/filterchain.html
  
  Index: filterchain.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTypes/filterchain.html,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- filterchain.html	23 Jul 2003 11:32:12 -0000	1.12
  +++ filterchain.html	19 Sep 2003 09:24:13 -0000	1.13
  @@ -103,6 +103,7 @@
   <a href="#tabstospaces">TabsToSpaces</a><BR>
   <a href="#tailfilter">TailFilter</a><BR>
   <a href="#deletecharacters">DeleteCharacters</a><BR>
  +<a href="#concatfilter">ConcatFilter</a><BR>
   <a href="#tokenfilter">TokenFilter</a><BR>
   
   <H3><a name="filterreader">FilterReader</a></H3>
  @@ -818,6 +819,49 @@
   &lt;deletecharacters chars="\t\r"/&gt;
   </PRE></BLOCKQUOTE>
   
  +<H3><a name="concatfilter">ConcatFilter</a></H3>
  +  <p>This filter prepends or appends the content file to the filtered files.</p>
  +  <p><em>since Ant 1.6</em></p>
  +<TABLE cellSpacing=0 cellPadding=2 border=1>
  +  <TR>
  +    <TD vAlign=top><B>Parameter Name</B></TD>
  +    <TD vAlign=top><B>Parameter Value</B></TD>
  +    <TD vAlign=top align="center"><B>Required</B></TD>
  +  </TR>
  +  <TR>
  +    <TD vAlign=top>prepend</TD>
  +    <TD vAlign=top>
  +      The name of the file which content should be prepended to the file.
  +    </TD>
  +    <TD vAlign=top align="center">No</TD>
  +  </TR>
  +  <TR>
  +    <TD vAlign=top>append</TD>
  +    <TD vAlign=top>
  +      The name of the file which content should be appended to the file.
  +    </TD>
  +    <TD vAlign=top align="center">No</TD>
  +  </TR>
  +</TABLE>
  +<P>
  +
  +<H4>Examples:</H4>
  +
  +Do nothing:
  +<BLOCKQUOTE><PRE>
  +&lt;filterchain&gt;
  +    &lt;concatfilter/&gt;
  +&lt;/filterchain&gt;
  +</PRE></BLOCKQUOTE>
  +
  +Adds a license text before each java source:
  +<BLOCKQUOTE><PRE>
  +&lt;filterchain&gt;
  +    &lt;concatfilter prepend="apache-license-java.txt"/&gt;
  +&lt;/filterchain&gt;
  +</PRE></BLOCKQUOTE>
  +
  +
   
   <H3><a name="tokenfilter">TokenFilter</a></H3>
   This filter tokenizes the inputstream into strings and passes these
  @@ -1293,4 +1337,4 @@
   <HR>
   
   <P align=center>Copyright &copy; 2002-2003 Apache Software Foundation. All rights
  -Reserved.</P></BODY></HTML>
  +Reserved.</P></BODY></HTML>
  \ No newline at end of file
  
  
  
  1.2       +21 -21    ant/src/etc/testcases/filters/concat.xml
  
  Index: concat.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/filters/concat.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- concat.xml	18 Sep 2003 15:39:26 -0000	1.1
  +++ concat.xml	19 Sep 2003 09:24:13 -0000	1.2
  @@ -3,8 +3,8 @@
   
     <target name="init">
       <mkdir dir="result" />
  -    <echo file="result/before.txt" message="this-should-be-the-first-line${line.separator}"/>
  -    <echo file="result/after.txt" message="this-should-be-the-last-line${line.separator}"/>
  +    <echo file="result/prepend.txt" message="this-should-be-the-first-line${line.separator}"/>
  +    <echo file="result/append.txt" message="this-should-be-the-last-line${line.separator}"/>
       <copy file="input/head-tail.test" tofile="input/concatfilter.test"/>
       <fixcrlf srcDir="input" includes="concatfilter.test"/>
     </target>
  @@ -26,35 +26,35 @@
       </copy>
     </target>
   
  -  <target name="testFilterReaderBefore" depends="init">
  +  <target name="testFilterReaderPrepend" depends="init">
       <copy file="input/concatfilter.test"
  -          tofile="result/concat.filterReaderBefore.test">
  +          tofile="result/concat.filterReaderPrepend.test">
         <filterchain>
           <filterreader classname="org.apache.tools.ant.filters.ConcatFilter">
  -          <param name="before" value="result/before.txt"/>
  +          <param name="prepend" value="result/prepend.txt"/>
           </filterreader>
         </filterchain>
       </copy>
     </target>
   
  -  <target name="testFilterReaderAfter" depends="init">
  +  <target name="testFilterReaderAppend" depends="init">
       <copy file="input/concatfilter.test"
  -          tofile="result/concat.filterReaderAfter.test">
  +          tofile="result/concat.filterReaderAppend.test">
         <filterchain>
           <filterreader classname="org.apache.tools.ant.filters.ConcatFilter">
  -          <param name="after" value="result/after.txt"/>
  +          <param name="append" value="result/append.txt"/>
           </filterreader>
         </filterchain>
       </copy>
     </target>
   
  -  <target name="testFilterReaderBeforeAfter" depends="init">
  +  <target name="testFilterReaderPrependAppend" depends="init">
       <copy file="input/concatfilter.test"
  -          tofile="result/concat.filterReaderBeforeAfter.test">
  +          tofile="result/concat.filterReaderPrependAppend.test">
         <filterchain>
           <filterreader classname="org.apache.tools.ant.filters.ConcatFilter">
  -          <param name="before" value="result/before.txt"/>
  -          <param name="after"  value="result/after.txt"/>
  +          <param name="prepend" value="result/prepend.txt"/>
  +          <param name="append"  value="result/append.txt"/>
           </filterreader>
         </filterchain>
       </copy>
  @@ -70,32 +70,32 @@
       </copy>
     </target>
   
  -  <target name="testConcatFilterBefore" depends="init">
  +  <target name="testConcatFilterPrepend" depends="init">
       <typedef name="concatfilter" classname="org.apache.tools.ant.filters.ConcatFilter"/>
       <copy file="input/concatfilter.test"
  -          tofile="result/concat.concatfilterBefore.test">
  +          tofile="result/concat.concatfilterPrepend.test">
         <filterchain>
  -        <concatfilter before="result/before.txt"/>
  +        <concatfilter prepend="result/prepend.txt"/>
         </filterchain>
       </copy>
     </target>
   
  -  <target name="testConcatFilterAfter" depends="init">
  +  <target name="testConcatFilterAppend" depends="init">
       <typedef name="concatfilter" classname="org.apache.tools.ant.filters.ConcatFilter"/>
       <copy file="input/concatfilter.test"
  -          tofile="result/concat.concatfilterAfter.test">
  +          tofile="result/concat.concatfilterAppend.test">
         <filterchain>
  -        <concatfilter after="result/after.txt"/>
  +        <concatfilter append="result/append.txt"/>
         </filterchain>
       </copy>
     </target>
   
  -  <target name="testConcatFilterBeforeAfter" depends="init">
  +  <target name="testConcatFilterPrependAppend" depends="init">
       <typedef name="concatfilter" classname="org.apache.tools.ant.filters.ConcatFilter"/>
       <copy file="input/concatfilter.test"
  -          tofile="result/concat.concatfilterBeforeAfter.test">
  +          tofile="result/concat.concatfilterPrependAppend.test">
         <filterchain>
  -        <concatfilter before="result/before.txt" after="result/after.txt"/>
  +        <concatfilter prepend="result/prepend.txt" append="result/append.txt"/>
         </filterchain>
       </copy>
     </target>
  
  
  
  1.2       +42 -42    ant/src/main/org/apache/tools/ant/filters/ConcatFilter.java
  
  Index: ConcatFilter.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/filters/ConcatFilter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConcatFilter.java	18 Sep 2003 15:39:26 -0000	1.1
  +++ ConcatFilter.java	19 Sep 2003 09:24:13 -0000	1.2
  @@ -67,7 +67,7 @@
    * <copy todir="build">
    *     <fileset dir="src" includes="*.java"/>
    *     <filterchain>
  - *         <concatfilter before="apache-license-java.txt"/>
  + *         <concatfilter prepend="apache-license-java.txt"/>
    *     </filterchain>
    * </copy>
    * </pre>
  @@ -83,16 +83,16 @@
       implements ChainableReader {
   
       /** File to add before the content. */
  -    private File before;
  +    private File prepend;
   
       /** File to add after the content. */
  -    private File after;
  +    private File append;
   
  -    /** Reader for before-file. */
  -    private Reader beforeReader = new EmptyReader();
  +    /** Reader for prepend-file. */
  +    private Reader prependReader = new EmptyReader();
   
  -    /** Reader for after-file. */
  -    private Reader afterReader = new EmptyReader();
  +    /** Reader for append-file. */
  +    private Reader appendReader = new EmptyReader();
   
       /**
        * Constructor for "dummy" instances.
  @@ -134,49 +134,49 @@
   
           int ch = -1;
   
  -        // The readers return -1 if they end. So simply read the "before"
  -        // after that the "content" and at the end the "after" file.
  -        ch = beforeReader.read();
  +        // The readers return -1 if they end. So simply read the "prepend"
  +        // after that the "content" and at the end the "append" file.
  +        ch = prependReader.read();
           if (ch == -1) {
               ch = super.read();
           }
           if (ch == -1) {
  -            ch = afterReader.read();
  +            ch = appendReader.read();
           }
   
           return ch;
       }
   
       /**
  -     * Sets <i>before</i> attribute.
  -     * @param before new value
  +     * Sets <i>prepend</i> attribute.
  +     * @param prepend new value
        */
  -    public void setBefore(final File before) {
  -        this.before = before;
  +    public void setPrepend(final File prepend) {
  +        this.prepend = prepend;
       }
   
       /**
  -     * Returns <i>before</i> attribute.
  -     * @return before attribute
  +     * Returns <i>prepend</i> attribute.
  +     * @return prepend attribute
        */
  -    public File getBefore() {
  -        return before;
  +    public File getPrepend() {
  +        return prepend;
       }
   
       /**
  -     * Sets <i>after</i> attribute.
  -     * @param after new value
  +     * Sets <i>append</i> attribute.
  +     * @param append new value
        */
  -    public void setAfter(final File after) {
  -        this.after = after;
  +    public void setAppend(final File append) {
  +        this.append = append;
       }
   
       /**
  -     * Returns <i>after</i> attribute.
  -     * @return after attribute
  +     * Returns <i>append</i> attribute.
  +     * @return append attribute
        */
  -    public File getAfter() {
  -        return after;
  +    public File getAppend() {
  +        return append;
       }
   
       /**
  @@ -191,10 +191,10 @@
        */
       public Reader chain(final Reader rdr) {
           ConcatFilter newFilter = new ConcatFilter(rdr);
  -        newFilter.setBefore(getBefore());
  -        newFilter.setAfter(getAfter());
  +        newFilter.setPrepend(getPrepend());
  +        newFilter.setAppend(getAppend());
           // Usually the initialized is set to true. But here it must not.
  -        // Because the before and after readers have to be instantiated
  +        // Because the prepend and append readers have to be instantiated
           // on runtime
           //newFilter.setInitialized(true);
           return newFilter;
  @@ -210,27 +210,27 @@
           Parameter[] params = getParameters();
           if (params != null) {
               for (int i = 0; i < params.length; i++) {
  -                if ("before".equals(params[i].getName())) {
  -                    setBefore(new File(params[i].getValue()));
  +                if ("prepend".equals(params[i].getName())) {
  +                    setPrepend(new File(params[i].getValue()));
                       continue;
                   }
  -                if ("after".equals(params[i].getName())) {
  -                    setAfter(new File(params[i].getValue()));
  +                if ("append".equals(params[i].getName())) {
  +                    setAppend(new File(params[i].getValue()));
                       continue;
                   }
               }
           }
  -        if (before != null) {
  -            if (!before.isAbsolute()) {
  -                before = new File(getProject().getBaseDir(), before.getPath());
  +        if (prepend != null) {
  +            if (!prepend.isAbsolute()) {
  +                prepend = new File(getProject().getBaseDir(), prepend.getPath());
               }
  -            beforeReader = new BufferedReader(new FileReader(before));
  +            prependReader = new BufferedReader(new FileReader(prepend));
           }
  -        if (after != null) {
  -            if (!after.isAbsolute()) {
  -                after = new File(getProject().getBaseDir(), after.getPath());
  +        if (append != null) {
  +            if (!append.isAbsolute()) {
  +                append = new File(getProject().getBaseDir(), append.getPath());
               }
  -            afterReader = new BufferedReader(new FileReader(after));
  +            appendReader = new BufferedReader(new FileReader(append));
           }
      }
   
  
  
  
  1.2       +31 -31    ant/src/testcases/org/apache/tools/ant/filters/ConcatFilterTest.java
  
  Index: ConcatFilterTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/filters/ConcatFilterTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConcatFilterTest.java	18 Sep 2003 15:39:26 -0000	1.1
  +++ ConcatFilterTest.java	19 Sep 2003 09:24:13 -0000	1.2
  @@ -69,7 +69,7 @@
       private static FileUtils fu = FileUtils.newFileUtils();
       private static final String lSep = System.getProperty("line.separator");
   
  -    private static final String FILE_BEGINNING_WITH =
  +    private static final String FILE_PREPEND_WITH =
             "this-should-be-the-first-line" + lSep
           + "Line  1" + lSep
           + "Line  2" + lSep
  @@ -77,7 +77,7 @@
           + "Line  4" + lSep
       ;
   
  -    private static final String FILE_BEGINNING =
  +    private static final String FILE_PREPEND =
             "Line  1" + lSep
           + "Line  2" + lSep
           + "Line  3" + lSep
  @@ -85,7 +85,7 @@
           + "Line  5" + lSep
       ;
   
  -    private static final String FILE_ENDING_WITH =
  +    private static final String FILE_APPEND_WITH =
             "Line 57" + lSep
           + "Line 58" + lSep
           + "Line 59" + lSep
  @@ -93,7 +93,7 @@
           + "this-should-be-the-last-line" + lSep
       ;
   
  -    private static final String FILE_ENDING =
  +    private static final String FILE_APPEND =
             "Line 56" + lSep
           + "Line 57" + lSep
           + "Line 58" + lSep
  @@ -112,7 +112,7 @@
   
       public void tearDown() {
           // I dont know why - but on my machine I always get a
  -        // "Unable to delete file ...result\after.txt" (or before.txt)
  +        // "Unable to delete file ...result\append.txt" (or prepend.txt)
           // from Delete.removeDir(Delete.java:612).
           // Win2000, JDK 1.4.1_02
           // A <sleep> before <delete> doesn´t work. From 10ms to 3000ms.
  @@ -137,59 +137,59 @@
       }
   
       public void testFilterReaderBefore() throws IOException {
  -        executeTarget("testFilterReaderBefore");
  -        File resultFile = getProject().resolveFile("result/concat.filterReaderBefore.test");
  +        executeTarget("testFilterReaderPrepend");
  +        File resultFile = getProject().resolveFile("result/concat.filterReaderPrepend.test");
           String resultContent = fu.readFully(new java.io.FileReader(resultFile));
  -        assertTrue("First 5 lines differs.", resultContent.startsWith(FILE_BEGINNING_WITH));
  -        assertTrue("Last 5 lines differs.", resultContent.endsWith(FILE_ENDING));
  +        assertTrue("First 5 lines differs.", resultContent.startsWith(FILE_PREPEND_WITH));
  +        assertTrue("Last 5 lines differs.", resultContent.endsWith(FILE_APPEND));
       }
   
       public void testFilterReaderAfter() throws IOException {
  -        executeTarget("testFilterReaderAfter");
  -        File resultFile = getProject().resolveFile("result/concat.filterReaderAfter.test");
  +        executeTarget("testFilterReaderAppend");
  +        File resultFile = getProject().resolveFile("result/concat.filterReaderAppend.test");
           String resultContent = fu.readFully(new java.io.FileReader(resultFile));
  -        assertTrue("First 5 lines differs.", resultContent.startsWith(FILE_BEGINNING));
  -        assertTrue("Last 5 lines differs.", resultContent.endsWith(FILE_ENDING_WITH));
  +        assertTrue("First 5 lines differs.", resultContent.startsWith(FILE_PREPEND));
  +        assertTrue("Last 5 lines differs.", resultContent.endsWith(FILE_APPEND_WITH));
       }
   
       public void testFilterReaderBeforeAfter() throws IOException {
  -        executeTarget("testFilterReaderBeforeAfter");
  -        File resultFile = getProject().resolveFile("result/concat.filterReaderBeforeAfter.test");
  +        executeTarget("testFilterReaderPrependAppend");
  +        File resultFile = getProject().resolveFile("result/concat.filterReaderPrependAppend.test");
           String resultContent = fu.readFully(new java.io.FileReader(resultFile));
  -        assertTrue("First 5 lines differs.", resultContent.startsWith(FILE_BEGINNING_WITH));
  -        assertTrue("Last 5 lines differs.", resultContent.endsWith(FILE_ENDING_WITH));
  +        assertTrue("First 5 lines differs.", resultContent.startsWith(FILE_PREPEND_WITH));
  +        assertTrue("Last 5 lines differs.", resultContent.endsWith(FILE_APPEND_WITH));
       }
   
       public void testConcatFilter() throws IOException {
           executeTarget("testConcatFilter");
           File resultFile = getProject().resolveFile("result/concat.concatfilter.test");
           String resultContent = fu.readFully(new java.io.FileReader(resultFile));
  -        assertTrue("First 5 lines differs.", resultContent.startsWith(FILE_BEGINNING));
  -        assertTrue("Last 5 lines differs.", resultContent.endsWith(FILE_ENDING));
  +        assertTrue("First 5 lines differs.", resultContent.startsWith(FILE_PREPEND));
  +        assertTrue("Last 5 lines differs.", resultContent.endsWith(FILE_APPEND));
       }
   
       public void testConcatFilterBefore() throws IOException {
  -        executeTarget("testConcatFilterBefore");
  -        File resultFile = getProject().resolveFile("result/concat.concatfilterBefore.test");
  +        executeTarget("testConcatFilterPrepend");
  +        File resultFile = getProject().resolveFile("result/concat.concatfilterPrepend.test");
           String resultContent = fu.readFully(new java.io.FileReader(resultFile));
  -        assertTrue("First 5 lines differs.", resultContent.startsWith(FILE_BEGINNING_WITH));
  -        assertTrue("Last 5 lines differs.", resultContent.endsWith(FILE_ENDING));
  +        assertTrue("First 5 lines differs.", resultContent.startsWith(FILE_PREPEND_WITH));
  +        assertTrue("Last 5 lines differs.", resultContent.endsWith(FILE_APPEND));
       }
   
       public void testConcatFilterAfter() throws IOException {
  -        executeTarget("testConcatFilterAfter");
  -        File resultFile = getProject().resolveFile("result/concat.concatfilterAfter.test");
  +        executeTarget("testConcatFilterAppend");
  +        File resultFile = getProject().resolveFile("result/concat.concatfilterAppend.test");
           String resultContent = fu.readFully(new java.io.FileReader(resultFile));
  -        assertTrue("First 5 lines differs.", resultContent.startsWith(FILE_BEGINNING));
  -        assertTrue("Last 5 lines differs.", resultContent.endsWith(FILE_ENDING_WITH));
  +        assertTrue("First 5 lines differs.", resultContent.startsWith(FILE_PREPEND));
  +        assertTrue("Last 5 lines differs.", resultContent.endsWith(FILE_APPEND_WITH));
       }
   
       public void testConcatFilterBeforeAfter() throws IOException {
  -        executeTarget("testConcatFilterBeforeAfter");
  -        File resultFile = getProject().resolveFile("result/concat.concatfilterBeforeAfter.test");
  +        executeTarget("testConcatFilterPrependAppend");
  +        File resultFile = getProject().resolveFile("result/concat.concatfilterPrependAppend.test");
           String resultContent = fu.readFully(new java.io.FileReader(resultFile));
  -        assertTrue("First 5 lines differs.", resultContent.startsWith(FILE_BEGINNING_WITH));
  -        assertTrue("Last 5 lines differs.", resultContent.endsWith(FILE_ENDING_WITH));
  +        assertTrue("First 5 lines differs.", resultContent.startsWith(FILE_PREPEND_WITH));
  +        assertTrue("Last 5 lines differs.", resultContent.endsWith(FILE_APPEND_WITH));
       }
   
   }
  
  
  

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


Mime
View raw message