Skip to content

Commit bef63e0

Browse files
committed
Merge branch '7.x'
* 7.x: 7.1.0 Add license to POM #319 Update CHANGELOG Support for AIX OS on ppc64 Drop incorrect node_modules input from documentation and tests Remove incorrect node_modules input in pnpm test fixture Add support for ARM64 Windows #315 Update documentation NodeSetupTask should not delete general files, only old node versions #297
2 parents 5bfaef3 + a319f0e commit bef63e0

File tree

8 files changed

+137
-55
lines changed

8 files changed

+137
-55
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Version 7.x *(unreleased)*
44

5+
## Version 7.1.0 *(2024-09-27)*
6+
* Add support for ARM64 Windows [#315](https://github.com/node-gradle/gradle-node-plugin/issues/315)
7+
* Add support for AIX [#320](https://github.com/node-gradle/gradle-node-plugin/issues/320)
8+
* Add license to publications POM [#319](https://github.com/node-gradle/gradle-node-plugin/issues/319)
9+
510
## Version 7.0.2 *(2024-02-02)*
611
* Prevent misconfigured `workDir` from removing all unrelated files [#297](https://github.com/node-gradle/gradle-node-plugin/issues/297)
712

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
![Build Status](https://github.com/node-gradle/gradle-node-plugin/workflows/Build/badge.svg?branch=main)
66
[![License](https://img.shields.io/github/license/node-gradle/gradle-node-plugin.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
7-
![Version](https://img.shields.io/badge/Version-7.0.2-orange.svg)
7+
![Version](https://img.shields.io/badge/Version-7.1.0-orange.svg)
88

99
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
@@ -39,7 +39,8 @@ issue to [GitHub Issues](https://github.com/node-gradle/gradle-node-plugin/issue
3939

4040
Here's the documentation for older releases of the plugin:
4141

42-
* [7.0.2](https://github.com/node-gradle/gradle-node-plugin/blob/7.0.2/README.md) (current)
42+
* [7.1.0](https://github.com/node-gradle/gradle-node-plugin/blob/7.1.0/README.md) (current)
43+
* [7.0.2](https://github.com/node-gradle/gradle-node-plugin/blob/7.0.2/README.md)
4344
* [6.0.0](https://github.com/node-gradle/gradle-node-plugin/blob/6.0.0/README.md)
4445
* [5.0.0](https://github.com/node-gradle/gradle-node-plugin/blob/5.0.0/README.md)
4546
* [4.0.0](https://github.com/node-gradle/gradle-node-plugin/blob/4.0.0/README.md)

build.gradle.kts

+9-1
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,12 @@ tasks.wrapper {
185185

186186
tasks.withType<Test>().configureEach {
187187
jvmArgs("--add-opens=java.base/java.util=ALL-UNNAMED")
188-
}
188+
}
189+
publishing.publications.withType<MavenPublication>().configureEach {
190+
pom.licenses {
191+
license {
192+
name.set("Apache License, Version 2.0")
193+
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
194+
}
195+
}
196+
}

docs/installation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ in your `build.gradle` file:
55

66
```gradle
77
plugins {
8-
id "com.github.node-gradle.node" version "7.0.2"
8+
id "com.github.node-gradle.node" version "7.1.0"
99
}
1010
```
1111

@@ -18,7 +18,7 @@ buildscript {
1818
}
1919
2020
dependencies {
21-
classpath "com.github.node-gradle:gradle-node-plugin:7.0.2"
21+
classpath "com.github.node-gradle:gradle-node-plugin:7.1.0"
2222
}
2323
}
2424

docs/usage.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ file (see [Installing](installation.md) for details):
1818

1919
```gradle
2020
plugins {
21-
id "com.github.node-gradle.node" version "7.0.2"
21+
id "com.github.node-gradle.node" version "7.1.0"
2222
}
2323
```
2424

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

+23-9
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ import com.github.gradle.node.variant.computeNodeDir
2020
import com.github.gradle.node.yarn.task.YarnInstallTask
2121
import com.github.gradle.node.yarn.task.YarnSetupTask
2222
import com.github.gradle.node.yarn.task.YarnTask
23+
import org.gradle.api.Action
2324
import org.gradle.api.Plugin
2425
import org.gradle.api.Project
2526
import org.gradle.api.provider.Property
2627
import org.gradle.kotlin.dsl.*
28+
import org.gradle.process.ExecSpec
2729
import org.gradle.util.GradleVersion
2830
import java.io.ByteArrayOutputStream
2931
import java.io.File
@@ -66,28 +68,40 @@ class NodePlugin : Plugin<Project> {
6668
}
6769

6870
private fun addPlatform(extension: NodeExtension) {
71+
val osType = parseOsType(System.getProperty("os.name"))
72+
val arch = System.getProperty("os.arch")
73+
74+
val unameSpec: Action<ExecSpec> = Action {
75+
if (osType == OsType.WINDOWS) {
76+
this.executable = "powershell"
77+
this.args = listOf(
78+
"-NoProfile", // Command runs in ~175ms, -NoProfile saves ~300ms
79+
"-Command",
80+
"(Get-WmiObject Win32_Processor).Architecture",
81+
)
82+
} else {
83+
this.executable = "uname"
84+
this.args = listOf("-m")
85+
}
86+
}
87+
6988
val uname = {
7089
if (GradleVersion.current() >= GradleVersion.version("7.5")) {
71-
val cmd = project.providers.exec {
72-
this.executable = "uname"
73-
this.args = listOf("-m")
74-
}
90+
val cmd = project.providers.exec(unameSpec)
7591
cmd.standardOutput.asText.get().trim()
7692
} else {
7793
val out = ByteArrayOutputStream()
94+
project.exec(unameSpec)
7895
val cmd = project.exec {
79-
this.executable = "uname"
80-
this.args = listOf("-m")
96+
unameSpec.execute(this)
8197
this.standardOutput = out
8298
}
8399

84100
cmd.assertNormalExitValue()
85101
out.toString().trim()
86102
}
87103
}
88-
val name = System.getProperty("os.name")
89-
val arch = System.getProperty("os.arch")
90-
val platform = parsePlatform(name, arch, uname)
104+
val platform = parsePlatform(osType, arch, uname)
91105
extension.resolvedPlatform.set(platform)
92106
extension.computedPlatform.convention(extension.resolvedPlatform)
93107
}

src/main/kotlin/com/github/gradle/node/util/PlatformHelper.kt

+64-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@ package com.github.gradle.node.util
22

33
import java.util.concurrent.Callable
44

5+
internal enum class OsType(val osName: String) {
6+
WINDOWS("win"),
7+
MAC("darwin"),
8+
LINUX("linux"),
9+
FREEBSD("linux"), // https://github.com/node-gradle/gradle-node-plugin/issues/178
10+
SUN("sunos"),
11+
AIX("aix"),
12+
}
13+
14+
internal fun parsePlatform(type: OsType, arch: String, uname: () -> String): Platform {
15+
val osArch = if (type == OsType.WINDOWS) parseWindowsArch(arch.toLowerCase(), uname)
16+
else parseOsArch(arch.toLowerCase(), uname)
17+
return Platform(type.osName, osArch)
18+
}
19+
20+
internal fun parseOsType(type: String): OsType {
21+
val name = type.toLowerCase()
22+
return when {
23+
name.contains("windows") -> OsType.WINDOWS
24+
name.contains("mac") -> OsType.MAC
25+
name.contains("linux") -> OsType.LINUX
26+
name.contains("freebsd") -> OsType.FREEBSD
27+
name.contains("sunos") -> OsType.SUN
28+
name.contains("aix") -> OsType.AIX
29+
else -> error("Unsupported OS: $name")
30+
}
31+
}
32+
533
fun parsePlatform(name: String, arch: String, uname: () -> String): Platform {
634
return Platform(parseOsName(name.toLowerCase()), parseOsArch(arch.toLowerCase(), uname))
735
}
@@ -35,10 +63,45 @@ fun parseOsArch(arch: String, uname: Callable<String>): String {
3563
}
3664
}
3765

66+
fun parseWindowsArch(arch: String, uname: Callable<String>): String {
67+
//
68+
return when {
69+
arch.startsWith("aarch") || arch.startsWith("arm")
70+
-> {
71+
val wmiArch = uname.call()
72+
return when (wmiArch) {
73+
/*
74+
* Parse Win32_Processor.Architectures to real processor type
75+
*
76+
* Table from https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-system_info#members
77+
*/
78+
"12" -> "arm64"
79+
"9" -> "x64"
80+
// "6" -> "IA64"
81+
// "5" -> "arm" // 32-bit
82+
"0" -> "x86"
83+
// "0xffff" -> "Unknown"
84+
else -> error("Unexpected Win32_Processor.Architecture: $arch")
85+
}
86+
}
87+
arch.contains("64") -> "x64"
88+
else -> "x86"
89+
}
90+
}
91+
3892
fun main(args: Array<String>) {
3993
val osName = System.getProperty("os.name")
4094
val osArch = System.getProperty("os.arch")
41-
val uname = { execute("uname", "-m", timeout = 10) }
95+
96+
val osType = parseOsType(osName)
97+
val uname = {
98+
val args = if (osType == OsType.WINDOWS) {
99+
listOf("powershell", "-NoProfile", "-Command", "(Get-WmiObject Win32_Processor).Architecture")
100+
} else {
101+
listOf("uname", "-m")
102+
}
103+
execute(*args.toTypedArray(), timeout = 10)
104+
}
42105
val platform = parsePlatform(osName, osArch, uname)
43106

44107
println("Your os.name is: '${osName}' and is parsed as: '${platform.name}'")

src/test/groovy/com/github/gradle/node/util/PlatformHelperTest.groovy

+30-39
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,45 @@ class PlatformHelperTest extends Specification {
1616
platform.windows == isWindows
1717

1818
where:
19-
osProp | archProp | osName | osArch | isWindows
20-
'Windows 8' | 'x86' | 'win' | 'x86' | true
21-
'Windows 8' | 'x86_64' | 'win' | 'x64' | true
22-
'Mac OS X' | 'x86' | 'darwin' | 'x86' | false
23-
'Mac OS X' | 'x86_64' | 'darwin' | 'x64' | false
24-
'Linux' | 'x86' | 'linux' | 'x86' | false
25-
'Linux' | 'x86_64' | 'linux' | 'x64' | false
26-
'Linux' | 'ppc64le' | 'linux' | 'ppc64le' | false
27-
'Linux' | 's390x' | 'linux' | 's390x' | false
28-
'SunOS' | 'x86' | 'sunos' | 'x86' | false
29-
'SunOS' | 'x86_64' | 'sunos' | 'x64' | false
30-
'AIX' | 'ppc64' | 'aix' | 'ppc64' | false
19+
osProp | archProp || osName | osArch | isWindows
20+
'Windows 8' | 'x86' || 'win' | 'x86' | true
21+
'Windows 8' | 'x86_64' || 'win' | 'x64' | true
22+
'Windows 10' | 'x86_64' || 'win' | 'x64' | true
23+
'Mac OS X' | 'x86' || 'darwin' | 'x86' | false
24+
'Mac OS X' | 'x86_64' || 'darwin' | 'x64' | false
25+
'Linux' | 'x86' || 'linux' | 'x86' | false
26+
'Linux' | 'x86_64' || 'linux' | 'x64' | false
27+
'Linux' | 'ppc64le' || 'linux' | 'ppc64le' | false
28+
'Linux' | 's390x' || 'linux' | 's390x' | false
29+
'SunOS' | 'x86' || 'sunos' | 'x86' | false
30+
'SunOS' | 'x86_64' || 'sunos' | 'x64' | false
31+
'AIX' | 'ppc64' || 'aix' | 'ppc64' | false
3132
}
3233

3334
@Unroll
34-
def "verify ARM handling #archProp (#unameProp)"() {
35+
def "verify #osProp ARM handling #archProp (#unameProp)"() {
3536
given:
36-
def platform = PlatformHelperKt.parsePlatform("Linux", archProp, { unameProp })
37+
def osType = PlatformHelperKt.parseOsType(osProp)
38+
def platform = PlatformHelperKt.parsePlatform(osType, archProp, { unameProp })
3739

3840
expect:
39-
platform.name == "linux"
40-
platform.arch == osArch
41-
42-
where:
43-
archProp | unameProp | osArch
44-
'arm' | 'armv7l' | 'armv7l' // Raspberry Pi 3
45-
'arm' | 'armv8l' | 'arm64'
46-
'aarch32' | 'arm' | 'arm'
47-
'aarch64' | 'arm64' | 'arm64'
48-
'aarch64' | 'aarch64' | 'arm64'
49-
'ppc64le' | 'ppc64le' | 'ppc64le'
50-
}
51-
52-
@Unroll
53-
def "verify ARM handling Mac OS #archProp (#unameProp)"() {
54-
given:
55-
def platform = PlatformHelperKt.parsePlatform("Mac OS X", archProp, { unameProp })
56-
57-
expect:
58-
platform.name == "darwin"
41+
platform.name == osName
5942
platform.arch == osArch
6043

6144
where:
62-
archProp | unameProp | osArch
63-
'aarch32' | 'arm' | 'arm'
64-
'aarch64' | 'arm64' | 'arm64'
65-
'aarch64' | 'aarch64' | 'arm64'
66-
'aarch64' | 'x86_64' | 'x64' // This shouldn't really happen but according to PR #204 it does
45+
osProp | archProp || osName | unameProp | osArch
46+
'Linux' | 'arm' || 'linux' | 'armv7l' | 'armv7l' // Raspberry Pi 3
47+
'Linux' | 'arm' || 'linux' | 'armv8l' | 'arm64'
48+
'Linux' | 'aarch32' || 'linux' | 'arm' | 'arm'
49+
'Linux' | 'aarch64' || 'linux' | 'arm64' | 'arm64'
50+
'Linux' | 'aarch64' || 'linux' | 'aarch64' | 'arm64'
51+
'Linux' | 'ppc64le' || 'linux' | 'ppc64le' | 'ppc64le'
52+
'Mac OS X' | 'aarch32' || 'darwin' | 'arm' | 'arm'
53+
'Mac OS X' | 'aarch64' || 'darwin' | 'arm64' | 'arm64'
54+
'Mac OS X' | 'aarch64' || 'darwin' | 'aarch64' | 'arm64'
55+
'Mac OS X' | 'aarch64' || 'darwin' | 'x86_64' | 'x64' // This unfortunately happens see PR #204
56+
'Windows 10' | 'aarch64' || 'win' | '12' | 'arm64'
57+
'Windows 11' | 'aarch64' || 'win' | '9' | 'x64' // Not sure if this can actually happen
6758
}
6859

6960
def "throw exception if unsupported os"() {

0 commit comments

Comments
 (0)