Skip to content

Commit

Permalink
build-logic: Unpack and copy bitcoind to java resources
Browse files Browse the repository at this point in the history
  • Loading branch information
alvasw committed Sep 3, 2024
1 parent 547bec3 commit fe47ad7
Showing 1 changed file with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import bisq.gradle.tasks.download.SignedBinaryDownloader
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.register

Expand Down Expand Up @@ -67,10 +69,44 @@ class BitcoinCorePlugin : Plugin<Project> {
val binaryDownloadTask = downloadTaskFactory
.registerDownloadTask("downloadBitcoinCore", binaryDownloadUrl)

project.tasks.register<HashVerificationTask>("verifyBitcoinCore") {
inputFile.set(binaryDownloadTask.flatMap { it.outputFile })
sha256File.set(hashFileDownloader.verifySignatureTask.flatMap { it.fileToVerify })
resultFile.set(project.layout.buildDirectory.file("${DOWNLOADS_DIR}/bitcoin_core.sha256.result"))
val bitcoinCoreHashVerificationTask: TaskProvider<HashVerificationTask> =
project.tasks.register<HashVerificationTask>("verifyBitcoinCore") {
inputFile.set(binaryDownloadTask.flatMap { it.outputFile })
sha256File.set(hashFileDownloader.verifySignatureTask.flatMap { it.fileToVerify })
resultFile.set(project.layout.buildDirectory.file("${DOWNLOADS_DIR}/bitcoin_core.sha256.result"))
}

val unpackBitcoinCoreArchiveTask: TaskProvider<Copy> =
project.tasks.register<Copy>("unpackBitcoinCoreArchive") {
dependsOn(bitcoinCoreHashVerificationTask)

val inputFile = bitcoinCoreHashVerificationTask.flatMap { it.inputFile }
val sourceFile = inputFile.map {
if (it.asFile.name.endsWith(".tar.gz")) {
project.tarTree(it.asFile.absolutePath)
} else {
project.zipTree(it.asFile.absolutePath)
}
}
from(sourceFile)

into(project.layout.buildDirectory.dir("${DOWNLOADS_DIR}/extracted"))
}

val copyBitcoinCoreToResourcesTask: TaskProvider<Copy> =
project.tasks.register<Copy>("copyBitcoinCoreToResources") {
dependsOn(unpackBitcoinCoreArchiveTask)
val sourceDirectory = extension.version.map { version ->
project.layout.buildDirectory.dir("${DOWNLOADS_DIR}/extracted/bitcoin-$version/bin/")
}
from(sourceDirectory)
include("bitcoind*")
into(project.layout.buildDirectory.dir("generated/src/main/resources"))
}

val processResourcesTask = project.tasks.named("processResources")
processResourcesTask.configure {
dependsOn(copyBitcoinCoreToResourcesTask)
}
}

Expand Down

0 comments on commit fe47ad7

Please sign in to comment.