From c7e70342cc84e335c2d1e473d33f511339287521 Mon Sep 17 00:00:00 2001 From: "aleksandr.afanasiev" Date: Wed, 9 Nov 2016 02:02:11 +0300 Subject: [PATCH 1/4] adds https proxy support --- .../plugin/coveralls/CoverallsTask.groovy | 9 ++++- .../plugin/coveralls/domain/ProxyInfo.groovy | 28 ++++++++++++++ .../coveralls/domain/ProxyInfoFactory.groovy | 25 ++++++++++++ .../domain/ProxyInfoFactoryTest.groovy | 38 +++++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfo.groovy create mode 100644 src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactory.groovy create mode 100644 src/test/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactoryTest.groovy diff --git a/src/main/groovy/org/kt3k/gradle/plugin/coveralls/CoverallsTask.groovy b/src/main/groovy/org/kt3k/gradle/plugin/coveralls/CoverallsTask.groovy index 76ea851..df744fe 100644 --- a/src/main/groovy/org/kt3k/gradle/plugin/coveralls/CoverallsTask.groovy +++ b/src/main/groovy/org/kt3k/gradle/plugin/coveralls/CoverallsTask.groovy @@ -38,7 +38,7 @@ class CoverallsTask extends DefaultTask { void postJsonToUrl(String json, String url) { HTTPBuilder http = new HTTPBuilder(url) - + setProxy(http) http.request(POST) { req -> req.entity = MultipartEntityBuilder.create().addBinaryBody('json_file', json.getBytes('UTF-8'), ContentType.APPLICATION_JSON, 'json_file').build() @@ -57,6 +57,13 @@ class CoverallsTask extends DefaultTask { } } + private setProxy(HTTPBuilder http) { + def proxyInfo = ProxyInfoFactory.createFromEnvVar this.env + if (proxyInfo) { + http.setProxy(proxyInfo.httpsProxyHost, proxyInfo.httpsProxyPort, "https") + } + } + void saveJsonToFile(String json, String saveFilePath) { try { File reportFile = new File(saveFilePath) diff --git a/src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfo.groovy b/src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfo.groovy new file mode 100644 index 0000000..609c509 --- /dev/null +++ b/src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfo.groovy @@ -0,0 +1,28 @@ +package org.kt3k.gradle.plugin.coveralls.domain + +import groovy.transform.TupleConstructor + +@TupleConstructor +class ProxyInfo { + String httpsProxyHost + Integer httpsProxyPort + + boolean equals(o) { + if (this.is(o)) return true + if (getClass() != o.class) return false + + ProxyInfo proxyInfo = (ProxyInfo) o + + if (httpsProxyHost != proxyInfo.httpsProxyHost) return false + if (httpsProxyPort != proxyInfo.httpsProxyPort) return false + + return true + } + + int hashCode() { + int result + result = 31 * result + (httpsProxyHost != null ? httpsProxyHost.hashCode() : 0) + result = 31 * result + (httpsProxyPort != null ? httpsProxyPort.hashCode() : 0) + return result + } +} diff --git a/src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactory.groovy b/src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactory.groovy new file mode 100644 index 0000000..f2ce61b --- /dev/null +++ b/src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactory.groovy @@ -0,0 +1,25 @@ +package org.kt3k.gradle.plugin.coveralls.domain + +import org.gradle.api.logging.Logger +import org.gradle.api.logging.Logging + + +class ProxyInfoFactory { + + public static ProxyInfo createFromEnvVar(Map env) { + Logger logger = Logging.getLogger('coveralls-logger') + if (httpsProxySet(env)) { + def host = env.get('https.proxyHost') + def port = env.getOrDefault('https.proxyPort', "443").toInteger() + logger.info 'Using HTTPS proxy $host:$port' + return new ProxyInfo( + httpsProxyHost: host, + httpsProxyPort: port + ) + } + } + + private static boolean httpsProxySet(Map env) { + env.get('https.proxyHost') != null + } +} diff --git a/src/test/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactoryTest.groovy b/src/test/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactoryTest.groovy new file mode 100644 index 0000000..41f6a9a --- /dev/null +++ b/src/test/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactoryTest.groovy @@ -0,0 +1,38 @@ +package org.kt3k.gradle.plugin.coveralls.domain + +import org.junit.Test +import static org.junit.Assert.* + +public class ProxyInfoFactoryTest { + + @Test + void testCreateFromEnvVarHostAndPort() { + ProxyInfo proxyInfo = ProxyInfoFactory + .createFromEnvVar 'https.proxyHost': 'some host', + 'https.proxyPort':'8080' + assertEquals 'some host', proxyInfo.httpsProxyHost + assertEquals 8080, proxyInfo.httpsProxyPort + } + + @Test + void testCreateFromEnvVarHostAndDefaultPort() { + ProxyInfo proxyInfo = ProxyInfoFactory + .createFromEnvVar 'https.proxyHost': 'some host' + assertEquals 'some host', proxyInfo.httpsProxyHost + assertEquals 443, proxyInfo.httpsProxyPort + } + + @Test + void testCreateFromEnvVarNoHost() { + ProxyInfo proxyInfo = ProxyInfoFactory + .createFromEnvVar [:] + assert proxyInfo == null + } + + @Test + void testCreateFromEnvVarOnlyPort() { + ProxyInfo proxyInfo = ProxyInfoFactory + .createFromEnvVar 'https.proxyPort': '8080' + assert proxyInfo == null + } +} \ No newline at end of file From a872f0e3e987511da1ee829b350d96c10b346fce Mon Sep 17 00:00:00 2001 From: "aleksandr.afanasiev" Date: Wed, 9 Nov 2016 02:27:15 +0300 Subject: [PATCH 2/4] syntax fix --- .../coveralls/domain/ProxyInfoFactoryTest.groovy | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactoryTest.groovy b/src/test/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactoryTest.groovy index 41f6a9a..3f4d751 100644 --- a/src/test/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactoryTest.groovy +++ b/src/test/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactoryTest.groovy @@ -1,15 +1,16 @@ package org.kt3k.gradle.plugin.coveralls.domain import org.junit.Test -import static org.junit.Assert.* + +import static org.junit.Assert.assertEquals public class ProxyInfoFactoryTest { @Test void testCreateFromEnvVarHostAndPort() { ProxyInfo proxyInfo = ProxyInfoFactory - .createFromEnvVar 'https.proxyHost': 'some host', - 'https.proxyPort':'8080' + .createFromEnvVar('https.proxyHost': 'some host', + 'https.proxyPort': '8080') assertEquals 'some host', proxyInfo.httpsProxyHost assertEquals 8080, proxyInfo.httpsProxyPort } @@ -17,7 +18,7 @@ public class ProxyInfoFactoryTest { @Test void testCreateFromEnvVarHostAndDefaultPort() { ProxyInfo proxyInfo = ProxyInfoFactory - .createFromEnvVar 'https.proxyHost': 'some host' + .createFromEnvVar('https.proxyHost': 'some host') assertEquals 'some host', proxyInfo.httpsProxyHost assertEquals 443, proxyInfo.httpsProxyPort } @@ -32,7 +33,7 @@ public class ProxyInfoFactoryTest { @Test void testCreateFromEnvVarOnlyPort() { ProxyInfo proxyInfo = ProxyInfoFactory - .createFromEnvVar 'https.proxyPort': '8080' + .createFromEnvVar('https.proxyPort': '8080') assert proxyInfo == null } } \ No newline at end of file From 372a9d70edc492d824802ac84c7c4962be35719a Mon Sep 17 00:00:00 2001 From: "aleksandr.afanasiev" Date: Wed, 9 Nov 2016 11:24:18 +0300 Subject: [PATCH 3/4] backwards compatibility with java 1.7 --- .../kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactory.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactory.groovy b/src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactory.groovy index f2ce61b..e43df43 100644 --- a/src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactory.groovy +++ b/src/main/groovy/org/kt3k/gradle/plugin/coveralls/domain/ProxyInfoFactory.groovy @@ -10,7 +10,7 @@ class ProxyInfoFactory { Logger logger = Logging.getLogger('coveralls-logger') if (httpsProxySet(env)) { def host = env.get('https.proxyHost') - def port = env.getOrDefault('https.proxyPort', "443").toInteger() + def port = env.get('https.proxyPort', "443").toInteger() logger.info 'Using HTTPS proxy $host:$port' return new ProxyInfo( httpsProxyHost: host, From df9fce31bab1da8aba08d0b2323600b93b60b7f2 Mon Sep 17 00:00:00 2001 From: "aleksandr.afanasiev" Date: Wed, 9 Nov 2016 18:41:54 +0300 Subject: [PATCH 4/4] updates README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 32a5598..46623dd 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,12 @@ If you need to customize something or support a different CI service, you can co If you have `COVERALLS_REPO_TOKEN` set and you're using Travis-CI not Travis-Pro, you need to set `CI_NAME=travis-ci`. +### HTTPS proxy settings +You can set https proxy if needed. +Environment variables to configure: +- `https.proxyHost` +- `https.proxyPort` (default value is **443**) + ## Examples - https://github.com/strawjs/straw-android