diff options
author | Jan Christopher Vogt <oss.nsp@cvogt.org> | 2016-07-06 11:02:28 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-06 11:02:28 -0400 |
commit | dff71b0fce364e7edab5c1a1f11dd8b32e2c3983 (patch) | |
tree | 60e069857eefee238406202a1a0ba4e690017025 /nailgun_launcher | |
parent | bc2231720d3620b5e0459fa12c467bf675fcfdf5 (diff) | |
parent | c8733351614bed77bd72708fdb12b36268cb2a28 (diff) | |
download | cbt-dff71b0fce364e7edab5c1a1f11dd8b32e2c3983.tar.gz cbt-dff71b0fce364e7edab5c1a1f11dd8b32e2c3983.tar.bz2 cbt-dff71b0fce364e7edab5c1a1f11dd8b32e2c3983.zip |
Merge pull request #200 from benjaminfrank/feature/proxy_support
Support proxy settings in CBT.
Diffstat (limited to 'nailgun_launcher')
-rw-r--r-- | nailgun_launcher/NailgunLauncher.java | 1 | ||||
-rw-r--r-- | nailgun_launcher/Stage0Lib.java | 48 |
2 files changed, 46 insertions, 3 deletions
diff --git a/nailgun_launcher/NailgunLauncher.java b/nailgun_launcher/NailgunLauncher.java index c909c12..159041f 100644 --- a/nailgun_launcher/NailgunLauncher.java +++ b/nailgun_launcher/NailgunLauncher.java @@ -54,6 +54,7 @@ public class NailgunLauncher{ return; } + installProxySettings(); String[] diff = args[0].split("\\."); long start = _start - (Long.parseLong(diff[0]) * 1000L) - Long.parseLong(diff[1]); diff --git a/nailgun_launcher/Stage0Lib.java b/nailgun_launcher/Stage0Lib.java index 9c13680..5f8c5c7 100644 --- a/nailgun_launcher/Stage0Lib.java +++ b/nailgun_launcher/Stage0Lib.java @@ -67,7 +67,7 @@ public class Stage0Lib{ if(changed){ List<String> zincArgs = new ArrayList<String>( Arrays.asList( - new String[]{ + new String[]{ "-scala-compiler", earlyDeps.scalaCompiler_2_11_8_File, "-scala-library", earlyDeps.scalaLibrary_2_11_8_File, "-scala-extra", earlyDeps.scalaReflect_2_11_8_File, @@ -113,13 +113,55 @@ public class Stage0Lib{ new URL[]{ new URL("file:"+file) }, parent ); } + + private static String getVarFromEnv(String envKey) { + String value = System.getenv(envKey); + if(value==null || value.isEmpty()) { + value = System.getenv(envKey.toUpperCase()); + } + return value; + } + + private static void setProxyfromPropOrEnv(String envKey, String propKeyH, String propKeyP) { + String proxyHost = System.getProperty(propKeyH); + String proxyPort = System.getProperty(propKeyP); + if((proxyHost==null || proxyHost.isEmpty()) && (proxyPort==null || proxyPort.isEmpty())) { + String envVar = getVarFromEnv(envKey); + if(envVar != null && !envVar.isEmpty()) { + String[] proxy = envVar.replaceFirst("^https?://", "").split(":", 2); + System.setProperty(propKeyH, proxy[0]); + System.setProperty(propKeyP, proxy[1]); + } + } + } + + public static void installProxySettings() throws URISyntaxException { + setProxyfromPropOrEnv("http_proxy", "http.proxyHost", "http.proxyPort"); + setProxyfromPropOrEnv("https_proxy", "https.proxyHost", "https.proxyPort"); + String nonHosts = System.getProperty("http.nonProxyHosts"); + if(nonHosts==null || nonHosts.isEmpty()) { + String envVar = getVarFromEnv("no_proxy"); + if(envVar != null && !envVar.isEmpty()) { + System.setProperty("http.nonProxyHosts", envVar.replaceAll(",","|")); + } + } + } + + private static final ProxySelector ps = ProxySelector.getDefault(); + + public static HttpURLConnection openConnectionConsideringProxy(URL urlString) + throws IOException, URISyntaxException { + java.net.Proxy proxy = ps.select(urlString.toURI()).get(0); + return (HttpURLConnection) urlString.openConnection(proxy); + } + public static void download(URL urlString, Path target, String sha1) throws Exception { final Path unverified = Paths.get(target+".unverified"); if(!Files.exists(target)) { new File(target.toString()).getParentFile().mkdirs(); System.err.println("downloading " + urlString); System.err.println("to " + target); - final InputStream stream = urlString.openStream(); + final InputStream stream = openConnectionConsideringProxy(urlString).getInputStream(); Files.copy(stream, unverified, StandardCopyOption.REPLACE_EXISTING); stream.close(); final String checksum = sha1(Files.readAllBytes(unverified)); @@ -151,4 +193,4 @@ public class Stage0Lib{ copy[array.length] = item; return copy; } -}
\ No newline at end of file +} |