git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@370259 13f79535-47bb-0310-9956-ffa450edef68master
@@ -165,6 +165,7 @@ | |||
<selector id="needs.jdk1.5+"> | |||
<or> | |||
<filename name="${taskdefs.package}/AptTest*"/> | |||
<filename name="${util.package}/java15/*"/> | |||
</or> | |||
</selector> | |||
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2002-2005 The Apache Software Foundation | |||
* Copyright 2002-2006 The Apache Software Foundation | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
@@ -19,6 +19,8 @@ package org.apache.tools.ant; | |||
import org.apache.tools.ant.util.LoaderUtils; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.util.JAXPUtils; | |||
import org.apache.tools.ant.util.ProxySetup; | |||
import org.apache.tools.ant.util.JavaEnvUtils; | |||
import org.apache.tools.ant.launch.Launcher; | |||
import org.xml.sax.XMLReader; | |||
@@ -285,6 +287,10 @@ public final class Diagnostics { | |||
header(out, "Locale information"); | |||
doReportLocale(out); | |||
header(out, "Proxy information"); | |||
doReportProxy(out); | |||
out.println(); | |||
} | |||
@@ -413,7 +419,8 @@ public final class Diagnostics { | |||
Class.forName(classname); | |||
props.remove(key); | |||
} catch (ClassNotFoundException e) { | |||
out.println(key + " : Not Available"); | |||
out.println(key + " : Not Available " | |||
+ "(the implementation class is not present)"); | |||
} catch (NoClassDefFoundError e) { | |||
String pkg = e.getMessage().replace('/', '.'); | |||
out.println(key + " : Missing dependency " + pkg); | |||
@@ -423,6 +430,9 @@ public final class Diagnostics { | |||
} | |||
if (props.size() == 0) { | |||
out.println("All defined tasks are available"); | |||
} else { | |||
out.println("A task being missing/unavailable should only " | |||
+"matter if you are trying to use it"); | |||
} | |||
} catch (IOException e) { | |||
out.println(e.getMessage()); | |||
@@ -494,7 +504,7 @@ public final class Diagnostics { | |||
tempFile.delete(); | |||
out.println("Temp dir is writeable"); | |||
long drift = filetime - now; | |||
out.println("temp dir alignment with system clock is " + drift + " ms"); | |||
out.println("Temp dir alignment with system clock is " + drift + " ms"); | |||
if (Math.abs(drift) > BIG_DRIFT_LIMIT) { | |||
out.println("Warning: big clock drift -maybe a network filesystem"); | |||
} | |||
@@ -513,7 +523,7 @@ public final class Diagnostics { | |||
/** | |||
* Report locale information | |||
* @param out | |||
* @param out stream to print to | |||
*/ | |||
private static void doReportLocale(PrintStream out) { | |||
//calendar stuff. | |||
@@ -530,4 +540,67 @@ public final class Diagnostics { | |||
+ cal.get(Calendar.SECOND)) * SECONDS_PER_MILLISECOND | |||
+ cal.get(Calendar.MILLISECOND))); | |||
} | |||
/** | |||
* print a property name="value" pair, or name=[undefined] if there is none | |||
* @param out | |||
* @param name | |||
*/ | |||
private static void printProperty(PrintStream out,String name) { | |||
out.print(name); | |||
out.print(" = "); | |||
String value=System.getProperty(name); | |||
if(value!=null) { | |||
out.print('"'); | |||
out.print(value); | |||
out.println('"'); | |||
} else { | |||
out.println("[undefined]"); | |||
} | |||
} | |||
/** | |||
* Report proxy information | |||
* | |||
* @param out stream to print to | |||
*/ | |||
private static void doReportProxy(PrintStream out) { | |||
if(JavaEnvUtils.getJavaVersionNumber()>=15) { | |||
printProperty(out, ProxySetup.USE_SYSTEM_PROXIES); | |||
} | |||
printProperty(out,ProxySetup.HTTP_PROXY_HOST); | |||
printProperty(out, ProxySetup.HTTP_PROXY_PORT); | |||
printProperty(out, ProxySetup.HTTP_PROXY_USERNAME); | |||
printProperty(out, ProxySetup.HTTP_PROXY_PASSWORD); | |||
printProperty(out, ProxySetup.HTTP_NON_PROXY_HOSTS); | |||
printProperty(out, ProxySetup.HTTPS_PROXY_HOST); | |||
printProperty(out, ProxySetup.HTTPS_PROXY_PORT); | |||
printProperty(out, ProxySetup.HTTPS_NON_PROXY_HOSTS); | |||
printProperty(out, ProxySetup.FTP_PROXY_HOST); | |||
printProperty(out, ProxySetup.FTP_PROXY_PORT); | |||
printProperty(out, ProxySetup.FTP_NON_PROXY_HOSTS); | |||
printProperty(out, ProxySetup.SOCKS_PROXY_HOST); | |||
printProperty(out, ProxySetup.SOCKS_PROXY_PORT); | |||
printProperty(out, ProxySetup.SOCKS_PROXY_USERNAME); | |||
printProperty(out, ProxySetup.SOCKS_PROXY_PASSWORD); | |||
final String proxyDiagClassname="org.apache.tools.ant.util.java15.ProxyDiagnostics"; | |||
try { | |||
Class proxyDiagClass = Class.forName(proxyDiagClassname); | |||
Object instance =proxyDiagClass.newInstance(); | |||
out.println("Java1.5+ proxy settings"); | |||
out.println(instance.toString()); | |||
} catch (ClassNotFoundException e) { | |||
//not included, do nothing | |||
} catch (IllegalAccessException e) { | |||
//not included, do nothing | |||
} catch (InstantiationException e) { | |||
//not included, do nothing | |||
} | |||
} | |||
} |
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2000-2005 The Apache Software Foundation | |||
* Copyright 2000-2006 The Apache Software Foundation | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
@@ -22,6 +22,7 @@ import java.util.Properties; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.Task; | |||
import org.apache.tools.ant.util.ProxySetup; | |||
/** | |||
* Sets Java's web proxy properties, so that tasks and code run in | |||
@@ -178,32 +179,32 @@ public class SetProxy extends Task { | |||
if (proxyHost.length() != 0) { | |||
traceSettingInfo(); | |||
enablingProxy = true; | |||
sysprops.put("http.proxyHost", proxyHost); | |||
sysprops.put(ProxySetup.HTTP_PROXY_HOST, proxyHost); | |||
String portString = Integer.toString(proxyPort); | |||
sysprops.put("http.proxyPort", portString); | |||
sysprops.put("https.proxyHost", proxyHost); | |||
sysprops.put("https.proxyPort", portString); | |||
sysprops.put("ftp.proxyHost", proxyHost); | |||
sysprops.put("ftp.proxyPort", portString); | |||
sysprops.put(ProxySetup.HTTP_PROXY_PORT, portString); | |||
sysprops.put(ProxySetup.HTTPS_PROXY_HOST, proxyHost); | |||
sysprops.put(ProxySetup.HTTPS_PROXY_PORT, portString); | |||
sysprops.put(ProxySetup.FTP_PROXY_HOST, proxyHost); | |||
sysprops.put(ProxySetup.FTP_PROXY_PORT, portString); | |||
if (nonProxyHosts != null) { | |||
sysprops.put("http.nonProxyHosts", nonProxyHosts); | |||
sysprops.put("https.nonProxyHosts", nonProxyHosts); | |||
sysprops.put("ftp.nonProxyHosts", nonProxyHosts); | |||
sysprops.put(ProxySetup.HTTP_NON_PROXY_HOSTS, nonProxyHosts); | |||
sysprops.put(ProxySetup.HTTPS_NON_PROXY_HOSTS, nonProxyHosts); | |||
sysprops.put(ProxySetup.FTP_NON_PROXY_HOSTS, nonProxyHosts); | |||
} | |||
if (proxyUser != null) { | |||
sysprops.put("http.proxyUser", proxyUser); | |||
sysprops.put("http.proxyPassword", proxyPassword); | |||
sysprops.put(ProxySetup.HTTP_PROXY_USERNAME, proxyUser); | |||
sysprops.put(ProxySetup.HTTP_PROXY_PASSWORD, proxyPassword); | |||
} | |||
} else { | |||
log("resetting http proxy", Project.MSG_VERBOSE); | |||
sysprops.remove("http.proxyHost"); | |||
sysprops.remove("http.proxyPort"); | |||
sysprops.remove("http.proxyUser"); | |||
sysprops.remove("http.proxyPassword"); | |||
sysprops.remove("https.proxyHost"); | |||
sysprops.remove("https.proxyPort"); | |||
sysprops.remove("ftp.proxyHost"); | |||
sysprops.remove("ftp.proxyPort"); | |||
sysprops.remove(ProxySetup.HTTP_PROXY_HOST); | |||
sysprops.remove(ProxySetup.HTTP_PROXY_PORT); | |||
sysprops.remove(ProxySetup.HTTP_PROXY_USERNAME); | |||
sysprops.remove(ProxySetup.HTTP_PROXY_PASSWORD); | |||
sysprops.remove(ProxySetup.HTTPS_PROXY_HOST); | |||
sysprops.remove(ProxySetup.HTTPS_PROXY_PORT); | |||
sysprops.remove(ProxySetup.FTP_PROXY_HOST); | |||
sysprops.remove(ProxySetup.FTP_PROXY_PORT); | |||
} | |||
} | |||
@@ -212,20 +213,20 @@ public class SetProxy extends Task { | |||
settingsChanged = true; | |||
if (socksProxyHost.length() != 0) { | |||
enablingProxy = true; | |||
sysprops.put("socksProxyHost", socksProxyHost); | |||
sysprops.put("socksProxyPort", Integer.toString(socksProxyPort)); | |||
sysprops.put(ProxySetup.SOCKS_PROXY_HOST, socksProxyHost); | |||
sysprops.put(ProxySetup.SOCKS_PROXY_PORT, Integer.toString(socksProxyPort)); | |||
if (proxyUser != null) { | |||
//this may be a java1.4 thingy only | |||
sysprops.put("java.net.socks.username", proxyUser); | |||
sysprops.put("java.net.socks.password", proxyPassword); | |||
sysprops.put(ProxySetup.SOCKS_PROXY_USERNAME, proxyUser); | |||
sysprops.put(ProxySetup.SOCKS_PROXY_PASSWORD, proxyPassword); | |||
} | |||
} else { | |||
log("resetting socks proxy", Project.MSG_VERBOSE); | |||
sysprops.remove("socksProxyHost"); | |||
sysprops.remove("socksProxyPort"); | |||
sysprops.remove("java.net.socks.username"); | |||
sysprops.remove("java.net.socks.password"); | |||
sysprops.remove(ProxySetup.SOCKS_PROXY_HOST); | |||
sysprops.remove(ProxySetup.SOCKS_PROXY_PORT); | |||
sysprops.remove(ProxySetup.SOCKS_PROXY_USERNAME); | |||
sysprops.remove(ProxySetup.SOCKS_PROXY_PASSWORD); | |||
} | |||
} | |||
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2005 The Apache Software Foundation | |||
* Copyright 2005-2006 The Apache Software Foundation | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
@@ -37,6 +37,21 @@ public class ProxySetup { | |||
* @value | |||
*/ | |||
public static final String USE_SYSTEM_PROXIES="java.net.useSystemProxies"; | |||
public static final String HTTP_PROXY_HOST = "http.proxyHost"; | |||
public static final String HTTP_PROXY_PORT = "http.proxyPort"; | |||
public static final String HTTPS_PROXY_HOST = "https.proxyHost"; | |||
public static final String HTTPS_PROXY_PORT = "https.proxyPort"; | |||
public static final String FTP_PROXY_HOST = "ftp.proxyHost"; | |||
public static final String FTP_PROXY_PORT = "ftp.proxyPort"; | |||
public static final String HTTP_NON_PROXY_HOSTS = "http.nonProxyHosts"; | |||
public static final String HTTPS_NON_PROXY_HOSTS = "https.nonProxyHosts"; | |||
public static final String FTP_NON_PROXY_HOSTS = "ftp.nonProxyHosts"; | |||
public static final String HTTP_PROXY_USERNAME = "http.proxyUser"; | |||
public static final String HTTP_PROXY_PASSWORD = "http.proxyPassword"; | |||
public static final String SOCKS_PROXY_HOST = "socksProxyHost"; | |||
public static final String SOCKS_PROXY_PORT = "socksProxyPort"; | |||
public static final String SOCKS_PROXY_USERNAME = "java.net.socks.username"; | |||
public static final String SOCKS_PROXY_PASSWORD = "java.net.socks.password"; | |||
/** | |||
@@ -0,0 +1,107 @@ | |||
/* | |||
* Copyright 2006 The Apache Software Foundation | |||
* | |||
* Licensed 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. | |||
* | |||
*/ | |||
package org.apache.tools.ant.util.java15; | |||
import org.apache.tools.ant.BuildException; | |||
import java.net.ProxySelector; | |||
import java.net.URI; | |||
import java.net.URISyntaxException; | |||
import java.net.Proxy; | |||
import java.net.SocketAddress; | |||
import java.net.InetSocketAddress; | |||
import java.net.InetAddress; | |||
import java.util.List; | |||
import java.util.Iterator; | |||
/** | |||
* This class exists to create a string that tells diagnostics about the current | |||
* state of proxy diagnostics. | |||
* It does this in its toString operator. | |||
* Java1.5+ is needed to compile this class; its interface is classic typeless | |||
* Java. | |||
* @since Ant 1.7 | |||
*/ | |||
public class ProxyDiagnostics { | |||
String destination; | |||
URI destURI; | |||
/** {@value} */ | |||
public static final String DEFAULT_DESTINATION = "http://ant.apache.org/"; | |||
/** | |||
* create a diagnostics binding for a specific URI | |||
* @param destination dest to bind to | |||
* @throws BuildException if the URI is malformed. | |||
*/ | |||
public ProxyDiagnostics(String destination) { | |||
this.destination = destination; | |||
try { | |||
this.destURI=new URI(destination); | |||
} catch (URISyntaxException e) { | |||
throw new BuildException(e); | |||
} | |||
} | |||
/** | |||
* create a proxy diagnostics tool bound to | |||
* {@link #DEFAULT_DESTINATION} | |||
*/ | |||
public ProxyDiagnostics() { | |||
this(DEFAULT_DESTINATION); | |||
} | |||
public String toString() { | |||
ProxySelector selector=ProxySelector.getDefault(); | |||
List list = selector.select(destURI); | |||
StringBuffer result=new StringBuffer(); | |||
Iterator proxies=list.listIterator(); | |||
while (proxies.hasNext()) { | |||
Proxy proxy = (Proxy) proxies.next(); | |||
SocketAddress address = proxy.address(); | |||
if(address==null) { | |||
result.append("Direct connection\n"); | |||
} else { | |||
result.append(proxy.toString()); | |||
if(address instanceof InetSocketAddress) { | |||
InetSocketAddress ina=(InetSocketAddress) address; | |||
result.append(' '); | |||
result.append(ina.getHostName()); | |||
result.append(':'); | |||
result.append(ina.getPort()); | |||
if(ina.isUnresolved()) { | |||
result.append(" [unresolved]"); | |||
} else { | |||
InetAddress addr = ina.getAddress(); | |||
result.append(" ["); | |||
result.append(addr.getHostAddress()); | |||
result.append(']'); | |||
} | |||
} | |||
result.append('\n'); | |||
} | |||
} | |||
return result.toString(); | |||
} | |||
} |