Skip to content

Commit

Permalink
Rename useGradleProxySettings to nodeProxySettings
Browse files Browse the repository at this point in the history
  • Loading branch information
deepy committed Jan 19, 2021
1 parent 293829a commit 9fbe6e1
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 31 deletions.
6 changes: 3 additions & 3 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand Down Expand Up @@ -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.
10 changes: 5 additions & 5 deletions src/main/kotlin/com/github/gradle/node/NodeExtension.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -85,7 +85,7 @@ open class NodeExtension(project: Project) {
* (in the .npmrc file for instance)
*
*/
val useGradleProxySettings = project.objects.property<ProxySetting>().convention(ProxySetting.SMART)
val nodeProxySettings = project.objects.property<ProxySettings>().convention(ProxySettings.SMART)

@Suppress("unused")
@Deprecated("Deprecated in version 3.0, please use nodeProjectDir now")
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/github/gradle/node/NodePlugin.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -40,7 +40,7 @@ class NodePlugin : Plugin<Project> {
addGlobalType<NpmTask>()
addGlobalType<NpxTask>()
addGlobalType<YarnTask>()
addGlobalType<ProxySetting>()
addGlobalType<ProxySettings>()
}

private inline fun <reified T> addGlobalType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/github/gradle/node/npm/proxy/NpmProxy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ internal class NpmProxy {
return proxyEnvironmentVariables.toMap()
}

fun shouldConfigureProxy(env: Map<String, String>, settings: ProxySetting): Boolean {
if (settings == ProxySetting.FORCED) {
fun shouldConfigureProxy(env: Map<String, String>, settings: ProxySettings): Boolean {
if (settings == ProxySettings.FORCED) {
return true
} else if (settings == ProxySetting.SMART) {
} else if (settings == ProxySettings.SMART) {
return !hasProxyConfiguration(env)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal abstract class YarnExecRunner {

private fun addNpmProxyEnvironment(nodeExtension: NodeExtension,
nodeExecConfiguration: NodeExecConfiguration): Map<String, String> {
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/fixtures/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9fbe6e1

Please sign in to comment.