You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2013/12/05 19:24:22 UTC

svn commit: r1548232 - in /ant/core/trunk: CONTRIBUTORS contributors.xml src/main/org/apache/tools/ant/MagicNames.java src/main/org/apache/tools/ant/Main.java src/main/org/apache/tools/ant/taskdefs/Get.java

Author: bodewig
Date: Thu Dec  5 18:24:21 2013
New Revision: 1548232

URL: http://svn.apache.org/r1548232
Log:
configurable User-Agent for <get>. PR 55489. Submitted by André-John Mas

Modified:
    ant/core/trunk/CONTRIBUTORS
    ant/core/trunk/contributors.xml
    ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java
    ant/core/trunk/src/main/org/apache/tools/ant/Main.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Get.java

Modified: ant/core/trunk/CONTRIBUTORS
URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=1548232&r1=1548231&r2=1548232&view=diff
==============================================================================
--- ant/core/trunk/CONTRIBUTORS (original)
+++ ant/core/trunk/CONTRIBUTORS Thu Dec  5 18:24:21 2013
@@ -16,6 +16,7 @@ Andrew Eisenberg
 Andrew Everitt
 Andrew Stevens
 Andrey Urazov
+André-John Mas
 Andy Wood
 Anil K. Vijendran
 Anli Shundi

Modified: ant/core/trunk/contributors.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?rev=1548232&r1=1548231&r2=1548232&view=diff
==============================================================================
--- ant/core/trunk/contributors.xml (original)
+++ ant/core/trunk/contributors.xml Thu Dec  5 18:24:21 2013
@@ -91,6 +91,10 @@
     <last>Urazov</last>
   </name>
   <name>
+    <first>André-John</first>
+    <last>Mas</last>
+  </name>
+  <name>
     <first>Andy</first>
     <last>Wood</last>
   </name>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java?rev=1548232&r1=1548231&r2=1548232&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java Thu Dec  5 18:24:21 2013
@@ -282,5 +282,12 @@ public final class MagicNames {
      * @since Ant 1.9.1
      */
     public static final String ATTRIBUTE_NAMESPACE = "attribute namespace";
+
+    /**
+     * Name of the property which can provide an override of the
+     * User-Agent used in &lt;get&gt; tasks.
+     * Value {@value}
+     */
+    public static final String HTTP_AGENT_PROPERTY = "ant.http.agent";
 }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/Main.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Main.java?rev=1548232&r1=1548231&r2=1548232&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Main.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Main.java Thu Dec  5 18:24:21 2013
@@ -1061,6 +1061,11 @@ public class Main implements AntMain {
     private static String antVersion = null;
 
     /**
+     * Cache of the short Ant version information when it has been loaded.
+     */
+    private static String shortAntVersion = null;
+    
+    /**
      * Returns the Ant version information, if available. Once the information
      * has been loaded once, it's cached and returned from the cache on future
      * calls.
@@ -1078,10 +1083,11 @@ public class Main implements AntMain {
                     Main.class.getResourceAsStream("/org/apache/tools/ant/version.txt");
                 props.load(in);
                 in.close();
+                shortAntVersion = props.getProperty("VERSION");
 
                 StringBuffer msg = new StringBuffer();
                 msg.append("Apache Ant(TM) version ");
-                msg.append(props.getProperty("VERSION"));
+                msg.append(shortAntVersion);
                 msg.append(" compiled on ");
                 msg.append(props.getProperty("DATE"));
                 antVersion = msg.toString();
@@ -1094,6 +1100,24 @@ public class Main implements AntMain {
         }
         return antVersion;
     }
+    
+    /**
+     * Returns the short Ant version information, if available. Once the information
+     * has been loaded once, it's cached and returned from the cache on future
+     * calls.
+     * 
+     * @return the short Ant version information as a String
+     *         (always non-<code>null</code>)
+     *         
+     * @throws BuildException BuildException if the version information is unavailable
+     * @since Ant 1.9.3
+     */
+    public static String getShortAntVersion() throws BuildException {
+        if (shortAntVersion == null) {
+            getAntVersion();
+        }
+        return shortAntVersion;
+    }
 
      /**
       * Prints the description of a project (if there is one) to

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Get.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Get.java?rev=1548232&r1=1548231&r2=1548232&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Get.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Get.java Thu Dec  5 18:24:21 2013
@@ -31,6 +31,7 @@ import java.net.URLConnection;
 import java.util.Date;
 
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.MagicNames;
 import org.apache.tools.ant.Main;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
@@ -80,7 +81,10 @@ public class Get extends Task {
     private boolean skipExisting = false;
     private boolean httpUseCaches = true; // on by default
     private Mapper mapperElement = null;
-    private String userAgent = System.getProperty("http.agent", DEFAULT_AGENT_PREFIX + "/" + Main.getAntVersion()); 
+    private String userAgent = 
+        System.getProperty(MagicNames.HTTP_AGENT_PROPERTY,
+                           DEFAULT_AGENT_PREFIX + "/"
+                           + Main.getShortAntVersion());
 
     /**
      * Does the work.
@@ -406,6 +410,18 @@ public class Get extends Task {
     public void setSkipExisting(boolean s) {
         this.skipExisting = s;
     }
+    
+    /**
+     * HTTP connections only - set the user-agent to be used
+     * when communicating with remote server. if null, then
+     * the value is considered unset and the behaviour falls
+     * back to the default of the http API.
+     *
+     * @since Ant 1.9.3
+     */
+    public void setUserAgent(String userAgent) {
+        this.userAgent = userAgent;
+    }
 
     /**
      * HTTP connections only - control caching on the
@@ -422,16 +438,6 @@ public class Get extends Task {
     }
     
     /**
-     * HTTP connections only - set the user-agent to be used
-     * when communicating with remote server. if null, then
-     * the value is considered unset and the behaviour falls
-     * back to the default of the http API.
-     */
-    public void setUserAgent(String userAgent) {
-        this.userAgent = userAgent;
-    }
-
-    /**
      * Define the mapper to map source to destination files.
      * @return a mapper to be configured.
      * @exception BuildException if more than one mapper is defined.
@@ -657,6 +663,9 @@ public class Get extends Task {
             if (hasTimestamp) {
                 connection.setIfModifiedSince(timestamp);
             }
+            // Set the user agent
+            connection.addRequestProperty("User-Agent", this.userAgent);
+            
             // prepare Java 1.1 style credentials
             if (uname != null || pword != null) {
                 String up = uname + ":" + pword;