diff --git a/docs/usage.md b/docs/usage.md index e6937d3a..1427bba6 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -244,7 +244,7 @@ node { // according the proxy configuration defined for Gradle // Disable this option if you want to configure the proxy for npm or yarn on your own // (in the .npmrc file for instance) - useGradleProxySettings = ProxySetting.SMART + nodeProxySettings = ProxySettings.SMART } ``` @@ -281,6 +281,6 @@ Note that: * For `npm` and `yarn`, it will only work for network requests done directly by the tool (for instance downloading a dependency). This will not work if you run a Node.js script for instance via `npm run`. * `npm` and `yarn` support host exclusion (`NO_PROXY`) variable but they do not support host name and port exclusion. In the case some host names and ports are defined in the proxy exclusion, the port will be removed. The exclusion will apply to both HTTP and HTTPS protocols. -To disable proxy configuration, set `useGradleProxySettings` to `ProxySetting.OFF` in the `node` extension. In this case, the plugin will do nothing regarding the proxy configuration and you may want to configure it manually, for instance using the `.npmrc` file as explained [here](https://www.devtech101.com/2016/07/21/how-to-set-npm-proxy-settings-in-npmrc/) for `npm`. +To disable proxy configuration, set `nodeProxySettings` to `ProxySettings.OFF` in the `node` extension. In this case, the plugin will do nothing regarding the proxy configuration and you may want to configure it manually, for instance using the `.npmrc` file as explained [here](https://www.devtech101.com/2016/07/21/how-to-set-npm-proxy-settings-in-npmrc/) for `npm`. -To force the proxy configuration to be done even if one of the proxy environment variables is already set (i.e. override the existing proxy configuration), set `useGradleProxySettings` to `ProxySetting.FORCE` in the `node` extension. +To force the proxy configuration to be done even if one of the proxy environment variables is already set (i.e. override the existing proxy configuration), set `nodeProxySettings` to `ProxySettings.FORCE` in the `node` extension. diff --git a/src/main/kotlin/com/github/gradle/node/NodeExtension.kt b/src/main/kotlin/com/github/gradle/node/NodeExtension.kt index ef92a05b..be766411 100644 --- a/src/main/kotlin/com/github/gradle/node/NodeExtension.kt +++ b/src/main/kotlin/com/github/gradle/node/NodeExtension.kt @@ -1,6 +1,6 @@ package com.github.gradle.node -import com.github.gradle.node.npm.proxy.ProxySetting +import com.github.gradle.node.npm.proxy.ProxySettings import org.gradle.api.Project import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.getByType @@ -85,7 +85,7 @@ open class NodeExtension(project: Project) { * (in the .npmrc file for instance) * */ - val useGradleProxySettings = project.objects.property().convention(ProxySetting.SMART) + val nodeProxySettings = project.objects.property().convention(ProxySettings.SMART) @Suppress("unused") @Deprecated("Deprecated in version 3.0, please use nodeProjectDir now") @@ -95,10 +95,10 @@ open class NodeExtension(project: Project) { distBaseUrl.set("https://nodejs.org/dist") } - @Deprecated("useGradleProxySettings is now an enum", - replaceWith = ReplaceWith("useGradleProxySettings.set(i)")) + @Deprecated("useGradleProxySettings has been replaced with nodeProxySettings", + replaceWith = ReplaceWith("nodeProxySettings.set(i)")) fun setUseGradleProxySettings(value: Boolean) { - useGradleProxySettings.set(if (value) ProxySetting.SMART else ProxySetting.OFF) + nodeProxySettings.set(if (value) ProxySettings.SMART else ProxySettings.OFF) } companion object { diff --git a/src/main/kotlin/com/github/gradle/node/NodePlugin.kt b/src/main/kotlin/com/github/gradle/node/NodePlugin.kt index aa78f871..b5c86161 100644 --- a/src/main/kotlin/com/github/gradle/node/NodePlugin.kt +++ b/src/main/kotlin/com/github/gradle/node/NodePlugin.kt @@ -1,6 +1,6 @@ package com.github.gradle.node -import com.github.gradle.node.npm.proxy.ProxySetting +import com.github.gradle.node.npm.proxy.ProxySettings import com.github.gradle.node.npm.task.NpmInstallTask import com.github.gradle.node.npm.task.NpmSetupTask import com.github.gradle.node.npm.task.NpmTask @@ -40,7 +40,7 @@ class NodePlugin : Plugin { addGlobalType() addGlobalType() addGlobalType() - addGlobalType() + addGlobalType() } private inline fun addGlobalType() { diff --git a/src/main/kotlin/com/github/gradle/node/npm/exec/NpmExecRunner.kt b/src/main/kotlin/com/github/gradle/node/npm/exec/NpmExecRunner.kt index 76d814de..cd482b74 100644 --- a/src/main/kotlin/com/github/gradle/node/npm/exec/NpmExecRunner.kt +++ b/src/main/kotlin/com/github/gradle/node/npm/exec/NpmExecRunner.kt @@ -29,7 +29,7 @@ internal abstract class NpmExecRunner { private fun addProxyEnvironmentVariables(nodeExtension: NodeExtension, nodeExecConfiguration: NodeExecConfiguration): NodeExecConfiguration { - if (NpmProxy.shouldConfigureProxy(System.getenv(), nodeExtension.useGradleProxySettings.get())) { + if (NpmProxy.shouldConfigureProxy(System.getenv(), nodeExtension.nodeProxySettings.get())) { val npmProxyEnvironmentVariables = computeNpmProxyEnvironmentVariables() if (npmProxyEnvironmentVariables.isNotEmpty()) { val environmentVariables = diff --git a/src/main/kotlin/com/github/gradle/node/npm/proxy/NpmProxy.kt b/src/main/kotlin/com/github/gradle/node/npm/proxy/NpmProxy.kt index be07c6c3..46c13b00 100644 --- a/src/main/kotlin/com/github/gradle/node/npm/proxy/NpmProxy.kt +++ b/src/main/kotlin/com/github/gradle/node/npm/proxy/NpmProxy.kt @@ -28,10 +28,10 @@ internal class NpmProxy { return proxyEnvironmentVariables.toMap() } - fun shouldConfigureProxy(env: Map, settings: ProxySetting): Boolean { - if (settings == ProxySetting.FORCED) { + fun shouldConfigureProxy(env: Map, settings: ProxySettings): Boolean { + if (settings == ProxySettings.FORCED) { return true - } else if (settings == ProxySetting.SMART) { + } else if (settings == ProxySettings.SMART) { return !hasProxyConfiguration(env) } diff --git a/src/main/kotlin/com/github/gradle/node/npm/proxy/ProxySetting.kt b/src/main/kotlin/com/github/gradle/node/npm/proxy/ProxySettings.kt similarity index 94% rename from src/main/kotlin/com/github/gradle/node/npm/proxy/ProxySetting.kt rename to src/main/kotlin/com/github/gradle/node/npm/proxy/ProxySettings.kt index 0c554b10..1ea10614 100644 --- a/src/main/kotlin/com/github/gradle/node/npm/proxy/ProxySetting.kt +++ b/src/main/kotlin/com/github/gradle/node/npm/proxy/ProxySettings.kt @@ -3,7 +3,7 @@ package com.github.gradle.node.npm.proxy /** * @since 3.0 */ -enum class ProxySetting { +enum class ProxySettings { /** * The default, this will set the proxy settings only if there's no configuration * present in the environment variables already. diff --git a/src/main/kotlin/com/github/gradle/node/yarn/exec/YarnExecRunner.kt b/src/main/kotlin/com/github/gradle/node/yarn/exec/YarnExecRunner.kt index 30710d8a..533cac87 100644 --- a/src/main/kotlin/com/github/gradle/node/yarn/exec/YarnExecRunner.kt +++ b/src/main/kotlin/com/github/gradle/node/yarn/exec/YarnExecRunner.kt @@ -36,7 +36,7 @@ internal abstract class YarnExecRunner { private fun addNpmProxyEnvironment(nodeExtension: NodeExtension, nodeExecConfiguration: NodeExecConfiguration): Map { - if (NpmProxy.shouldConfigureProxy(System.getenv(), nodeExtension.useGradleProxySettings.get())) { + if (NpmProxy.shouldConfigureProxy(System.getenv(), nodeExtension.nodeProxySettings.get())) { val npmProxyEnvironmentVariables = NpmProxy.computeNpmProxyEnvironmentVariables() if (npmProxyEnvironmentVariables.isNotEmpty()) { return nodeExecConfiguration.environment.plus(npmProxyEnvironmentVariables) diff --git a/src/test/groovy/com/github/gradle/node/npm/task/NpmInstallTaskTest.groovy b/src/test/groovy/com/github/gradle/node/npm/task/NpmInstallTaskTest.groovy index f7473483..dbb3f210 100644 --- a/src/test/groovy/com/github/gradle/node/npm/task/NpmInstallTaskTest.groovy +++ b/src/test/groovy/com/github/gradle/node/npm/task/NpmInstallTaskTest.groovy @@ -1,7 +1,7 @@ package com.github.gradle.node.npm.task import com.github.gradle.node.npm.proxy.GradleProxyHelper -import com.github.gradle.node.npm.proxy.ProxySetting +import com.github.gradle.node.npm.proxy.ProxySettings import com.github.gradle.node.task.AbstractTaskTest class NpmInstallTaskTest extends AbstractTaskTest { @@ -33,7 +33,7 @@ class NpmInstallTaskTest extends AbstractTaskTest { props.setProperty('os.name', 'Linux') GradleProxyHelper.setHttpsProxyHost("my-super-proxy.net") GradleProxyHelper.setHttpsProxyPort(11235) - nodeExtension.useGradleProxySettings.set(ProxySetting.OFF) + nodeExtension.nodeProxySettings.set(ProxySettings.OFF) def task = project.tasks.getByName("npmInstall") mockProjectApiHelperExec(task) diff --git a/src/test/groovy/com/github/gradle/node/npm/task/NpmTaskTest.groovy b/src/test/groovy/com/github/gradle/node/npm/task/NpmTaskTest.groovy index b8a3492c..3ef860e8 100644 --- a/src/test/groovy/com/github/gradle/node/npm/task/NpmTaskTest.groovy +++ b/src/test/groovy/com/github/gradle/node/npm/task/NpmTaskTest.groovy @@ -1,7 +1,7 @@ package com.github.gradle.node.npm.task import com.github.gradle.node.npm.proxy.GradleProxyHelper -import com.github.gradle.node.npm.proxy.ProxySetting +import com.github.gradle.node.npm.proxy.ProxySettings import com.github.gradle.node.task.AbstractTaskTest import static com.github.gradle.node.NodeExtension.DEFAULT_NODE_VERSION @@ -141,7 +141,7 @@ class NpmTaskTest extends AbstractTaskTest { props.setProperty('os.name', 'Linux') GradleProxyHelper.setHttpsProxyHost("my-super-proxy.net") GradleProxyHelper.setHttpsProxyPort(11235) - nodeExtension.useGradleProxySettings.set(ProxySetting.OFF) + nodeExtension.nodeProxySettings.set(ProxySettings.OFF) def task = project.tasks.create('simple', NpmTask) mockProjectApiHelperExec(task) diff --git a/src/test/groovy/com/github/gradle/node/yarn/task/YarnSetupTaskTest.groovy b/src/test/groovy/com/github/gradle/node/yarn/task/YarnSetupTaskTest.groovy index 2f0e2559..b4ec39ca 100644 --- a/src/test/groovy/com/github/gradle/node/yarn/task/YarnSetupTaskTest.groovy +++ b/src/test/groovy/com/github/gradle/node/yarn/task/YarnSetupTaskTest.groovy @@ -1,7 +1,7 @@ package com.github.gradle.node.yarn.task import com.github.gradle.node.npm.proxy.GradleProxyHelper -import com.github.gradle.node.npm.proxy.ProxySetting +import com.github.gradle.node.npm.proxy.ProxySettings import com.github.gradle.node.task.AbstractTaskTest class YarnSetupTaskTest extends AbstractTaskTest { @@ -35,7 +35,7 @@ class YarnSetupTaskTest extends AbstractTaskTest { given: GradleProxyHelper.setHttpProxyHost("my-proxy") GradleProxyHelper.setHttpProxyPort(80) - nodeExtension.useGradleProxySettings.set(ProxySetting.OFF) + nodeExtension.nodeProxySettings.set(ProxySettings.OFF) def task = project.tasks.create('simple', YarnSetupTask) mockProjectApiHelperExec(task) diff --git a/src/test/groovy/com/github/gradle/node/yarn/task/YarnTaskTest.groovy b/src/test/groovy/com/github/gradle/node/yarn/task/YarnTaskTest.groovy index 1d53c23e..76e37bda 100644 --- a/src/test/groovy/com/github/gradle/node/yarn/task/YarnTaskTest.groovy +++ b/src/test/groovy/com/github/gradle/node/yarn/task/YarnTaskTest.groovy @@ -1,9 +1,8 @@ package com.github.gradle.node.yarn.task import com.github.gradle.node.npm.proxy.GradleProxyHelper -import com.github.gradle.node.npm.proxy.ProxySetting +import com.github.gradle.node.npm.proxy.ProxySettings import com.github.gradle.node.task.AbstractTaskTest -import org.gradle.process.ExecSpec class YarnTaskTest extends AbstractTaskTest { def cleanup() { @@ -87,7 +86,7 @@ class YarnTaskTest extends AbstractTaskTest { GradleProxyHelper.setHttpsProxyPort(443) GradleProxyHelper.setHttpsProxyUser("me") GradleProxyHelper.setHttpsProxyPassword("password") - nodeExtension.useGradleProxySettings.set(ProxySetting.OFF) + nodeExtension.nodeProxySettings.set(ProxySettings.OFF) def task = project.tasks.create('simple', YarnTask) mockProjectApiHelperExec(task) diff --git a/src/test/kotlin/com/github/gradle/node/npm/proxy/NpmProxyTest.kt b/src/test/kotlin/com/github/gradle/node/npm/proxy/NpmProxyTest.kt index b1b237b0..62820632 100644 --- a/src/test/kotlin/com/github/gradle/node/npm/proxy/NpmProxyTest.kt +++ b/src/test/kotlin/com/github/gradle/node/npm/proxy/NpmProxyTest.kt @@ -13,14 +13,14 @@ class NpmProxyTest { @Test internal fun verifyProxyConfigurationSettings() { - assertThat(NpmProxy.shouldConfigureProxy(emptyMap(), ProxySetting.FORCED)).isTrue - assertThat(NpmProxy.shouldConfigureProxy(emptyMap(), ProxySetting.OFF)).isFalse + assertThat(NpmProxy.shouldConfigureProxy(emptyMap(), ProxySettings.FORCED)).isTrue + assertThat(NpmProxy.shouldConfigureProxy(emptyMap(), ProxySettings.OFF)).isFalse // No proxy settings present, should be set - assertThat(NpmProxy.shouldConfigureProxy(emptyMap(), ProxySetting.SMART)).isTrue + assertThat(NpmProxy.shouldConfigureProxy(emptyMap(), ProxySettings.SMART)).isTrue // Proxy settings present, SMART shouldn't configure. - assertThat(NpmProxy.shouldConfigureProxy(mapOf(("HTTP_PROXY" to "")), ProxySetting.SMART)).isFalse + assertThat(NpmProxy.shouldConfigureProxy(mapOf(("HTTP_PROXY" to "")), ProxySettings.SMART)).isFalse } @Test diff --git a/src/test/resources/fixtures/kotlin/build.gradle.kts b/src/test/resources/fixtures/kotlin/build.gradle.kts index 21041cff..f47f8827 100644 --- a/src/test/resources/fixtures/kotlin/build.gradle.kts +++ b/src/test/resources/fixtures/kotlin/build.gradle.kts @@ -1,4 +1,4 @@ -import com.github.gradle.node.npm.proxy.ProxySetting +import com.github.gradle.node.npm.proxy.ProxySettings import com.github.gradle.node.npm.task.NpmTask import com.github.gradle.node.npm.task.NpxTask import com.github.gradle.node.task.NodeTask @@ -26,7 +26,7 @@ node { npmWorkDir.set(file("${project.projectDir}/.cache/npm")) yarnWorkDir.set(file("${project.projectDir}/.cache/yarn")) nodeProjectDir.set(file("${project.projectDir}")) - useGradleProxySettings.set(ProxySetting.SMART) + nodeProxySettings.set(ProxySettings.SMART) } tasks.npmInstall {