1 18 19 package org.apache.tools.ant.util; 20 21 import org.apache.tools.ant.Project; 22 23 28 29 public class ProxySetup { 30 31 34 private Project owner; 35 36 40 public static final String USE_SYSTEM_PROXIES = "java.net.useSystemProxies"; 41 42 public static final String HTTP_PROXY_HOST = "http.proxyHost"; 43 44 public static final String HTTP_PROXY_PORT = "http.proxyPort"; 45 46 public static final String HTTPS_PROXY_HOST = "https.proxyHost"; 47 48 public static final String HTTPS_PROXY_PORT = "https.proxyPort"; 49 50 public static final String FTP_PROXY_HOST = "ftp.proxyHost"; 51 52 public static final String FTP_PROXY_PORT = "ftp.proxyPort"; 53 54 public static final String HTTP_NON_PROXY_HOSTS = "http.nonProxyHosts"; 55 56 public static final String HTTPS_NON_PROXY_HOSTS = "https.nonProxyHosts"; 57 58 public static final String FTP_NON_PROXY_HOSTS = "ftp.nonProxyHosts"; 59 60 public static final String HTTP_PROXY_USERNAME = "http.proxyUser"; 61 62 public static final String HTTP_PROXY_PASSWORD = "http.proxyPassword"; 63 64 public static final String SOCKS_PROXY_HOST = "socksProxyHost"; 65 66 public static final String SOCKS_PROXY_PORT = "socksProxyPort"; 67 68 public static final String SOCKS_PROXY_USERNAME = "java.net.socks.username"; 69 70 public static final String SOCKS_PROXY_PASSWORD = "java.net.socks.password"; 71 72 73 77 public ProxySetup(Project owner) { 78 this.owner = owner; 79 } 80 81 85 public static String getSystemProxySetting() { 86 try { 87 return System.getProperty(USE_SYSTEM_PROXIES); 88 } catch (SecurityException e) { 89 return null; 91 } 92 } 93 94 100 public void enableProxies() { 101 if (!(getSystemProxySetting() != null)) { 102 String proxies = owner.getProperty(USE_SYSTEM_PROXIES); 103 if (proxies == null || Project.toBoolean(proxies)) { 104 proxies = "true"; 105 } 106 String message = "setting " + USE_SYSTEM_PROXIES + " to " + proxies; 107 try { 108 owner.log(message, Project.MSG_DEBUG); 109 System.setProperty(USE_SYSTEM_PROXIES, proxies); 110 } catch (SecurityException e) { 111 owner.log("Security Exception when " + message); 114 } 115 } 116 } 117 118 } 119 | Popular Tags |