Skip to content

Commit 361d834

Browse files
authored
Merge pull request #44 from build-extensions-oss/fork-of-bedrin-patch-1
support arm macos
2 parents fc1f149 + 4fb0838 commit 361d834

File tree

2 files changed

+64
-3
lines changed

2 files changed

+64
-3
lines changed

gradle-plugin-utils/src/main/kotlin/build/extensions/oss/gradle/pluginutils/SystemUtils.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
package build.extensions.oss.gradle.pluginutils
22

3-
3+
/**
4+
* The code is used in Gradle Helm Plugin - to put proper classifier and archive format depending on operating system.
5+
*
6+
* Suffixes below are very common for binary distribution, so they work for other packages as well.
7+
*/
48
object SystemUtils {
59

610
private val osName = System.getProperty("os.name")
711
private val osArch = System.getProperty("os.arch")
812

9-
13+
/**
14+
* Returns operating system classifier for Helm package.
15+
*/
16+
// Suppress the error - it is easier to list all options in a one place.
17+
@Suppress("complexity:CyclomaticComplexMethod")
1018
fun getOperatingSystemClassifier() =
1119
when {
1220
osName.startsWith("Windows") ->
1321
"windows-amd64"
1422
osName.startsWith("Mac OS X") ->
15-
"darwin-amd64"
23+
when (osArch) {
24+
"aarch64" -> "darwin-arm64"
25+
else -> "darwin-amd64"
26+
}
1627
osName.startsWith("Linux") ->
1728
when (osArch) {
1829
"amd64" -> "linux-amd64"
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package build.extensions.oss.gradle.pluginutils
2+
3+
import io.kotest.matchers.should
4+
import io.kotest.matchers.shouldBe
5+
import io.kotest.matchers.string.startWith
6+
import org.junit.jupiter.api.Test
7+
import org.junit.jupiter.api.condition.EnabledOnOs
8+
import org.junit.jupiter.api.condition.OS
9+
10+
/**
11+
* Test if we return more or less adequate values. Basically, we can't verify that without running integration tests,
12+
* therefore let's check that at least some values are more or less good here.
13+
*
14+
* We can't check (for example) it easily on ARM on GitHub.
15+
*
16+
* We run the same test on different operating systems,
17+
* so we will never run all methods from this class at the same test run.
18+
*/
19+
class SystemUtilsTest {
20+
21+
@Test
22+
@EnabledOnOs(OS.WINDOWS)
23+
fun testWindowsClassifier() {
24+
SystemUtils.getOperatingSystemClassifier() shouldBe "windows-amd64"
25+
}
26+
27+
@Test
28+
@EnabledOnOs(OS.LINUX)
29+
fun testLinuxClassifier() {
30+
SystemUtils.getOperatingSystemClassifier() should startWith("linux-")
31+
}
32+
33+
@Test
34+
@EnabledOnOs(OS.MAC)
35+
fun testMacClassifier() {
36+
SystemUtils.getOperatingSystemClassifier() should startWith("darwin-")
37+
}
38+
39+
@Test
40+
@EnabledOnOs(OS.WINDOWS)
41+
fun testWindowsArchiveFormat() {
42+
SystemUtils.getOperatingSystemArchiveFormat() shouldBe "zip"
43+
}
44+
45+
@Test
46+
@EnabledOnOs(OS.LINUX, OS.MAC)
47+
fun testPosixArchiveFormat() {
48+
SystemUtils.getOperatingSystemArchiveFormat() shouldBe "tar.gz"
49+
}
50+
}

0 commit comments

Comments
 (0)