Skip to content

Commit

Permalink
Add Bisq Toolchain Resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
alvasw committed Nov 17, 2023
1 parent 818c6a1 commit e3314bb
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions build-logic/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ include 'gradle-tasks'
include 'electrum-binaries'
include 'packaging'
include 'tor-binary'
include 'toolchain-resolver'
17 changes: 17 additions & 0 deletions build-logic/toolchain-resolver/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
`java-gradle-plugin`
`kotlin-dsl`
}

repositories {
mavenCentral()
}

gradlePlugin {
plugins {
create("ToolchainResolverPlugin") {
id = "bisq.gradle.toolchain_resolver.ToolchainResolverPlugin"
implementationClass = "bisq.gradle.toolchain_resolver.ToolchainResolverPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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"
15 -> "https://cdn.azul.com/zulu/bin/zulu15.46.17-ca-jdk15.0.10-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
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}
14 changes: 14 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ pluginManagement {
includeBuild('build-logic')
}

plugins {
id 'bisq.gradle.toolchain_resolver.ToolchainResolverPlugin'
}

toolchainManagement {
jvm {
javaRepositories {
repository("bisq_zulu") {
resolverClass = bisq.gradle.toolchain_resolver.BisqToolchainResolver
}
}
}
}

rootProject.name = 'bisq'

include 'platforms:cli-platform'
Expand Down

0 comments on commit e3314bb

Please sign in to comment.