Implement custom toolchain resolver

This commit is contained in:
Alva Swanson 2023-09-12 20:33:31 +02:00
parent e0164dfc1b
commit fea0e69fc7
No known key found for this signature in database
GPG Key ID: 004760E77F753090
5 changed files with 86 additions and 3 deletions

View File

@ -11,4 +11,5 @@ include 'commons'
include 'gradle-tasks'
include 'packaging'
include 'regtest'
include 'toolchain-resolver'
include 'tor-binary'

View File

@ -0,0 +1,17 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.7.10'
id 'org.gradle.kotlin.kotlin-dsl' version '2.4.1'
}
repositories {
mavenCentral()
}
gradlePlugin {
plugins {
simplePlugin {
id = 'bisq.gradle.toolchain_resolver.ToolchainResolverPlugin'
implementationClass = 'bisq.gradle.toolchain_resolver.ToolchainResolverPlugin'
}
}
}

View File

@ -0,0 +1,50 @@
package bisq.gradle.toolchain_resolver
import org.gradle.jvm.toolchain.JavaToolchainDownload
import org.gradle.jvm.toolchain.JavaToolchainRequest
import org.gradle.jvm.toolchain.JavaToolchainResolver
import org.gradle.platform.OperatingSystem
import java.net.URI
import java.util.*
@Suppress("UnstableApiUsage")
abstract class BisqToolchainResolver : JavaToolchainResolver {
override fun resolve(toolchainRequest: JavaToolchainRequest): Optional<JavaToolchainDownload> {
val operatingSystem = toolchainRequest.buildPlatform.operatingSystem
val javaVersion = toolchainRequest.javaToolchainSpec.languageVersion.get().asInt()
val toolchainUrl: String = when (operatingSystem) {
OperatingSystem.LINUX -> getToolchainUrlForLinux(javaVersion)
OperatingSystem.MAC_OS -> getToolchainUrlForMacOs(javaVersion)
OperatingSystem.WINDOWS -> getToolchainUrlForWindows(javaVersion)
else -> null
} ?: return Optional.empty()
val uri = URI(toolchainUrl)
return Optional.of(
JavaToolchainDownload.fromUri(uri)
)
}
private fun getToolchainUrlForLinux(javaVersion: Int): String? =
when (javaVersion) {
11 -> "https://cdn.azul.com/zulu/bin/zulu11.66.15-ca-jdk11.0.20-linux_x64.zip"
17 -> "https://cdn.azul.com/zulu/bin/zulu17.44.15-ca-jdk17.0.8-linux_x64.zip"
else -> null
}
private fun getToolchainUrlForMacOs(javaVersion: Int): String? =
when (javaVersion) {
11 -> "https://cdn.azul.com/zulu/bin/zulu11.66.15_1-ca-jdk11.0.20-macosx_x64.tar.gz"
17 -> "https://cdn.azul.com/zulu/bin/zulu17.44.15_1-ca-jdk17.0.8-macosx_x64.tar.gz"
else -> null
}
private fun getToolchainUrlForWindows(javaVersion: Int): String? =
when (javaVersion) {
11 -> "https://cdn.azul.com/zulu/bin/zulu11.66.15-ca-jdk11.0.20-win_x64.zip"
17 -> "https://cdn.azul.com/zulu/bin/zulu17.44.15-ca-jdk17.0.8-win_x64.zip"
else -> null
}
}

View File

@ -0,0 +1,15 @@
package bisq.gradle.toolchain_resolver
import org.gradle.api.Plugin
import org.gradle.api.initialization.Settings
import org.gradle.jvm.toolchain.*
import javax.inject.Inject
@Suppress("UnstableApiUsage")
class ToolchainResolverPlugin @Inject constructor(private val toolchainResolverRegistry: JavaToolchainResolverRegistry) : Plugin<Settings> {
override fun apply(settings: Settings) {
settings.plugins.apply("jvm-toolchain-management")
toolchainResolverRegistry.register(BisqToolchainResolver::class.java)
}
}

View File

@ -6,14 +6,14 @@ pluginManagement {
}
plugins {
id("org.gradle.toolchains.foojay-resolver") version "0.7.0"
id 'bisq.gradle.toolchain_resolver.ToolchainResolverPlugin'
}
toolchainManagement {
jvm {
javaRepositories {
repository("foojay") {
resolverClass = org.gradle.toolchains.foojay.FoojayToolchainResolver
repository("bisq_zulu") {
resolverClass = bisq.gradle.toolchain_resolver.BisqToolchainResolver
}
}
}