You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by jh...@apache.org on 2017/02/09 08:31:40 UTC

[1/4] ant git commit: [AA] Bugzilla Bug 60628 - Ant Get Task To Accept Arbitrary Header

Repository: ant
Updated Branches:
  refs/heads/master 79a34b8d2 -> 1ccf1989a


[AA] Bugzilla Bug 60628 - Ant Get Task To Accept Arbitrary Header


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/b83bdceb
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/b83bdceb
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/b83bdceb

Branch: refs/heads/master
Commit: b83bdcebf0395250b3ae5e7e4af94ff1400493f0
Parents: a928452
Author: Arcadius Ahouansou <Ar...@aexp.com>
Authored: Mon Jan 23 22:46:06 2017 +0000
Committer: Arcadius Ahouansou <Ar...@aexp.com>
Committed: Mon Jan 23 22:46:06 2017 +0000

----------------------------------------------------------------------
 manual/Tasks/get.html                           | 34 ++++++++++++++++
 src/etc/testcases/taskdefs/get.xml              | 28 +++++++++++++
 src/main/org/apache/tools/ant/taskdefs/Get.java | 43 ++++++++++++++++++++
 .../apache/tools/ant/taskdefs/email/Header.java |  4 +-
 .../org/apache/tools/ant/taskdefs/GetTest.java  | 36 ++++++++++++++++
 5 files changed, 144 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/b83bdceb/manual/Tasks/get.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/get.html b/manual/Tasks/get.html
index a2c9b7e..a6d89e9 100644
--- a/manual/Tasks/get.html
+++ b/manual/Tasks/get.html
@@ -170,6 +170,29 @@ plain text' authentication is used. This is only secure over an HTTPS link.
   name will be skipped.  If the returned name is a relative path, it
   will be considered relative to the <em>dest</em> attribute.</p>
 
+<h4>header</h4>
+<p>Any arbitrary number of HTTP headers can be added to a request.<br/>
+  The attributes of a nested <pre>&lt;header/&gt; </pre> node are as follow:
+<p></p>
+
+<table width="60%" border="1" cellpadding="2" cellspacing="0">
+  <tr>
+    <td valign="top"><b>Attribute</b></td>
+    <td valign="top"><b>Description</b></td>
+    <td align="center" valign="top"><b>Required</b></td>
+  </tr>
+  <tr>
+    <td valign="top">name</td>
+    <td valign="top">The name or key of this header.</td>
+    <td align="center" valign="top">Yes</td>
+  </tr>
+  <tr>
+    <td valign="top">value</td>
+    <td valign="top">The value to assign to the.</td>
+    <td align="center" valign="top">Yes</td>
+  </tr>
+</table>
+
 <h3>Examples</h3>
 <pre>  &lt;get src=&quot;http://ant.apache.org/&quot; dest=&quot;help/index.html&quot;/&gt;</pre>
 <p>Gets the index page of http://ant.apache.org/, and stores it in the file <code>help/index.html</code>.</p>
@@ -234,6 +257,17 @@ the <a href="input.html">input task</a> to query for a password.</p>
   &lt;url url=&quot;http://ant.apache.org/faq.html&quot;/&gt;
 &lt;/get&gt;
 </pre>
+
+<p>With custom HTTP headers</p>
+<pre>
+&lt;get src=&quot;http://ant.apache.org/index.html&quot; dest=&quot;downloads&quot;&gt;
+  &lt;header name=&quot;header1&quot; value==&quot;headerValue1&quot; /&gt;
+  &lt;header name=&quot;header2&quot; value==&quot;headerValue2&quot; /&gt;
+  &lt;header name=&quot;header3&quot; value==&quot;headerValue3&quot; /&gt;
+
+&lt;/get&gt;
+</pre>
+
 <p>Gets the index and FAQ pages of http://ant.apache.org/, and stores
   them in the directory <code>downloads</code> which will be created if
   necessary.</p>

http://git-wip-us.apache.org/repos/asf/ant/blob/b83bdceb/src/etc/testcases/taskdefs/get.xml
----------------------------------------------------------------------
diff --git a/src/etc/testcases/taskdefs/get.xml b/src/etc/testcases/taskdefs/get.xml
index b74e92a..569d833 100644
--- a/src/etc/testcases/taskdefs/get.xml
+++ b/src/etc/testcases/taskdefs/get.xml
@@ -98,6 +98,34 @@
     </fail>
   </target>
 
+  <target name="testTwoHeaders">
+    <get src="http://www.apache.org/" dest="get.tmp">
+      <header name="header1" value="header1Value"/>
+      <header name="header2" value="header2Value"/>
+    </get>
+  </target>
+
+  <target name="testEmptyHeaders">
+    <get src="http://www.apache.org/" dest="get.tmp">
+      <header name="" value="headerValue"/>
+      <header name="header2" value=""/>
+    </get>
+  </target>
+
+  <target name="testDuplicateHeaderNames">
+    <get src="http://www.apache.org/" dest="get.tmp">
+      <header name="header1" value="headerValue1"/>
+      <header name="header1" value="headerValue2"/>
+      <header name="header1" value="headerValue3"/>
+    </get>
+  </target>
+
+  <target name="testHeaderSpacesTrimmed">
+    <get src="http://www.apache.org/" dest="get.tmp">
+      <header name="  header1     " value="  headerValue1  "/>
+    </get>
+  </target>
+
   <target name="cleanup">
     <delete>
       <fileset dir="${basedir}" includes="get.tmp" />

http://git-wip-us.apache.org/repos/asf/ant/blob/b83bdceb/src/main/org/apache/tools/ant/taskdefs/Get.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Get.java b/src/main/org/apache/tools/ant/taskdefs/Get.java
index 83f3b6b..2200bd8 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Get.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Get.java
@@ -36,6 +36,7 @@ import org.apache.tools.ant.MagicNames;
 import org.apache.tools.ant.Main;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.email.Header;
 import org.apache.tools.ant.types.Mapper;
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.ResourceCollection;
@@ -44,6 +45,8 @@ import org.apache.tools.ant.types.resources.URLProvider;
 import org.apache.tools.ant.types.resources.URLResource;
 import org.apache.tools.ant.util.FileNameMapper;
 import org.apache.tools.ant.util.FileUtils;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 /**
  * Gets a particular file from a URL source.
@@ -90,6 +93,9 @@ public class Get extends Task {
                            DEFAULT_AGENT_PREFIX + "/"
                            + Main.getShortAntVersion());
 
+    // Store headers as key/value pair without duplicate in keyz
+    private Map<String, String> headers = new LinkedHashMap<String, String>();
+
     /**
      * Does the work.
      *
@@ -483,6 +489,35 @@ public class Get extends Task {
     }
 
     /**
+     * Add a nested header
+     * @param header to be added
+     *
+     */
+    public void addConfiguredHeader(Header header) {
+        if (header != null) {
+            String key = trimToNull(header.getName());
+            String value = trimToNull(header.getValue());
+            if (key != null && value != null) {
+                this.headers.put(key, value);
+            }
+        }
+    }
+
+    private String trimToNull(String inputString) {
+
+        if (inputString == null) {
+            return null;
+        }
+
+        inputString = inputString.trim();
+        if ("".equals(inputString)) {
+            return null;
+        }
+        return inputString;
+    }
+
+
+    /**
      * Define the mapper to map source to destination files.
      * @return a mapper to be configured.
      * @exception BuildException if more than one mapper is defined.
@@ -726,6 +761,14 @@ public class Get extends Task {
                 connection.setRequestProperty("Accept-Encoding", GZIP_CONTENT_ENCODING);
             }
 
+            if (!headers.isEmpty()) {
+                for (final Map.Entry<String, String> header : headers.entrySet()) {
+                    //we do not log the header value as it may contain sensitive data like passwords
+                    log(String.format("Adding header '%s' ", header.getKey()));
+                    connection.setRequestProperty(header.getKey(), header.getValue());
+                }
+            }
+
             if (connection instanceof HttpURLConnection) {
                 ((HttpURLConnection) connection)
                         .setInstanceFollowRedirects(false);

http://git-wip-us.apache.org/repos/asf/ant/blob/b83bdceb/src/main/org/apache/tools/ant/taskdefs/email/Header.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/email/Header.java b/src/main/org/apache/tools/ant/taskdefs/email/Header.java
index 6bcfb66..aaee693 100644
--- a/src/main/org/apache/tools/ant/taskdefs/email/Header.java
+++ b/src/main/org/apache/tools/ant/taskdefs/email/Header.java
@@ -19,7 +19,9 @@
 package org.apache.tools.ant.taskdefs.email;
 
 /**
- * Class representing a generic e-mail header.
+ * Class representing a generic key-value header.
+ * TODO: This should be moved out of the email package
+ *
  * @since Ant 1.7
  */
 public class Header {

http://git-wip-us.apache.org/repos/asf/ant/blob/b83bdceb/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java
index 3e1157d..52950c9 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.tools.ant.taskdefs;
 
+import org.apache.tools.ant.AntAssert;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.BuildFileRule;
 import org.junit.After;
@@ -25,6 +26,7 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
 /**
@@ -103,6 +105,8 @@ public class GetTest {
     public void test7() {
         try {
             buildRule.executeTarget("test7");
+            AntAssert.assertNotContains("Adding header", buildRule.getLog());
+
             fail("userAgent may not be null or empty");
         } catch (BuildException ex) {
             //TODO assert value
@@ -119,4 +123,36 @@ public class GetTest {
         buildRule.executeTarget("testUseTomorrow");
     }
 
+    @Test
+    public void testTwoHeaders() {
+        buildRule.executeTarget("testTwoHeaders");
+        String log = buildRule.getLog();
+        AntAssert.assertContains("Adding header 'header1'", log);
+        AntAssert.assertContains("Adding header 'header2'", log);
+    }
+
+    @Test
+    public void testEmptyHeadersAreNeverAdded() {
+        buildRule.executeTarget("testEmptyHeaders");
+        AntAssert.assertNotContains("Adding header", buildRule.getLog());
+    }
+
+    @Test
+    public void testThatWhenMoreThanOneHeaderHaveSameNameOnlyLastOneIsAdded() {
+        buildRule.executeTarget("testDuplicateHeaderNames");
+        String log = buildRule.getLog();
+        AntAssert.assertContains("Adding header 'header1'", log);
+
+        String firstHeaderLogTrimmed = log.replaceFirst("Adding header ", "");
+        String allHeaderLogsTrimmed = log.replaceAll("Adding header ", "");
+
+        assertEquals("Only one header has been added", firstHeaderLogTrimmed, allHeaderLogsTrimmed);
+    }
+
+    @Test
+    public void testHeaderSpaceTrimmed() {
+        buildRule.executeTarget("testHeaderSpacesTrimmed");
+        AntAssert.assertContains("Adding header 'header1'", buildRule.getLog());
+    }
+
 }


[2/4] ant git commit: [AA] bugzilla-Bug-60628-Ant-Get-Task-To-Accept-Arbitrary-Header : simplifying test

Posted by jh...@apache.org.
[AA]  bugzilla-Bug-60628-Ant-Get-Task-To-Accept-Arbitrary-Header : simplifying test


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/3d215101
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/3d215101
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/3d215101

Branch: refs/heads/master
Commit: 3d215101449f63be2c62baf49425a929d758168f
Parents: b83bdce
Author: Arcadius <ar...@menelic.com>
Authored: Mon Jan 23 23:50:55 2017 +0000
Committer: Arcadius <ar...@menelic.com>
Committed: Mon Jan 23 23:50:55 2017 +0000

----------------------------------------------------------------------
 src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/3d215101/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java
index 52950c9..e18fdcd 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java
@@ -143,10 +143,9 @@ public class GetTest {
         String log = buildRule.getLog();
         AntAssert.assertContains("Adding header 'header1'", log);
 
-        String firstHeaderLogTrimmed = log.replaceFirst("Adding header ", "");
-        String allHeaderLogsTrimmed = log.replaceAll("Adding header ", "");
+        int actualHeaderCount = log.split("Adding header ").length - 1;
 
-        assertEquals("Only one header has been added", firstHeaderLogTrimmed, allHeaderLogsTrimmed);
+        assertEquals("Only one header has been added", 1, actualHeaderCount);
     }
 
     @Test


[3/4] ant git commit: [AA] Bugzilla Bug 60628: Change after code review by @janmaterne

Posted by jh...@apache.org.
[AA] Bugzilla Bug 60628: Change after code review by @janmaterne


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/198d7a2f
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/198d7a2f
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/198d7a2f

Branch: refs/heads/master
Commit: 198d7a2f449b91d7c559e17e2bc472269a8645ac
Parents: 3d21510
Author: Arcadius Ahouansou <Ar...@aexp.com>
Authored: Mon Jan 30 22:48:40 2017 +0000
Committer: Arcadius Ahouansou <Ar...@aexp.com>
Committed: Mon Jan 30 22:48:40 2017 +0000

----------------------------------------------------------------------
 manual/Tasks/get.html                           | 11 +++----
 src/etc/testcases/taskdefs/get.xml              |  8 ++---
 src/main/org/apache/tools/ant/taskdefs/Get.java | 32 ++++++--------------
 .../org/apache/tools/ant/util/StringUtils.java  | 21 +++++++++++++
 .../org/apache/tools/ant/taskdefs/GetTest.java  | 10 +++---
 .../apache/tools/ant/util/StringUtilsTest.java  | 27 ++++++++++++++---
 6 files changed, 67 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/198d7a2f/manual/Tasks/get.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/get.html b/manual/Tasks/get.html
index a6d89e9..e63b59d 100644
--- a/manual/Tasks/get.html
+++ b/manual/Tasks/get.html
@@ -183,12 +183,12 @@ plain text' authentication is used. This is only secure over an HTTPS link.
   </tr>
   <tr>
     <td valign="top">name</td>
-    <td valign="top">The name or key of this header.</td>
+    <td valign="top">The name or key of this header. Cannot be null or empty. Leading and trailing spaces are removed</td>
     <td align="center" valign="top">Yes</td>
   </tr>
   <tr>
     <td valign="top">value</td>
-    <td valign="top">The value to assign to the.</td>
+    <td valign="top">The value to assign to the header. Cannot be null or empty. Leading and trailing spaces are removed</td>
     <td align="center" valign="top">Yes</td>
   </tr>
 </table>
@@ -261,10 +261,9 @@ the <a href="input.html">input task</a> to query for a password.</p>
 <p>With custom HTTP headers</p>
 <pre>
 &lt;get src=&quot;http://ant.apache.org/index.html&quot; dest=&quot;downloads&quot;&gt;
-  &lt;header name=&quot;header1&quot; value==&quot;headerValue1&quot; /&gt;
-  &lt;header name=&quot;header2&quot; value==&quot;headerValue2&quot; /&gt;
-  &lt;header name=&quot;header3&quot; value==&quot;headerValue3&quot; /&gt;
-
+  &lt;header name=&quot;header1&quot; value=&quot;headerValue1&quot; /&gt;
+  &lt;header name=&quot;header2&quot; value=&quot;headerValue2&quot; /&gt;
+  &lt;header name=&quot;header3&quot; value=&quot;headerValue3&quot; /&gt;
 &lt;/get&gt;
 </pre>
 

http://git-wip-us.apache.org/repos/asf/ant/blob/198d7a2f/src/etc/testcases/taskdefs/get.xml
----------------------------------------------------------------------
diff --git a/src/etc/testcases/taskdefs/get.xml b/src/etc/testcases/taskdefs/get.xml
index 569d833..188febd 100644
--- a/src/etc/testcases/taskdefs/get.xml
+++ b/src/etc/testcases/taskdefs/get.xml
@@ -98,21 +98,21 @@
     </fail>
   </target>
 
-  <target name="testTwoHeaders">
+  <target name="testTwoHeadersAreAddedOK">
     <get src="http://www.apache.org/" dest="get.tmp">
       <header name="header1" value="header1Value"/>
       <header name="header2" value="header2Value"/>
     </get>
   </target>
 
-  <target name="testEmptyHeaders">
+  <target name="testEmptyHeadersAreNeverAdded">
     <get src="http://www.apache.org/" dest="get.tmp">
       <header name="" value="headerValue"/>
       <header name="header2" value=""/>
     </get>
   </target>
 
-  <target name="testDuplicateHeaderNames">
+  <target name="testThatWhenMoreThanOneHeaderHaveSameNameOnlyLastOneIsAdded">
     <get src="http://www.apache.org/" dest="get.tmp">
       <header name="header1" value="headerValue1"/>
       <header name="header1" value="headerValue2"/>
@@ -120,7 +120,7 @@
     </get>
   </target>
 
-  <target name="testHeaderSpacesTrimmed">
+  <target name="testHeaderSpaceTrimmed">
     <get src="http://www.apache.org/" dest="get.tmp">
       <header name="  header1     " value="  headerValue1  "/>
     </get>

http://git-wip-us.apache.org/repos/asf/ant/blob/198d7a2f/src/main/org/apache/tools/ant/taskdefs/Get.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Get.java b/src/main/org/apache/tools/ant/taskdefs/Get.java
index 2200bd8..674a535 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Get.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Get.java
@@ -45,6 +45,8 @@ import org.apache.tools.ant.types.resources.URLProvider;
 import org.apache.tools.ant.types.resources.URLResource;
 import org.apache.tools.ant.util.FileNameMapper;
 import org.apache.tools.ant.util.FileUtils;
+import org.apache.tools.ant.util.StringUtils;
+
 import java.util.LinkedHashMap;
 import java.util.Map;
 
@@ -495,28 +497,14 @@ public class Get extends Task {
      */
     public void addConfiguredHeader(Header header) {
         if (header != null) {
-            String key = trimToNull(header.getName());
-            String value = trimToNull(header.getValue());
+            String key = StringUtils.trimToNull(header.getName());
+            String value = StringUtils.trimToNull(header.getValue());
             if (key != null && value != null) {
                 this.headers.put(key, value);
             }
         }
     }
 
-    private String trimToNull(String inputString) {
-
-        if (inputString == null) {
-            return null;
-        }
-
-        inputString = inputString.trim();
-        if ("".equals(inputString)) {
-            return null;
-        }
-        return inputString;
-    }
-
-
     /**
      * Define the mapper to map source to destination files.
      * @return a mapper to be configured.
@@ -761,14 +749,14 @@ public class Get extends Task {
                 connection.setRequestProperty("Accept-Encoding", GZIP_CONTENT_ENCODING);
             }
 
-            if (!headers.isEmpty()) {
-                for (final Map.Entry<String, String> header : headers.entrySet()) {
-                    //we do not log the header value as it may contain sensitive data like passwords
-                    log(String.format("Adding header '%s' ", header.getKey()));
-                    connection.setRequestProperty(header.getKey(), header.getValue());
-                }
+
+            for (final Map.Entry<String, String> header : headers.entrySet()) {
+                //we do not log the header value as it may contain sensitive data like passwords
+                log(String.format("Adding header '%s' ", header.getKey()));
+                connection.setRequestProperty(header.getKey(), header.getValue());
             }
 
+
             if (connection instanceof HttpURLConnection) {
                 ((HttpURLConnection) connection)
                         .setInstanceFollowRedirects(false);

http://git-wip-us.apache.org/repos/asf/ant/blob/198d7a2f/src/main/org/apache/tools/ant/util/StringUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/StringUtils.java b/src/main/org/apache/tools/ant/util/StringUtils.java
index 04f1ce8..6ee9c45 100644
--- a/src/main/org/apache/tools/ant/util/StringUtils.java
+++ b/src/main/org/apache/tools/ant/util/StringUtils.java
@@ -306,4 +306,25 @@ public final class StringUtils {
     private static Collector<CharSequence,?,String> joining(CharSequence separator) {
         return separator == null ? Collectors.joining() : Collectors.joining(separator);
     }
+
+
+    /**
+     * @param inputString String to trim
+     * @return null if the input string is null or empty or contain only empty spaces.
+     * It returns the input string without leading and trailing spaces otherwise.
+     *
+     */
+    public static String trimToNull(String inputString) {
+
+        if (inputString == null) {
+            return null;
+        }
+
+       String tmpString = inputString.trim();
+        if ("".equals(tmpString)) {
+            return null;
+        }
+        return tmpString;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/198d7a2f/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java
index e18fdcd..fb78937 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java
@@ -124,8 +124,8 @@ public class GetTest {
     }
 
     @Test
-    public void testTwoHeaders() {
-        buildRule.executeTarget("testTwoHeaders");
+    public void testTwoHeadersAreAddedOK() {
+        buildRule.executeTarget("testTwoHeadersAreAddedOK");
         String log = buildRule.getLog();
         AntAssert.assertContains("Adding header 'header1'", log);
         AntAssert.assertContains("Adding header 'header2'", log);
@@ -133,13 +133,13 @@ public class GetTest {
 
     @Test
     public void testEmptyHeadersAreNeverAdded() {
-        buildRule.executeTarget("testEmptyHeaders");
+        buildRule.executeTarget("testEmptyHeadersAreNeverAdded");
         AntAssert.assertNotContains("Adding header", buildRule.getLog());
     }
 
     @Test
     public void testThatWhenMoreThanOneHeaderHaveSameNameOnlyLastOneIsAdded() {
-        buildRule.executeTarget("testDuplicateHeaderNames");
+        buildRule.executeTarget("testThatWhenMoreThanOneHeaderHaveSameNameOnlyLastOneIsAdded");
         String log = buildRule.getLog();
         AntAssert.assertContains("Adding header 'header1'", log);
 
@@ -150,7 +150,7 @@ public class GetTest {
 
     @Test
     public void testHeaderSpaceTrimmed() {
-        buildRule.executeTarget("testHeaderSpacesTrimmed");
+        buildRule.executeTarget("testHeaderSpaceTrimmed");
         AntAssert.assertContains("Adding header 'header1'", buildRule.getLog());
     }
 

http://git-wip-us.apache.org/repos/asf/ant/blob/198d7a2f/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
index d2187c4..612c6ec 100644
--- a/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java
@@ -17,16 +17,14 @@
  */
 package org.apache.tools.ant.util;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Vector;
 
 import org.junit.Test;
 
+import static org.junit.Assert.*;
+
 /**
  * Test for StringUtils
  */
@@ -195,5 +193,24 @@ public class StringUtilsTest {
     public void testJoinNullSeparator() {
         assertEquals("abc", StringUtils.join(Arrays.asList("a", "b", "c"), null));
     }
-    
+
+    @Test
+    public void testTrimToNullWithNullInput(){
+        assertNull(StringUtils.trimToNull(null));
+    }
+
+    @Test
+    public void testTrimToNullWithEmptyInput(){
+        assertNull(StringUtils.trimToNull(""));
+    }
+
+    @Test
+    public void testTrimToNullWithBlankSpaceInput(){
+        assertNull(StringUtils.trimToNull("   "));
+    }
+
+    @Test
+    public void testTrimToNullWithInputPaddedWithSpace(){
+        assertEquals("aaBcDeF",StringUtils.trimToNull(" aaBcDeF  "));
+    }
 }


[4/4] ant git commit: Merge remote-tracking branch 'origin/pr/31'

Posted by jh...@apache.org.
Merge remote-tracking branch 'origin/pr/31'


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/1ccf1989
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/1ccf1989
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/1ccf1989

Branch: refs/heads/master
Commit: 1ccf1989ac4c780845737fcb6b5e9b7e9664084b
Parents: 79a34b8 198d7a2
Author: Jan Mat�rne <jh...@apache.org>
Authored: Thu Feb 9 08:09:23 2017 +0100
Committer: Jan Mat�rne <jh...@apache.org>
Committed: Thu Feb 9 08:09:23 2017 +0100

----------------------------------------------------------------------
 manual/Tasks/get.html                           | 33 ++++++++++++++++++
 src/etc/testcases/taskdefs/get.xml              | 28 ++++++++++++++++
 src/main/org/apache/tools/ant/taskdefs/Get.java | 31 +++++++++++++++++
 .../apache/tools/ant/taskdefs/email/Header.java |  4 ++-
 .../org/apache/tools/ant/util/StringUtils.java  | 21 ++++++++++++
 .../org/apache/tools/ant/taskdefs/GetTest.java  | 35 ++++++++++++++++++++
 .../apache/tools/ant/util/StringUtilsTest.java  | 27 ++++++++++++---
 7 files changed, 173 insertions(+), 6 deletions(-)
----------------------------------------------------------------------