Skip to content

Commit 3ea8a87

Browse files
committed
Move platform computation to NodeExtension
This fixes #271 and starts a bunch of refactors, it also re-introduces support for Gradle 6, and deprecates the platform functionality of PlatformHelper (in it's current state)
1 parent 0073845 commit 3ea8a87

29 files changed

+343
-209
lines changed

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ jobs:
66
strategy:
77
matrix:
88
config:
9-
- {os: ubuntu-latest, params: "'-PtestedGradleVersion=7.5.1|8.1.1' pnpmTests" }
10-
- {os: ubuntu-latest, params: "'-PtestedGradleVersion=7.5.1|8.1.1' build" }
9+
- {os: ubuntu-latest, params: "'-PtestedGradleVersion=6.9.4|7.5.1|8.1.1' pnpmTests" }
10+
- {os: ubuntu-latest, params: "'-PtestedGradleVersion=6.9.4|7.5.1|8.1.1' build" }
1111
- {os: windows-latest, params: "build pnpmTests" }
1212
- {os: macos-latest, params: "build pnpmTests" }
1313
steps:

CHANGELOG.md

+22-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# Changelog
22

3-
## Version 4.x *(unreleased)*
3+
## Version 5.x *(unreleased)*
4+
5+
## Version 5.0.0 *(unreleased)*
6+
* Support configuration-cache on Gradle 8.1 [#271](https://github.com/node-gradle/gradle-node-plugin/issues/271)
7+
* Store node directories on NodeExtension
8+
* Deprecate parts of PlatformHelper that require executing commands during configuration
9+
* Re-introduce support for Gradle 6.6 and newer
410

511
## Version 4.0.0 *(2023-04-23)*
12+
* **This version is unfortunately broken, please upgrade directly to 5.0.0**
613
* Drop support for versions lower than Gradle 7.5.1
714
* Rename `package.json` extension to `packageJson` [#232](https://github.com/node-gradle/gradle-node-plugin/issues/232)
815
* Support configuration-cache on Gradle 8.1 [#271](https://github.com/node-gradle/gradle-node-plugin/issues/271)
@@ -39,7 +46,7 @@
3946
## Version 3.1.0 *(2021-05-07)*
4047
* Add support for Linux Power PC [#166](https://github.com/node-gradle/gradle-node-plugin/issues/166) (thanks [akatona84](https://github.com/akatona84) for the [pull request](https://github.com/node-gradle/gradle-node-plugin/issues/167))
4148
* Internal test suite now running against Gradle 7
42-
* Adds `yarn.lock` as an input to `NpmInstallTask` [#155](https://github.com/node-gradle/gradle-node-plugin/issues/155)
49+
* Adds `yarn.lock` as an input to `NpmInstallTask` [#155](https://github.com/node-gradle/gradle-node-plugin/issues/155)
4350

4451
## Version 3.0.1 *(2021-02-09)*
4552
* Fixes a bug with the task rule preventing it from being configured [#145](https://github.com/node-gradle/gradle-node-plugin/issues/145)
@@ -74,15 +81,15 @@ Here is what changed:
7481
* `com.moowork.gradle.node` (and all children) renamed to `com.github.gradle.node`
7582
* `com.moowork.gradle.node.npm` renamed to `com.github.gradle.node.npm.task`
7683
* `com.moowork.gradle.node.yarn` renamed to `com.github.gradle.node.yarn.task`
77-
* All the configuration properties (the `node` extension and all tasks) are now some
78-
[lazy properties](https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_properties) as recommended by
79-
Gradle. This makes this plugin fully compatible with lazy configuration (tasks will be configured only if they need to
84+
* All the configuration properties (the `node` extension and all tasks) are now some
85+
[lazy properties](https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_properties) as recommended by
86+
Gradle. This makes this plugin fully compatible with lazy configuration (tasks will be configured only if they need to
8087
run and configuration properties are read only at runtime if needed and not at configuration time).
8188
* Thanks to the Kotlin rewrite, some properties now have a stronger typing.
8289
* `nodeModulesDir` option was renamed to `nodeProjectDir` (name more explicit and less confusing)
83-
(issue [#99](https://github.com/node-gradle/gradle-node-plugin/issues/99)). The former name still works but is
90+
(issue [#99](https://github.com/node-gradle/gradle-node-plugin/issues/99)). The former name still works but is
8491
deprecated.
85-
* Change the syntax to configure `nodeModulesOutputFilter` on `npmInstall` and `yarn` tasks. It also affects Groovy DSL
92+
* Change the syntax to configure `nodeModulesOutputFilter` on `npmInstall` and `yarn` tasks. It also affects Groovy DSL
8693
users. Use now `nodeModulesOutputFilter { ... }` instead of `nodeModulesOutputFilter = { ... }`.
8794

8895
## Version 2.2.4 *(2020-05-18)*
@@ -91,7 +98,7 @@ users. Use now `nodeModulesOutputFilter { ... }` instead of `nodeModulesOutputFi
9198

9299
## Version 2.2.3 *(2020-02-28)*
93100

94-
The previous release (2.2.2) was released by error from the development branch which contains an entire Kotlin rewrite
101+
The previous release (2.2.2) was released by error from the development branch which contains an entire Kotlin rewrite
95102
of the plugin code and many backward compatibility breaks. This new version replaces the previous one and adds one fix.
96103
* Make npm and npx symlinks relative. PR #68
97104
* NpmSetupTask does not work when using separate http and https proxy settings #69
@@ -110,10 +117,10 @@ of the plugin code and many backward compatibility breaks. This new version repl
110117
* `NodeTask`'s `script` now has relative path sensitivity (issue [#41](https://github.com/node-gradle/gradle-node-plugin/issues/41))
111118
* No longer consider the working dir as an input for all tasks (issue [#40](https://github.com/node-gradle/gradle-node-plugin/issues/40))
112119
* Explicitly exclude the `execOverrides` option of tasks from the inputs (issue [#40](https://github.com/node-gradle/gradle-node-plugin/issues/40))
113-
* Add the ability to remove some files of the `node_modules` directory from the `NpmInstallTask` and `YarnInstallTask`
120+
* Add the ability to remove some files of the `node_modules` directory from the `NpmInstallTask` and `YarnInstallTask`
114121
outputs from the task output ; this is necessary when some tasks change some files of the `node_modules` directory ;
115122
the `NpmInstallTask` and `YarnInstallTask` are never up-to-date in this case
116-
(issue [#38](https://github.com/node-gradle/gradle-node-plugin/issues/38))
123+
(issue [#38](https://github.com/node-gradle/gradle-node-plugin/issues/38))
117124
* Deprecate the usage of `NodeTask` with a `script` which is a directory ; Node.js supports that and looks for an
118125
`index.js` file in the directory but this is not compliant with a correct input/output declaration (issue [#41](https://github.com/node-gradle/gradle-node-plugin/issues/41))
119126
* No longer use `Project.afterEvaluate` as a first step to support lazy tasks configuration (issue [#39](https://github.com/node-gradle/gradle-node-plugin/issues/39))
@@ -126,17 +133,17 @@ of the plugin code and many backward compatibility breaks. This new version repl
126133
* Improve the inputs declarations of the `YarnTask`
127134

128135
## Version 2.1.0 *(2019-09-19)*
129-
* Adds NpxTask for making use of https://www.npmjs.com/package/npx PR #32
130-
* Improved up-to-date checks PR #32
136+
* Adds NpxTask for making use of https://www.npmjs.com/package/npx PR #32
137+
* Improved up-to-date checks PR #32
131138
* Support ARM even if the JDK reports aarch64 #33
132-
* Setting distBaseUrl to null disables repository adding PR #25
139+
* Setting distBaseUrl to null disables repository adding PR #25
133140

134141
## Version 2.0.0 *(2019-07-29)*
135142
* Only support Gradle 5.x officially.
136143
* Drop support for grunt/gulp plugins.
137144

138145
## Version 1.5.1 *(2019-06-19)*
139-
* Fix inputs/outputs for NpmInstallTask/YarnInstallTask.
146+
* Fix inputs/outputs for NpmInstallTask/YarnInstallTask.
140147

141148
## Version 1.5.0 *(2019-06-19)*
142149
* Backport from srs: Added gradle build cache support for npm install (bjornmagnusson)
@@ -195,7 +202,7 @@ Version 0.14 *(2016-11-29)*
195202
Version 0.13 *(2016-06-27)*
196203
---------------------------
197204

198-
* Bumped gradle wrapper version to 2.14
205+
* Bumped gradle wrapper version to 2.14
199206
* Implement ARM compatibility _(madmas)_
200207
* Allow node modules to be used when calling npm_run _(jmcampanini)_
201208
* Updated plugin versions and test versions

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![License](https://img.shields.io/github/license/node-gradle/gradle-node-plugin.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
77
![Version](https://img.shields.io/badge/Version-4.0.0-orange.svg)
88

9-
This plugin enables you to use a lot of [Node.js](https://nodejs.org)-based technologies as part of your
9+
This plugin enables you to use a lot of [Node.js](https://nodejs.org)-based technologies as part of your
1010
build without having Node.js installed locally on your system. It integrates the following Node.js-based system
1111
with Gradle:
1212

@@ -18,14 +18,14 @@ with Gradle:
1818
The plugin is published in the [Gradle plugins portal](https://plugins.gradle.org/plugin/com.github.node-gradle.node)
1919
with the `com.github.node-gradle.node` identifier.
2020

21-
It supports Gradle 7.5.1+ and Node.js 10+, for Gradle 5.6.4 support use version 3.x
21+
It supports Gradle 6.6+ and Node.js 10+, for Gradle 5.6.4 support use version 3.x
2222

2323
## Documentation
2424

25-
⚠️ This is the documentation of the development version. See below in the releases history to read the
25+
⚠️ This is the documentation of the development version. See below in the releases history to read the
2626
documentation of the version you're using.
2727

28-
Here's how you get started using this plugin. If you do not find what you are looking for, please add an
28+
Here's how you get started using this plugin. If you do not find what you are looking for, please add an
2929
issue to [GitHub Issues](https://github.com/node-gradle/gradle-node-plugin/issues).
3030

3131
* [Installation](docs/installation.md)
@@ -88,7 +88,7 @@ To run the tests against all Gradle versions, use the following option (it is do
8888

8989
## Contributing
9090

91-
Contributions are always welcome! If you'd like to contribute (and we hope you do) please send
91+
Contributions are always welcome! If you'd like to contribute (and we hope you do) please send
9292
one of the existing contributors a nudge.
9393

9494
## <a name="support"></a> Support this project :heart:

build.gradle.kts

+4-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ repositories {
4343
}
4444

4545
dependencies {
46-
api("com.fasterxml.jackson.core:jackson-databind:2.13.2.2")
46+
implementation("com.fasterxml.jackson.core:jackson-databind:2.14.2")
4747
testImplementation(platform("org.junit:junit-bom:5.6.2"))
4848
testImplementation("org.junit.jupiter:junit-jupiter-api")
4949
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
@@ -76,7 +76,8 @@ tasks.withType(Test::class) {
7676
)
7777

7878
val processorsCount = Runtime.getRuntime().availableProcessors()
79-
maxParallelForks = if (processorsCount > 2) processorsCount.div(2) else processorsCount
79+
val safeMaxForks = if (processorsCount > 2) processorsCount.div(2) else processorsCount
80+
maxParallelForks = safeMaxForks
8081
testLogging {
8182
events = setOf(TestLogEvent.SKIPPED, TestLogEvent.FAILED)
8283
exceptionFormat = TestExceptionFormat.FULL
@@ -152,7 +153,7 @@ tasks.jacocoTestReport {
152153
tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
153154
dokkaSourceSets {
154155
named("main") {
155-
jdkVersion.set(8)
156+
jdkVersion.set(compatibilityVersion.majorVersion.toInt())
156157
}
157158
}
158159
}

buildSrc/src/main/groovy/com/github/gradle/buildlogic/GradleVersionData.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class GradleVersionData {
2525
.findAll { !it.rcFor || it.activeRc } // filter out inactive rcs
2626
.findAll { !it.milestoneFor } // filter out milestones
2727
.<String, VersionNumber, String>collectEntries { [(it.version): VersionNumber.parse(it.version as String)] }
28-
.findAll { it.value.major >= 5 } // only 5.6 and above
29-
.findAll { !(it.value.major == 5 && it.value.minor < 6) } // only 5.6 and above
28+
.findAll { it.value.major >= 6 } // only 6.9 and above
29+
.findAll { !(it.value.major == 6 && it.value.minor < 6.9) } // only 6.9 and above
3030
.inject([] as List<Map.Entry<String, VersionNumber>>) { releasesToTest, version -> // only test against latest patch versions
3131
if (!releasesToTest.any { it.value.major == version.value.major && it.value.minor == version.value.minor }) {
3232
releasesToTest + version

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
org.gradle.unsafe.configuration-cache=true
22
systemProp.gradle.enterprise.testretry.enabled=false
3-
systemProp.org.gradle.unsafe.kotlin.assignment=true
3+
systemProp.org.gradle.unsafe.kotlin.assignment=true

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.gradle.node
22

33
import com.github.gradle.node.npm.proxy.ProxySettings
4+
import com.github.gradle.node.util.Platform
45
import org.gradle.api.Project
56
import org.gradle.kotlin.dsl.create
67
import org.gradle.kotlin.dsl.getByType
@@ -147,6 +148,17 @@ open class NodeExtension(project: Project) {
147148
*/
148149
val enableTaskRules = project.objects.property<Boolean>().convention(true)
149150

151+
152+
/**
153+
* Computed path to nodejs directory
154+
*/
155+
val computedNodeDir = project.objects.directoryProperty()
156+
157+
/**
158+
* Operating system and architecture
159+
*/
160+
val computedPlatform = project.objects.property<Platform>()
161+
150162
init {
151163
distBaseUrl.set("https://nodejs.org/dist")
152164
}
@@ -180,7 +192,7 @@ open class NodeExtension(project: Project) {
180192

181193
@JvmStatic
182194
fun create(project: Project): NodeExtension {
183-
return project.extensions.create(NAME, project)
195+
return project.extensions.create<NodeExtension>(NAME, project, )
184196
}
185197
}
186198
}

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

+45-15
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,30 @@ import com.github.gradle.node.pnpm.task.PnpmSetupTask
1010
import com.github.gradle.node.pnpm.task.PnpmTask
1111
import com.github.gradle.node.task.NodeSetupTask
1212
import com.github.gradle.node.task.NodeTask
13-
import com.github.gradle.node.util.NodeVersionSource
13+
import com.github.gradle.node.util.*
14+
import com.github.gradle.node.variant.computeNodeArchiveDependency
15+
import com.github.gradle.node.variant.computeNodeDir
1416
import com.github.gradle.node.yarn.task.YarnInstallTask
1517
import com.github.gradle.node.yarn.task.YarnSetupTask
1618
import com.github.gradle.node.yarn.task.YarnTask
1719
import org.gradle.api.Plugin
1820
import org.gradle.api.Project
1921
import org.gradle.api.provider.Property
20-
import org.gradle.kotlin.dsl.create
21-
import org.gradle.kotlin.dsl.named
22-
import org.gradle.kotlin.dsl.of
23-
import org.gradle.kotlin.dsl.register
22+
import org.gradle.kotlin.dsl.*
2423
import org.gradle.util.GradleVersion
24+
import java.io.ByteArrayOutputStream
2525
import java.io.File
2626

2727
class NodePlugin : Plugin<Project> {
2828
private lateinit var project: Project
2929

3030
override fun apply(project: Project) {
31-
if (GradleVersion.current() < MINIMAL_SUPPORTED_GRADLE_VERSION) {
32-
project.logger.error("This version of the plugin requires $MINIMAL_SUPPORTED_GRADLE_VERSION or newer.")
33-
}
31+
// if (GradleVersion.current() < MINIMAL_SUPPORTED_GRADLE_VERSION) {
32+
// project.logger.error("This version of the plugin requires $MINIMAL_SUPPORTED_GRADLE_VERSION or newer.")
33+
// }
3434
this.project = project
3535
val nodeExtension = NodeExtension.create(project)
36+
configureNodeExtension(nodeExtension)
3637
project.extensions.create<PackageJsonExtension>(PackageJsonExtension.NAME, project)
3738
addGlobalTypes()
3839
addTasks()
@@ -47,6 +48,38 @@ class NodePlugin : Plugin<Project> {
4748
}
4849
}
4950

51+
private fun configureNodeExtension(extension: NodeExtension) {
52+
addPlatform(extension)
53+
extension.computedNodeDir.set(computeNodeDir(extension))
54+
extension.computedNodeDir.finalizeValueOnRead()
55+
}
56+
57+
private fun addPlatform(extension: NodeExtension) {
58+
val uname = {
59+
if (GradleVersion.current() >= GradleVersion.version("7.5")) {
60+
val cmd = project.providers.exec {
61+
this.executable = "uname"
62+
this.args = listOf("-m")
63+
}
64+
cmd.standardOutput.asText.get().trim()
65+
} else {
66+
val out = ByteArrayOutputStream()
67+
val cmd = project.exec {
68+
this.executable = "uname"
69+
this.args = listOf("-m")
70+
this.standardOutput = out
71+
}
72+
73+
cmd.assertNormalExitValue()
74+
out.toString().trim()
75+
}
76+
}
77+
val name = System.getProperty("os.name")
78+
val arch = System.getProperty("os.arch")
79+
val platform = parsePlatform(name, arch, uname)
80+
extension.computedPlatform.set(platform)
81+
}
82+
5083
private fun addGlobalTypes() {
5184
addGlobalType<NodeTask>()
5285
addGlobalType<NpmTask>()
@@ -133,12 +166,9 @@ class NodePlugin : Plugin<Project> {
133166
}
134167

135168
private fun configureNodeSetupTask(nodeExtension: NodeExtension) {
136-
val versionSource = project.providers.of(NodeVersionSource::class) {
137-
parameters.nodeVersion.set(nodeExtension.version)
138-
}
139-
project.tasks.named<NodeSetupTask>(NodeSetupTask.NAME) {
140-
val nodeArchiveDependencyProvider = versionSource.get()
141-
val archiveFileProvider = nodeArchiveDependencyProvider
169+
project.tasks.withType<NodeSetupTask>().configureEach {
170+
nodeDir.set(nodeExtension.computedNodeDir)
171+
val archiveFileProvider = computeNodeArchiveDependency(nodeExtension)
142172
.map { nodeArchiveDependency ->
143173
resolveNodeArchiveFile(nodeArchiveDependency)
144174
}
@@ -154,7 +184,7 @@ class NodePlugin : Plugin<Project> {
154184
}
155185

156186
companion object {
157-
val MINIMAL_SUPPORTED_GRADLE_VERSION: GradleVersion = GradleVersion.version("7.5.1")
187+
val MINIMAL_SUPPORTED_GRADLE_VERSION: GradleVersion = GradleVersion.version("6.6")
158188
const val NODE_GROUP = "Node"
159189
const val NPM_GROUP = "npm"
160190
const val PNPM_GROUP = "pnpm"

src/main/kotlin/com/github/gradle/node/exec/NodeExecRunner.kt

+13-6
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,31 @@ import com.github.gradle.node.NodeExtension
44
import com.github.gradle.node.util.ProjectApiHelper
55
import com.github.gradle.node.util.zip
66
import com.github.gradle.node.variant.VariantComputer
7+
import com.github.gradle.node.variant.computeNodeExec
78
import org.gradle.api.file.Directory
89
import org.gradle.api.provider.Provider
910
import org.gradle.process.ExecResult
1011

1112
/**
1213
* This function is responsible for setting up the configuration used when running the tasks.
1314
*/
14-
fun buildExecConfiguration(nodeExtension: NodeExtension, nodeExecConfiguration: NodeExecConfiguration, variantComputer: VariantComputer):
15-
Provider<ExecConfiguration> {
16-
val nodeDirProvider = variantComputer.computeNodeDir(nodeExtension)
15+
fun buildExecConfiguration(
16+
nodeExtension: NodeExtension,
17+
nodeExecConfiguration: NodeExecConfiguration,
18+
variantComputer: VariantComputer
19+
):
20+
Provider<ExecConfiguration> {
21+
val nodeDirProvider = nodeExtension.computedNodeDir
1722
val nodeBinDirProvider = variantComputer.computeNodeBinDir(nodeDirProvider)
18-
val executableProvider = variantComputer.computeNodeExec(nodeExtension, nodeBinDirProvider)
23+
val executableProvider = computeNodeExec(nodeExtension, nodeBinDirProvider)
1924
val additionalBinPathProvider = computeAdditionalBinPath(nodeExtension, nodeBinDirProvider)
2025
return zip(executableProvider, additionalBinPathProvider)
2126
.map { (executable, additionalBinPath) ->
22-
ExecConfiguration(executable, nodeExecConfiguration.command, additionalBinPath,
27+
ExecConfiguration(
28+
executable, nodeExecConfiguration.command, additionalBinPath,
2329
nodeExecConfiguration.environment, nodeExecConfiguration.workingDir,
24-
nodeExecConfiguration.ignoreExitValue, nodeExecConfiguration.execOverrides)
30+
nodeExecConfiguration.ignoreExitValue, nodeExecConfiguration.execOverrides
31+
)
2532
}
2633
}
2734

0 commit comments

Comments
 (0)