mirror of https://github.com/sbt/sbt.git
Read https+ftp proxy environment variables into system properties. Fixes #886.
This commit is contained in:
parent
d4aa7bf0e9
commit
97e5ac8ec1
|
|
@ -91,14 +91,28 @@ private object BootConfiguration
|
|||
None
|
||||
}
|
||||
}
|
||||
private final class ProxyProperties(
|
||||
val envURL: String,
|
||||
val envUser: String,
|
||||
val envPassword: String,
|
||||
val sysHost: String,
|
||||
val sysPort: String,
|
||||
val sysUser: String,
|
||||
val sysPassword: String
|
||||
)
|
||||
private object ProxyProperties
|
||||
{
|
||||
val HttpProxyEnv = "http_proxy"
|
||||
val HttpProxyUser = "http_proxy_user"
|
||||
val HttpProxyPassword = "http_proxy_pass"
|
||||
val http = apply("http")
|
||||
val https = apply("https")
|
||||
val ftp = apply("ftp")
|
||||
|
||||
val ProxyHost = "http.proxyHost"
|
||||
val ProxyPort = "http.proxyPort"
|
||||
val ProxyUser = "http.proxyUser"
|
||||
val ProxyPassword = "http.proxyPassword"
|
||||
def apply(pre: String) = new ProxyProperties(
|
||||
pre+"_proxy",
|
||||
pre+"_proxy_user",
|
||||
pre+"_proxy_pass",
|
||||
pre+".proxyHost",
|
||||
pre+".proxyPort",
|
||||
pre+".proxyUser",
|
||||
pre+".proxyPassword"
|
||||
)
|
||||
}
|
||||
|
|
@ -11,18 +11,25 @@ object CheckProxy
|
|||
def apply()
|
||||
{
|
||||
import ProxyProperties._
|
||||
val httpProxy = System.getenv(HttpProxyEnv)
|
||||
if(isDefined(httpProxy) && !isPropertyDefined(ProxyHost) && !isPropertyDefined(ProxyPort))
|
||||
for( pp <- Seq(http, https, ftp))
|
||||
setFromEnv(pp)
|
||||
}
|
||||
|
||||
private[this] def setFromEnv(conf: ProxyProperties)
|
||||
{
|
||||
import conf._
|
||||
val proxyURL = System.getenv(envURL)
|
||||
if(isDefined(proxyURL) && !isPropertyDefined(sysHost) && !isPropertyDefined(sysPort))
|
||||
{
|
||||
try
|
||||
{
|
||||
val proxy = new URL(httpProxy)
|
||||
setProperty(ProxyHost, proxy.getHost)
|
||||
val proxy = new URL(proxyURL)
|
||||
setProperty(sysHost, proxy.getHost)
|
||||
val port = proxy.getPort
|
||||
if(port >= 0)
|
||||
System.setProperty(ProxyPort, port.toString)
|
||||
copyEnv(HttpProxyUser, ProxyUser)
|
||||
copyEnv(HttpProxyPassword, ProxyPassword)
|
||||
System.setProperty(sysPort, port.toString)
|
||||
copyEnv(envUser, sysUser)
|
||||
copyEnv(envPassword, sysPassword)
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -31,6 +38,7 @@ object CheckProxy
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def copyEnv(envKey: String, sysKey: String) { setProperty(sysKey, System.getenv(envKey)) }
|
||||
private def setProperty(key: String, value: String) { if(value != null) System.setProperty(key, value) }
|
||||
private def isPropertyDefined(k: String) = isDefined(System.getProperty(k))
|
||||
|
|
|
|||
|
|
@ -52,22 +52,27 @@ following uses the pre-0.11 style of putting the boot directory in
|
|||
|
||||
java -Dsbt.boot.directory=project/boot/
|
||||
|
||||
HTTP Proxy
|
||||
----------
|
||||
HTTP/HTTPS/FTP Proxy
|
||||
--------------------
|
||||
|
||||
On Unix, sbt will pick up any HTTP proxy settings from the standard
|
||||
`http_proxy` environment variable. If you are behind a proxy requiring
|
||||
authentication, your `sbt` script must also pass flags to set the
|
||||
`http.proxyUser` and `http.proxyPassword` properties:
|
||||
On Unix, sbt will pick up any HTTP, HTTPS, or FTP proxy settings from the standard
|
||||
`http_proxy`, `https_proxy`, and `ftp_proxy` environment variables. If you are behind
|
||||
a proxy requiring authentication, your `sbt` script must also pass flags to set the
|
||||
`http.proxyUser` and `http.proxyPassword` properties for HTTP,
|
||||
`ftp.proxyUser` and `ftp.proxyPassword` properties for FTP,
|
||||
or `https.proxyUser` and `https.proxyPassword` properties for HTTPS.
|
||||
|
||||
For example,
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
java -Dhttp.proxyUser=username -Dhttp.proxyPassword=mypassword
|
||||
|
||||
On Windows, your script should set properties for proxy host, port, and
|
||||
if applicable, username and password:
|
||||
if applicable, username and password. For example, for HTTP:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
java -Dhttp.proxyHost=myproxy -Dhttp.proxyPort=8080 -Dhttp.proxyUser=username -Dhttp.proxyPassword=mypassword
|
||||
|
||||
Replace `http` with `https` or `ftp` in the above command line to configure HTTPS or FTP.
|
||||
|
|
|
|||
Loading…
Reference in New Issue