Skip to content

Commit bd6884a

Browse files
authored
Merge pull request #164 from markslater/allow-insecure-protocol
Allow insecure protocol
2 parents e4b9b15 + d2e6052 commit bd6884a

9 files changed

Lines changed: 88 additions & 2 deletions

File tree

docs/usage.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ node {
222222
// Or set to null if you want to add the repository on your own.
223223
distBaseUrl = "https://nodejs.org/dist"
224224
225+
// Specifies whether it is acceptable to communicate with the Node.js repository over an insecure HTTP connection.
226+
// Only used if download is true
227+
// Change it to true if you use a mirror that uses HTTP rather than HTTPS
228+
// Or set to null if you want to use Gradle's default behaviour.
229+
allowInsecureProtocol = null
230+
225231
// The npm command executed by the npmInstall task
226232
// By default it is install but it can be changed to ci
227233
npmInstallCommand = "install"

src/main/kotlin/com/github/gradle/node/NodeExtension.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ open class NodeExtension(project: Project) {
5959
*/
6060
val distBaseUrl = project.objects.property<String>()
6161

62+
/**
63+
* Specifies whether it is acceptable to communicate with the Node.js repository over an insecure HTTP connection.
64+
* Only used if download is true
65+
* Change it to true if you use a mirror that uses HTTP rather than HTTPS
66+
* Or set to null if you want to use Gradle's default behaviour.
67+
*/
68+
val allowInsecureProtocol = project.objects.property<Boolean>()
69+
6270
val npmCommand = project.objects.property<String>().convention("npm")
6371
val npxCommand = project.objects.property<String>().convention("npx")
6472
val yarnCommand = project.objects.property<String>().convention("yarn")

src/main/kotlin/com/github/gradle/node/NodePlugin.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.gradle.api.Project
1616
import org.gradle.kotlin.dsl.create
1717
import org.gradle.kotlin.dsl.named
1818
import org.gradle.kotlin.dsl.register
19+
import org.gradle.util.GradleVersion
1920
import java.io.File
2021

2122
class NodePlugin : Plugin<Project> {
@@ -30,7 +31,7 @@ class NodePlugin : Plugin<Project> {
3031
addYarnRule()
3132
project.afterEvaluate {
3233
if (nodeExtension.download.get()) {
33-
nodeExtension.distBaseUrl.orNull?.let { addRepository(it) }
34+
nodeExtension.distBaseUrl.orNull?.let { addRepository(it, nodeExtension.allowInsecureProtocol.orNull) }
3435
configureNodeSetupTask(nodeExtension)
3536
}
3637
}
@@ -86,7 +87,7 @@ class NodePlugin : Plugin<Project> {
8687
}
8788
}
8889

89-
private fun addRepository(distUrl: String) {
90+
private fun addRepository(distUrl: String, allowInsecureProtocol: Boolean?) {
9091
project.repositories.ivy {
9192
name = "Node.js"
9293
setUrl(distUrl)
@@ -99,6 +100,9 @@ class NodePlugin : Plugin<Project> {
99100
content {
100101
includeModule("org.nodejs", "node")
101102
}
103+
if (GradleVersion.current() >= GradleVersion.version("6.0")) {
104+
allowInsecureProtocol?.let { isAllowInsecureProtocol = it }
105+
}
102106
}
103107
}
104108

src/test/groovy/com/github/gradle/node/NodeExtensionTest.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class NodeExtensionTest extends AbstractProjectTest {
1515
nodeExtension.npmCommand.get() == 'npm'
1616
nodeExtension.npxCommand.get() == 'npx'
1717
nodeExtension.distBaseUrl.get() == 'https://nodejs.org/dist'
18+
nodeExtension.allowInsecureProtocol.orNull == null
1819
nodeExtension.workDir.get() != null
1920
nodeExtension.nodeProjectDir.get() != null
2021
nodeExtension.version.get() == DEFAULT_NODE_VERSION

src/test/groovy/com/github/gradle/node/task/NodeTask_integTest.groovy

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,31 @@ class NodeTask_integTest extends AbstractIntegTest {
267267
result.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
268268
result.task(":hello").outcome == TaskOutcome.SUCCESS
269269
}
270+
271+
def 'make sure build works with allowInsecureProtocol false using a custom repository'() {
272+
given:
273+
Assume.assumeFalse(gradleVersion < GradleVersion.version("6.8"))
274+
copyResources("fixtures/node-disallow-insecure-protocol")
275+
276+
when:
277+
def result = build("hello")
278+
279+
then:
280+
result.task(":nodeSetup").outcome == TaskOutcome.SUCCESS
281+
result.task(":hello").outcome == TaskOutcome.SUCCESS
282+
}
283+
284+
def 'make sure build works with allowInsecureProtocol true using a custom repository'() {
285+
given:
286+
Assume.assumeFalse(gradleVersion < GradleVersion.version("6.8"))
287+
copyResources("fixtures/node-allow-insecure-protocol")
288+
289+
when:
290+
def result = build("hello")
291+
292+
then:
293+
result.task(":nodeSetup").outcome == TaskOutcome.SUCCESS
294+
result.task(":hello").outcome == TaskOutcome.SUCCESS
295+
}
296+
270297
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
plugins {
2+
id "com.github.node-gradle.node"
3+
}
4+
5+
node {
6+
version = "12.13.0"
7+
distBaseUrl = "http://nodejs.org/dist/"
8+
download = true
9+
allowInsecureProtocol = true
10+
workDir = file("build/node")
11+
}
12+
13+
task hello(type: NodeTask) {
14+
script = file("simple.js")
15+
args = []
16+
outputs.upToDateWhen {
17+
true
18+
}
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Hello World");
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
plugins {
2+
id "com.github.node-gradle.node"
3+
}
4+
5+
node {
6+
version = "12.13.0"
7+
distBaseUrl = "https://nodejs.org/dist/"
8+
download = true
9+
allowInsecureProtocol = false
10+
workDir = file("build/node")
11+
}
12+
13+
task hello(type: NodeTask) {
14+
script = file("simple.js")
15+
args = []
16+
outputs.upToDateWhen {
17+
true
18+
}
19+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Hello World");

0 commit comments

Comments
 (0)