diff --git a/build-logic/bitcoin-core-binaries/src/main/kotlin/bisq/gradle/bitcoin_core/BitcoinCorePlugin.kt b/build-logic/bitcoin-core-binaries/src/main/kotlin/bisq/gradle/bitcoin_core/BitcoinCorePlugin.kt index 6e83d59ba1..478c7cec0d 100644 --- a/build-logic/bitcoin-core-binaries/src/main/kotlin/bisq/gradle/bitcoin_core/BitcoinCorePlugin.kt +++ b/build-logic/bitcoin-core-binaries/src/main/kotlin/bisq/gradle/bitcoin_core/BitcoinCorePlugin.kt @@ -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 @@ -67,10 +69,44 @@ class BitcoinCorePlugin : Plugin { val binaryDownloadTask = downloadTaskFactory .registerDownloadTask("downloadBitcoinCore", binaryDownloadUrl) - project.tasks.register("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 = + project.tasks.register("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 = + project.tasks.register("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 = + project.tasks.register("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) } }