From 652a78cbad2d32ce86723deb1fddcec5541f3e2b Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Tue, 8 Oct 2024 21:02:57 +0000 Subject: [PATCH] packaging: Remove dependency to Bisq 2 commons module --- build-logic/packaging/build.gradle.kts | 1 - .../bisq/gradle/packaging/Architecture.kt | 36 +++++++++++++++++ .../bisq/gradle/packaging/JPackageTask.kt | 2 - .../main/kotlin/bisq/gradle/packaging/OS.kt | 38 ++++++++++++++++++ .../bisq/gradle/packaging/PackagingPlugin.kt | 3 -- .../kotlin/bisq/gradle/packaging/Platform.kt | 40 +++++++++++++++++++ .../packaging/ReleaseBinariesTaskFactory.kt | 2 - .../bisq/gradle/packaging/Sha256HashTask.kt | 2 - 8 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/Architecture.kt create mode 100644 build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/OS.kt create mode 100644 build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/Platform.kt diff --git a/build-logic/packaging/build.gradle.kts b/build-logic/packaging/build.gradle.kts index 056be44659..18223b3d71 100644 --- a/build-logic/packaging/build.gradle.kts +++ b/build-logic/packaging/build.gradle.kts @@ -17,7 +17,6 @@ gradlePlugin { } dependencies { - implementation(project(":commons")) implementation("bitcoind-build-logic:gradle-tasks") implementation(libs.commons.codec) } diff --git a/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/Architecture.kt b/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/Architecture.kt new file mode 100644 index 0000000000..6a02f3629d --- /dev/null +++ b/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/Architecture.kt @@ -0,0 +1,36 @@ +package bisq.gradle.packaging + +import java.util.* + +enum class Architecture(val architectureName: String) { + X86_64("x86_64"), + ARM_64("arm64"), +} + +fun getArchitecture(): Architecture { + val architectureName = getArchitectureName() + if (isX86_64(architectureName)) { + return Architecture.X86_64 + } else if (isArm64(architectureName)) { + return Architecture.ARM_64 + } + + throw IllegalStateException("Running on unsupported Architecture: $architectureName") +} + +fun isX86_64(archName: String): Boolean { + return is64Bit(archName) && (archName.contains("x86") || archName.contains("amd")) +} + +fun isArm64(archName: String): Boolean { + return is64Bit(archName) && (archName.contains("aarch") || archName.contains("arm")) +} + +fun is64Bit(archName: String): Boolean { + return archName.contains("64") +} + +fun getArchitectureName(): String { + return System.getProperty("os.arch").lowercase(Locale.US) +} + diff --git a/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/JPackageTask.kt b/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/JPackageTask.kt index 26a17f8ca3..dad4565b92 100644 --- a/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/JPackageTask.kt +++ b/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/JPackageTask.kt @@ -1,7 +1,5 @@ package bisq.gradle.packaging -import bisq.gradle.common.OS -import bisq.gradle.common.getOS import bisq.gradle.packaging.jpackage.JPackageAppConfig import bisq.gradle.packaging.jpackage.JPackageConfig import bisq.gradle.packaging.jpackage.PackageFactory diff --git a/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/OS.kt b/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/OS.kt new file mode 100644 index 0000000000..6752253ee4 --- /dev/null +++ b/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/OS.kt @@ -0,0 +1,38 @@ +package bisq.gradle.packaging + +import java.util.* + +enum class OS(val osName: String) { + LINUX("linux"), + MAC_OS("macos"), + WINDOWS("win") +} + +fun getOS(): OS { + val osName = getOSName() + if (isLinux(osName)) { + return OS.LINUX + } else if (isMacOs(osName)) { + return OS.MAC_OS + } else if (isWindows(osName)) { + return OS.WINDOWS + } + + throw IllegalStateException("Running on unsupported OS: $osName") +} + +private fun isLinux(osName: String): Boolean { + return osName.contains("linux") +} + +private fun isMacOs(osName: String): Boolean { + return osName.contains("mac") || osName.contains("darwin") +} + +private fun isWindows(osName: String): Boolean { + return osName.contains("win") +} + +fun getOSName(): String { + return System.getProperty("os.name").lowercase(Locale.US) +} diff --git a/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/PackagingPlugin.kt b/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/PackagingPlugin.kt index 6ccab14611..a2ffed7df7 100644 --- a/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/PackagingPlugin.kt +++ b/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/PackagingPlugin.kt @@ -1,8 +1,5 @@ package bisq.gradle.packaging -import bisq.gradle.common.OS -import bisq.gradle.common.getOS -import bisq.gradle.common.getPlatform import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.Directory diff --git a/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/Platform.kt b/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/Platform.kt new file mode 100644 index 0000000000..e4bede8b5c --- /dev/null +++ b/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/Platform.kt @@ -0,0 +1,40 @@ +package bisq.gradle.packaging + +enum class Platform(val platformName: String) { + LINUX_X86_64("linux_x86_64"), + LINUX_ARM_64("linux_arm64"), + + MACOS_X86_64("macos_x86_64"), + MACOS_ARM_64("macos_arm64"), + + WIN_X86_64("win_x86_64"), + WIN_ARM_64("win_arm64") +} + +fun getPlatform(): Platform { + val os = getOS() + val architecture = getArchitecture() + when (os) { + OS.LINUX -> { + return when (architecture) { + Architecture.X86_64 -> Platform.LINUX_X86_64 + Architecture.ARM_64 -> Platform.LINUX_ARM_64 + } + } + + OS.MAC_OS -> { + return when (architecture) { + Architecture.X86_64 -> Platform.MACOS_X86_64 + Architecture.ARM_64 -> Platform.MACOS_ARM_64 + } + } + + OS.WINDOWS -> { + return when (architecture) { + Architecture.X86_64 -> Platform.WIN_X86_64 + Architecture.ARM_64 -> Platform.WIN_ARM_64 + } + } + } + throw IllegalStateException("Running on unsupported Platform: ${os.osName} / ${architecture.architectureName}") +} \ No newline at end of file diff --git a/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/ReleaseBinariesTaskFactory.kt b/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/ReleaseBinariesTaskFactory.kt index cd4c1a1248..9b8f42447e 100644 --- a/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/ReleaseBinariesTaskFactory.kt +++ b/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/ReleaseBinariesTaskFactory.kt @@ -1,7 +1,5 @@ package bisq.gradle.packaging -import bisq.gradle.common.Platform -import bisq.gradle.common.getPlatform import org.gradle.api.Project import org.gradle.api.file.Directory import org.gradle.api.file.RegularFile diff --git a/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/Sha256HashTask.kt b/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/Sha256HashTask.kt index 1db33a9436..c9428c747c 100644 --- a/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/Sha256HashTask.kt +++ b/build-logic/packaging/src/main/kotlin/bisq/gradle/packaging/Sha256HashTask.kt @@ -1,7 +1,5 @@ package bisq.gradle.packaging -import bisq.gradle.common.OS -import bisq.gradle.common.getOS import org.apache.commons.codec.binary.Hex import org.gradle.api.DefaultTask import org.gradle.api.file.RegularFileProperty