Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 8.1 configuration-cache support #272

Merged
merged 7 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ jobs:
strategy:
matrix:
config:
- {os: ubuntu-latest, params: "'-PtestedGradleVersion=6.6|7.0|7.5.1' pnpmTests" }
- {os: ubuntu-latest, params: "'-PtestedGradleVersion=6.6|7.0|7.5.1' build" }
- {os: ubuntu-latest, params: "'-PtestedGradleVersion=7.5.1|8.1.1' pnpmTests" }
- {os: ubuntu-latest, params: "'-PtestedGradleVersion=7.5.1|8.1.1' build" }
- {os: windows-latest, params: "build pnpmTests" }
- {os: macos-latest, params: "build pnpmTests" }
steps:
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## Version 3.x *(unreleased)*
## Version 4.x *(unreleased)*

## Version 4.0.0 *(unreleased)*
* Drop support for versions lower than Gradle 7.5.1
* Rename `package.json` extension to `packageJson` [#232](https://github.com/node-gradle/gradle-node-plugin/issues/232)

## Version 3.6.0 *(2023-04-20)*
* Allow task rules to be disabled [#116](https://github.com/node-gradle/gradle-node-plugin/issues/116)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ with Gradle:
The plugin is published in the [Gradle plugins portal](https://plugins.gradle.org/plugin/com.github.node-gradle.node)
with the `com.github.node-gradle.node` identifier.

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

## Documentation

Expand Down
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ tasks.compileKotlin {
kotlinOptions {
apiVersion = "1.3"
freeCompilerArgs = listOf("-Xno-optimized-callable-references")
jvmTarget = compatibilityVersion.toString()
}
}

Expand Down Expand Up @@ -138,13 +139,13 @@ tasks.register<Test>("testGradleNightlies") {

tasks.register("runParameterTest", JavaExec::class.java) {
classpath = sourceSets["main"].runtimeClasspath
main = "com.github.gradle.node.util.PlatformHelperKt"
mainClass.set("com.github.gradle.node.util.PlatformHelperKt")
}

tasks.jacocoTestReport {
reports {
xml.isEnabled = true
html.isEnabled = true
xml.required.set(true)
html.required.set(true)
}
}

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.gradle.unsafe.configuration-cache=true
systemProp.gradle.enterprise.testretry.enabled=false
systemProp.gradle.enterprise.testretry.enabled=false
systemProp.org.gradle.unsafe.kotlin.assignment=true
11 changes: 10 additions & 1 deletion src/main/kotlin/com/github/gradle/node/NodePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.github.gradle.node.pnpm.task.PnpmSetupTask
import com.github.gradle.node.pnpm.task.PnpmTask
import com.github.gradle.node.task.NodeSetupTask
import com.github.gradle.node.task.NodeTask
import com.github.gradle.node.util.NodeVersionSource
import com.github.gradle.node.yarn.task.YarnInstallTask
import com.github.gradle.node.yarn.task.YarnSetupTask
import com.github.gradle.node.yarn.task.YarnTask
Expand All @@ -18,6 +19,7 @@ import org.gradle.api.Project
import org.gradle.api.provider.Property
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.of
import org.gradle.kotlin.dsl.register
import org.gradle.util.GradleVersion
import java.io.File
Expand All @@ -26,6 +28,9 @@ class NodePlugin : Plugin<Project> {
private lateinit var project: Project

override fun apply(project: Project) {
if (GradleVersion.current() < MINIMAL_SUPPORTED_GRADLE_VERSION) {
project.logger.error("This version of the plugin requires $MINIMAL_SUPPORTED_GRADLE_VERSION or newer.")
}
this.project = project
val nodeExtension = NodeExtension.create(project)
project.extensions.create<PackageJsonExtension>(PackageJsonExtension.NAME, project)
Expand Down Expand Up @@ -128,8 +133,11 @@ class NodePlugin : Plugin<Project> {
}

private fun configureNodeSetupTask(nodeExtension: NodeExtension) {
val versionSource = project.providers.of(NodeVersionSource::class) {
parameters.nodeVersion.set(nodeExtension.version)
}
project.tasks.named<NodeSetupTask>(NodeSetupTask.NAME) {
val nodeArchiveDependencyProvider = variantComputer.computeNodeArchiveDependency(nodeExtension)
val nodeArchiveDependencyProvider = versionSource.get()
val archiveFileProvider = nodeArchiveDependencyProvider
.map { nodeArchiveDependency ->
resolveNodeArchiveFile(nodeArchiveDependency)
Expand All @@ -146,6 +154,7 @@ class NodePlugin : Plugin<Project> {
}

companion object {
val MINIMAL_SUPPORTED_GRADLE_VERSION: GradleVersion = GradleVersion.version("7.5.1")
const val NODE_GROUP = "Node"
const val NPM_GROUP = "npm"
const val PNPM_GROUP = "pnpm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ open class PackageJsonExtension(project: Project) {
/**
* Extension name in Gradle
*/
const val NAME = "package.json"
const val NAME = "packageJson"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.github.gradle.node.exec.NodeExecConfiguration
import com.github.gradle.node.npm.exec.NpmExecRunner
import com.github.gradle.node.task.BaseTask
import com.github.gradle.node.task.NodeSetupTask
import com.github.gradle.node.util.ProjectApiHelper
import com.github.gradle.node.util.DefaultProjectApiHelper
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
Expand All @@ -15,6 +15,7 @@ import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.listProperty
import org.gradle.kotlin.dsl.newInstance
import java.io.File
import javax.inject.Inject

Expand All @@ -33,7 +34,7 @@ abstract class NpmSetupTask : BaseTask() {
protected val nodeExtension = NodeExtension[project]

@get:Internal
val projectHelper = ProjectApiHelper.newInstance(project)
val projectHelper = project.objects.newInstance<DefaultProjectApiHelper>()

@get:Input
val args = objects.listProperty<String>()
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/github/gradle/node/npm/task/NpmTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.github.gradle.node.NodePlugin
import com.github.gradle.node.exec.NodeExecConfiguration
import com.github.gradle.node.npm.exec.NpmExecRunner
import com.github.gradle.node.task.BaseTask
import com.github.gradle.node.util.ProjectApiHelper
import com.github.gradle.node.util.DefaultProjectApiHelper
import org.gradle.api.Action
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.ProviderFactory
Expand All @@ -15,6 +15,7 @@ import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.listProperty
import org.gradle.kotlin.dsl.mapProperty
import org.gradle.kotlin.dsl.newInstance
import org.gradle.kotlin.dsl.property
import org.gradle.process.ExecSpec
import javax.inject.Inject
Expand Down Expand Up @@ -47,7 +48,7 @@ abstract class NpmTask : BaseTask() {
val execOverrides = objects.property<Action<ExecSpec>>()

@get:Internal
val projectHelper = ProjectApiHelper.newInstance(project)
val projectHelper = project.objects.newInstance<DefaultProjectApiHelper>()

@get:Internal
val nodeExtension = NodeExtension[project]
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/github/gradle/node/npm/task/NpxTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.github.gradle.node.NodePlugin
import com.github.gradle.node.exec.NodeExecConfiguration
import com.github.gradle.node.npm.exec.NpmExecRunner
import com.github.gradle.node.task.BaseTask
import com.github.gradle.node.util.ProjectApiHelper
import com.github.gradle.node.util.DefaultProjectApiHelper
import org.gradle.api.Action
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.ProviderFactory
Expand All @@ -14,6 +14,7 @@ import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.listProperty
import org.gradle.kotlin.dsl.mapProperty
import org.gradle.kotlin.dsl.newInstance
import org.gradle.kotlin.dsl.property
import org.gradle.process.ExecSpec
import javax.inject.Inject
Expand Down Expand Up @@ -45,7 +46,7 @@ abstract class NpxTask : BaseTask() {
val execOverrides = objects.property<Action<ExecSpec>>()

@get:Internal
val projectHelper = ProjectApiHelper.newInstance(project)
val projectHelper = project.objects.newInstance<DefaultProjectApiHelper>()

@get:Internal
val extension = NodeExtension[project]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class PnpmSetupTask : NpmSetupTask() {

@get:OutputDirectory
val pnpmDir by lazy {
val variantComputer = VariantComputer()
val variantComputer = VariantComputer(platformHelper)
variantComputer.computePnpmDir(nodeExtension)
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/github/gradle/node/pnpm/task/PnpmTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.github.gradle.node.NodePlugin
import com.github.gradle.node.exec.NodeExecConfiguration
import com.github.gradle.node.pnpm.exec.PnpmExecRunner
import com.github.gradle.node.task.BaseTask
import com.github.gradle.node.util.ProjectApiHelper
import com.github.gradle.node.util.DefaultProjectApiHelper
import org.gradle.api.Action
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.ProviderFactory
Expand All @@ -15,6 +15,7 @@ import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.listProperty
import org.gradle.kotlin.dsl.mapProperty
import org.gradle.kotlin.dsl.newInstance
import org.gradle.kotlin.dsl.property
import org.gradle.process.ExecSpec
import javax.inject.Inject
Expand Down Expand Up @@ -47,7 +48,7 @@ abstract class PnpmTask : BaseTask() {
val execOverrides = objects.property<Action<ExecSpec>>()

@get:Internal
val projectHelper = ProjectApiHelper.newInstance(project)
val projectHelper = project.objects.newInstance<DefaultProjectApiHelper>()

@get:Internal
val nodeExtension = NodeExtension[project]
Expand Down
9 changes: 8 additions & 1 deletion src/main/kotlin/com/github/gradle/node/task/BaseTask.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package com.github.gradle.node.task

import com.github.gradle.node.util.GradleHelperExecution
import com.github.gradle.node.util.PlatformHelper
import com.github.gradle.node.variant.VariantComputer
import org.gradle.api.DefaultTask
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Internal
import org.gradle.process.ExecOperations
import org.gradle.process.ExecResult
import javax.inject.Inject

abstract class BaseTask : DefaultTask() {

@get:Internal
var result: ExecResult? = null

@get:Internal
var platformHelper = PlatformHelper.INSTANCE
var platformHelper = PlatformHelper(GradleHelperExecution(execOperations))

@get:Inject
abstract val execOperations: ExecOperations

@get:Internal
internal val variantComputer by lazy {
VariantComputer(platformHelper)
}


}
4 changes: 2 additions & 2 deletions src/main/kotlin/com/github/gradle/node/task/NodeSetupTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.github.gradle.node.task

import com.github.gradle.node.NodeExtension
import com.github.gradle.node.NodePlugin
import com.github.gradle.node.util.ProjectApiHelper
import com.github.gradle.node.util.DefaultProjectApiHelper
import org.gradle.api.file.Directory
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Provider
Expand Down Expand Up @@ -36,7 +36,7 @@ abstract class NodeSetupTask : BaseTask() {
}

@get:Internal
val projectHelper = ProjectApiHelper.newInstance(project)
val projectHelper = project.objects.newInstance(DefaultProjectApiHelper::class.java)

init {
group = NodePlugin.NODE_GROUP
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/github/gradle/node/task/NodeTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import com.github.gradle.node.NodeExtension
import com.github.gradle.node.NodePlugin
import com.github.gradle.node.exec.NodeExecConfiguration
import com.github.gradle.node.exec.NodeExecRunner
import com.github.gradle.node.util.ProjectApiHelper
import com.github.gradle.node.util.DefaultProjectApiHelper
import org.gradle.api.Action
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.ProviderFactory
import org.gradle.api.tasks.*
import org.gradle.api.tasks.PathSensitivity.RELATIVE
import org.gradle.kotlin.dsl.listProperty
import org.gradle.kotlin.dsl.mapProperty
import org.gradle.kotlin.dsl.newInstance
import org.gradle.kotlin.dsl.property
import org.gradle.process.ExecSpec
import javax.inject.Inject
Expand Down Expand Up @@ -67,7 +68,7 @@ abstract class NodeTask : BaseTask() {
val execOverrides = objects.property<Action<ExecSpec>>()

@get:Internal
val projectHelper = ProjectApiHelper.newInstance(project)
val projectHelper = project.objects.newInstance<DefaultProjectApiHelper>()

/**
* Overrides for [ExecSpec]
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/com/github/gradle/node/util/KotlinUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.gradle.node.util

import java.util.concurrent.TimeUnit


/**
* Executes the given command and returns its output.
*
Expand Down
25 changes: 25 additions & 0 deletions src/main/kotlin/com/github/gradle/node/util/NodeVersionSource.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.gradle.node.util

import com.github.gradle.node.variant.VariantComputer
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ValueSource
import org.gradle.api.provider.ValueSourceParameters
import org.gradle.process.ExecOperations
import javax.inject.Inject

abstract class NodeVersionSource: ValueSource<Provider<String>, NodeVersionSource.NodeVersionSourceParameters> {
@get:Inject
abstract val execOperations: ExecOperations

interface NodeVersionSourceParameters : ValueSourceParameters {
val nodeVersion: Property<String>
}

override fun obtain(): Provider<String> {
val platformHelper = PlatformHelper(GradleHelperExecution(execOperations))
val variantComputer = VariantComputer(platformHelper)
return variantComputer.computeNodeArchiveDependency(parameters.nodeVersion)
}
}

21 changes: 14 additions & 7 deletions src/main/kotlin/com/github/gradle/node/util/PlatformHelper.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.github.gradle.node.util

import java.util.*

open class PlatformHelper {
internal class DefaultHelperExecution : HelperExecution {
override fun exec(command: String, vararg args: String, timeout: Long): String {
return execute(command, *args, timeout = timeout)
}
}
interface HelperExecution {
fun exec(command: String, vararg args: String, timeout: Long = 60): String
}
open class PlatformHelper(private val execution: HelperExecution = DefaultHelperExecution()) {
open val osName: String by lazy {
val name = property("os.name").toLowerCase()
when {
Expand Down Expand Up @@ -37,12 +44,12 @@ open class PlatformHelper {
private fun property(name: String): String {
return getSystemProperty(name) ?:
// Added so that we can test osArch on Windows and on non-arm systems
if (name == "uname") execute("uname", "-m")
if (name == "uname") execution.exec("uname", "-m")
else error("Unable to find a value for property [$name].")
}

open fun getSystemProperty(name: String): String? {
return System.getProperty(name);
return System.getProperty(name)
}

companion object {
Expand All @@ -51,11 +58,11 @@ open class PlatformHelper {
}

fun main(args: Array<String>) {
println("Your os.name is: '${System.getProperty("os.name")}' and is parsed as: ${PlatformHelper.INSTANCE.osName}")
println("Your os.arch is: '${System.getProperty("os.arch")}' and is parsed as: ${PlatformHelper.INSTANCE.osArch}")
println("Your os.name is: '${System.getProperty("os.name")}' and is parsed as: '${PlatformHelper.INSTANCE.osName}'")
println("Your os.arch is: '${System.getProperty("os.arch")}' and is parsed as: '${PlatformHelper.INSTANCE.osArch}'")
if (PlatformHelper.INSTANCE.isWindows) {
println("You're on windows (isWindows == true)")
} else {
println("You're not on windows (isWindows == false)")
}
}
}
Loading