git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1548232 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -16,6 +16,7 @@ Andrew Eisenberg | |||
| Andrew Everitt | |||
| Andrew Stevens | |||
| Andrey Urazov | |||
| André-John Mas | |||
| Andy Wood | |||
| Anil K. Vijendran | |||
| Anli Shundi | |||
| @@ -90,6 +90,10 @@ | |||
| <first>Andrey</first> | |||
| <last>Urazov</last> | |||
| </name> | |||
| <name> | |||
| <first>André-John</first> | |||
| <last>Mas</last> | |||
| </name> | |||
| <name> | |||
| <first>Andy</first> | |||
| <last>Wood</last> | |||
| @@ -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 <get> tasks. | |||
| * Value {@value} | |||
| */ | |||
| public static final String HTTP_AGENT_PROPERTY = "ant.http.agent"; | |||
| } | |||
| @@ -1060,6 +1060,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 | |||
| @@ -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 | |||
| @@ -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 | |||
| @@ -421,16 +437,6 @@ public class Get extends Task { | |||
| this.httpUseCaches = httpUseCache; | |||
| } | |||
| /** | |||
| * 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. | |||
| @@ -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; | |||