ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r894462 - in /ant/core/trunk: WHATSNEW docs/manual/CoreTypes/filterchain.html src/main/org/apache/tools/ant/filters/AppendToLines.java src/main/org/apache/tools/ant/types/FilterChain.java src/tests/antunit/filters/append-test.xml
Date Tue, 29 Dec 2009 18:49:53 GMT
Author: bodewig
Date: Tue Dec 29 18:49:53 2009
New Revision: 894462

URL: http://svn.apache.org/viewvc?rev=894462&view=rev
Log:
complement prefixlines with appendtolines

Added:
    ant/core/trunk/src/main/org/apache/tools/ant/filters/AppendToLines.java   (contents, props
changed)
      - copied, changed from r894428, ant/core/trunk/src/main/org/apache/tools/ant/filters/PrefixLines.java
    ant/core/trunk/src/tests/antunit/filters/append-test.xml   (with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTypes/filterchain.html
    ant/core/trunk/src/main/org/apache/tools/ant/types/FilterChain.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=894462&r1=894461&r2=894462&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Dec 29 18:49:53 2009
@@ -1038,6 +1038,8 @@
    list of resources from non-file resources and may return resources
    that are not files.
 
+ * a new filterreader appendtolines complements prefixlines.
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/docs/manual/CoreTypes/filterchain.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/filterchain.html?rev=894462&r1=894461&r2=894462&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/filterchain.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/filterchain.html Tue Dec 29 18:49:53 2009
@@ -107,6 +107,7 @@
 A FilterChain is formed by defining zero or more of the following
 nested elements.<br>
 <a href="#filterreader">FilterReader</a><br>
+<a href="#appendtolines">AppendToLines</a><br>
 <a href="#classconstants">ClassConstants</a><br>
 <a href="#escapeunicode">EscapeUnicode</a><br>
 <a href="#expandproperties">ExpandProperties</a><br>
@@ -478,6 +479,39 @@
 &lt;prefixlines prefix=&quot;Foo&quot;/&gt;
 </pre></blockquote>
 
+<h3><a name="appendtolines">AppendToLines</a></h3>
+
+Attaches an appendix to every line.
+
+<p><em>since Ant 1.8.0</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>append</td>
+    <td vAlign=top align="center">Appendix to be attached to lines.</td>
+    <td vAlign=top align="center">Yes</td>
+  </tr>
+</table>
+<p>
+<h4>Example:</h4>
+
+This will attach the appendix <code>Foo</code> to all lines.
+<blockquote><pre>
+&lt;filterreader classname=&quot;org.apache.tools.ant.filters.AppendToLines&quot;&gt;
+  &lt;param name=&quot;append&quot; value=&quot;Foo&quot;/&gt;
+&lt;/filterreader&gt;
+</pre></blockquote>
+
+Convenience method:
+<blockquote><pre>
+&lt;appendtolines append=&quot;Foo&quot;/&gt;
+</pre></blockquote>
+
 <h3><a name="replacetokens">ReplaceTokens</a></h3>
 
 This filter reader replaces all strings that are

Copied: ant/core/trunk/src/main/org/apache/tools/ant/filters/AppendToLines.java (from r894428,
ant/core/trunk/src/main/org/apache/tools/ant/filters/PrefixLines.java)
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/filters/AppendToLines.java?p2=ant/core/trunk/src/main/org/apache/tools/ant/filters/AppendToLines.java&p1=ant/core/trunk/src/main/org/apache/tools/ant/filters/PrefixLines.java&r1=894428&r2=894462&rev=894462&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/filters/PrefixLines.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/filters/AppendToLines.java Tue Dec 29 18:49:53
2009
@@ -22,26 +22,27 @@
 import org.apache.tools.ant.types.Parameter;
 
 /**
- * Attaches a prefix to every line.
+ * Attaches a suffix to every line.
  *
  * Example:
- * <pre>&lt;prefixlines prefix=&quot;Foo&quot;/&gt;</pre>
+ * <pre>&lt;appendtolines append=&quot;Foo&quot;/&gt;</pre>
  *
  * Or:
  *
- * <pre>&lt;filterreader classname=&quot;org.apache.tools.ant.filters.PrefixLines&quot;&gt;
- *  &lt;param name=&quot;prefix&quot; value=&quot;Foo&quot;/&gt;
+ * <pre>&lt;filterreader classname=&quot;org.apache.tools.ant.filters.AppendToLines&quot;&gt;
+ *  &lt;param name=&quot;append&quot; value=&quot;Foo&quot;/&gt;
  * &lt;/filterreader&gt;</pre>
  *
+ * @since Ant 1.8.0
  */
-public final class PrefixLines
+public final class AppendToLines
     extends BaseParamFilterReader
     implements ChainableReader {
     /** Parameter name for the prefix. */
-    private static final String PREFIX_KEY = "prefix";
+    private static final String APPEND_KEY = "append";
 
-    /** The prefix to be used. */
-    private String prefix = null;
+    /** The appendix to be used. */
+    private String append = null;
 
     /** Data that must be read from, if not null. */
     private String queuedData = null;
@@ -51,7 +52,7 @@
      *
      * @see BaseFilterReader#BaseFilterReader()
      */
-    public PrefixLines() {
+    public AppendToLines() {
         super();
     }
 
@@ -61,13 +62,13 @@
      * @param in A Reader object providing the underlying stream.
      *           Must not be <code>null</code>.
      */
-    public PrefixLines(final Reader in) {
+    public AppendToLines(final Reader in) {
         super(in);
     }
 
     /**
      * Returns the next character in the filtered stream. One line is read
-     * from the original input, and the prefix added. The resulting
+     * from the original input, and the appendix added. The resulting
      * line is then used until it ends, at which point the next original line
      * is read, etc.
      *
@@ -100,8 +101,17 @@
             if (queuedData == null) {
                 ch = -1;
             } else {
-                if (prefix != null) {
-                    queuedData = prefix + queuedData;
+                if (append != null) {
+                    String lf = "";
+                    if (queuedData.endsWith("\r\n")) {
+                        lf = "\r\n";
+                    } else if (queuedData.endsWith("\n")) {
+                        lf = "\n";
+                    }
+                    queuedData =
+                        queuedData.substring(0,
+                                             queuedData.length() - lf.length())
+                        + append + lf;
                 }
                 return read();
             }
@@ -110,27 +120,27 @@
     }
 
     /**
-     * Sets the prefix to add at the start of each input line.
+     * Sets the appendix to add at the end of each input line.
      *
-     * @param prefix The prefix to add at the start of each input line.
-     *               May be <code>null</code>, in which case no prefix
+     * @param append The appendix to add at the end of each input line.
+     *               May be <code>null</code>, in which case no appendix
      *               is added.
      */
-    public void setPrefix(final String prefix) {
-        this.prefix = prefix;
+    public void setAppend(final String append) {
+        this.append = append;
     }
 
     /**
-     * Returns the prefix which will be added at the start of each input line.
+     * Returns the appendix which will be added at the end of each input line.
      *
-     * @return the prefix which will be added at the start of each input line
+     * @return the appendix which will be added at the end of each input line
      */
-    private String getPrefix() {
-        return prefix;
+    private String getAppend() {
+        return append;
     }
 
     /**
-     * Creates a new PrefixLines filter using the passed in
+     * Creates a new AppendToLines filter using the passed in
      * Reader for instantiation.
      *
      * @param rdr A Reader object providing the underlying stream.
@@ -140,21 +150,21 @@
      *         the specified reader
      */
     public Reader chain(final Reader rdr) {
-        PrefixLines newFilter = new PrefixLines(rdr);
-        newFilter.setPrefix(getPrefix());
+        AppendToLines newFilter = new AppendToLines(rdr);
+        newFilter.setAppend(getAppend());
         newFilter.setInitialized(true);
         return newFilter;
     }
 
     /**
-     * Initializes the prefix if it is available from the parameters.
+     * Initializes the appendix if it is available from the parameters.
      */
     private void initialize() {
         Parameter[] params = getParameters();
         if (params != null) {
             for (int i = 0; i < params.length; i++) {
-                if (PREFIX_KEY.equals(params[i].getName())) {
-                    prefix = params[i].getValue();
+                if (APPEND_KEY.equals(params[i].getName())) {
+                    append = params[i].getValue();
                     break;
                 }
             }

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/filters/AppendToLines.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/filters/AppendToLines.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/filters/AppendToLines.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/FilterChain.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/FilterChain.java?rev=894462&r1=894461&r2=894462&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/FilterChain.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/FilterChain.java Tue Dec 29 18:49:53
2009
@@ -23,6 +23,7 @@
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.filters.AppendToLines;
 import org.apache.tools.ant.filters.ChainableReader;
 import org.apache.tools.ant.filters.ClassConstants;
 import org.apache.tools.ant.filters.EscapeUnicode;
@@ -155,6 +156,19 @@
     }
 
     /**
+     * Add a PrefixLines filter.
+     *
+     * @param prefixLines a <code>AppendToLines</code> value
+     */
+    public void addAppendToLines(final AppendToLines appendToLines) {
+        if (isReference()) {
+            throw noChildrenAllowed();
+        }
+        setChecked(false);
+        filterReaders.addElement(appendToLines);
+    }
+
+    /**
      * Add a ReplaceTokens filter.
      *
      * @param replaceTokens a <code>ReplaceTokens</code> value

Added: ant/core/trunk/src/tests/antunit/filters/append-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/filters/append-test.xml?rev=894462&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/filters/append-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/filters/append-test.xml Tue Dec 29 18:49:53 2009
@@ -0,0 +1,42 @@
+<?xml version="1.0"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+  -->
+<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
+  <import file="../antunit-base.xml" />
+
+  <target name="setUp">
+    <mkdir dir="${input}"/>
+    <mkdir dir="${output}"/>
+  </target>
+
+  <target name="testSimple">
+    <echo file="${input}/a.txt">a
+b
+c</echo>
+    <echo file="${input}/b.txt">aFoo
+bFoo
+cFoo</echo>
+    <copy todir="${output}">
+      <fileset dir="${input}"/>
+      <filterchain>
+        <appendtolines append="Foo"/>
+      </filterchain>
+    </copy>
+    <au:assertFilesMatch expected="${input}/b.txt"
+                         actual="${output}/a.txt"/>
+  </target>
+</project>

Propchange: ant/core/trunk/src/tests/antunit/filters/append-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message