Last active
December 9, 2022 04:44
-
-
Save sandipchitale/3134e67b06291dfaa49b8346cceaf68f to your computer and use it in GitHub Desktop.
Configure http proxy #powershell #proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task generateHttpProxy() { | |
doFirst { | |
println "Paste the above sysprops to your gradle.properties in your project or ${project.gradle.gradleUserHomeDir}${File.separator}gradle.properties" | |
} | |
} | |
defaultTasks 'generateHttpProxy' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform | |
// https://docs.gradle.org/current/userguide/build_environment.html#sec:accessing_the_web_via_a_proxy | |
if (DefaultNativePlatform.getCurrentOperatingSystem().isWindows()) { | |
String proxyEnabled = ['reg', 'query', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', '/v', 'ProxyEnable'].execute().text | |
proxyEnabled.eachLine { | |
if (it.trim().startsWith('ProxyEnable')) { | |
if ('0x0' == it.split()[-1]) { | |
Properties systemProperties = System.getProperties(); | |
String proxyServer = ['reg', 'query', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings'].execute().text | |
proxyServer.eachLine { | |
if (it.trim().startsWith('ProxyServer')) { | |
String proxyServerHostPort = it.split()[-1] | |
systemProperties.setProperty('http.proxyHost', "${proxyServerHostPort.split(':')[0]}"); | |
systemProperties.setProperty('http.proxyPort', "${proxyServerHostPort.split(':')[1]}"); | |
systemProperties.setProperty('https.proxyHost', "${proxyServerHostPort.split(':')[0]}"); | |
systemProperties.setProperty('https.proxyPort', "${proxyServerHostPort.split(':')[1]}"); | |
} | |
if (it.trim().startsWith('ProxyOverride')) { | |
String nonProxyHosts = it.split()[-1].replace(';', '|'); | |
systemProperties.setProperty('http.nonProxyHosts', "${nonProxyHosts}"); | |
systemProperties.setProperty('https.nonProxyHosts', "${nonProxyHosts}"); | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' | findstr /R "^Proxy" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform | |
// https://docs.gradle.org/current/userguide/build_environment.html#sec:accessing_the_web_via_a_proxy | |
if (DefaultNativePlatform.getCurrentOperatingSystem().isWindows()) { | |
String proxyEnabled = ['reg', 'query', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', '/v', 'ProxyEnable'].execute().text | |
proxyEnabled.eachLine { | |
if (it.trim().startsWith('ProxyEnable')) { | |
if ('0x0' == it.split()[-1]) { | |
String proxyServer = ['reg', 'query', 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings'].execute().text | |
proxyServer.eachLine { | |
if (it.trim().startsWith('ProxyServer')) { | |
String proxyServerHostPort = it.split()[-1] | |
println "systemProp.http.proxyHost=${proxyServerHostPort.split(':')[0]}" | |
println "systemProp.http.proxyPort=${proxyServerHostPort.split(':')[1]}" | |
println "systemProp.https.proxyHost=${proxyServerHostPort.split(':')[0]}" | |
println "systemProp.https.proxyPort=${proxyServerHostPort.split(':')[1]}" | |
} | |
if (it.trim().startsWith('ProxyOverride')) { | |
String nonProxyHosts = it.split()[-1].replace(';', '|'); | |
println "systemProp.http.nonProxyHosts=${nonProxyHosts}" | |
println "systemProp.https.nonProxyHosts=${nonProxyHosts}" | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment