From 2578aa00bfbe3a6ac51e98e7711c46af1e465593 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Wed, 2 Aug 2023 20:05:18 +0200 Subject: [PATCH] build-logic: Create URL in DownloadTask --- .../src/main/kotlin/bisq/gradle/tasks/PerOsUrlProvider.kt | 6 ++---- .../main/kotlin/bisq/gradle/tasks/download/DownloadTask.kt | 4 ++-- .../bisq/gradle/tasks/download/DownloadTaskFactory.kt | 5 ++--- .../bisq/gradle/tasks/download/SignedBinaryDownloader.kt | 4 ++-- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/PerOsUrlProvider.kt b/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/PerOsUrlProvider.kt index dd8a068cd6..97896ce602 100644 --- a/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/PerOsUrlProvider.kt +++ b/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/PerOsUrlProvider.kt @@ -1,7 +1,5 @@ package bisq.gradle.tasks -import java.net.URL - interface PerOsUrlProvider { val urlPrefix: String @@ -9,8 +7,8 @@ interface PerOsUrlProvider { val macOsUrl: String val windowsUrl: String - val url: URL - get() = URL(urlPrefix + getUrlSuffix()) + val url: String + get() = urlPrefix + getUrlSuffix() private fun getUrlSuffix() = when (getOS()) { diff --git a/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/download/DownloadTask.kt b/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/download/DownloadTask.kt index 8d43287510..dfd13e3c04 100644 --- a/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/download/DownloadTask.kt +++ b/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/download/DownloadTask.kt @@ -13,7 +13,7 @@ import java.nio.channels.Channels abstract class DownloadTask : DefaultTask() { @get:Input - abstract val downloadUrl: Property + abstract val downloadUrl: Property @get:OutputFile abstract val outputFile: RegularFileProperty @@ -24,7 +24,7 @@ abstract class DownloadTask : DefaultTask() { } private fun downloadFile() { - val url = downloadUrl.get() + val url = URL(downloadUrl.get()) url.openStream().use { inputStream -> Channels.newChannel(inputStream).use { readableByteChannel -> println("Downloading: $url") diff --git a/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/download/DownloadTaskFactory.kt b/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/download/DownloadTaskFactory.kt index ef71cefabf..3967421e4d 100644 --- a/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/download/DownloadTaskFactory.kt +++ b/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/download/DownloadTaskFactory.kt @@ -5,16 +5,15 @@ import org.gradle.api.file.RegularFile import org.gradle.api.provider.Provider import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.register -import java.net.URL class DownloadTaskFactory( private val project: Project, private val downloadDirectoryPath: String ) { - fun registerDownloadTask(taskName: String, url: Provider): TaskProvider { + fun registerDownloadTask(taskName: String, url: Provider): TaskProvider { val outputFileProvider: Provider = url.flatMap { // url.file: // https://example.org/1.2.3/binary.exe -> 1.2.3/binary.exe - val fileName = it.file.split("/").last() + val fileName = it.split("/").last() project.layout.buildDirectory.file("$downloadDirectoryPath/$fileName") } return project.tasks.register(taskName) { diff --git a/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/download/SignedBinaryDownloader.kt b/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/download/SignedBinaryDownloader.kt index c4aa50b16b..bcf974e62f 100644 --- a/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/download/SignedBinaryDownloader.kt +++ b/build-logic/gradle-tasks/src/main/kotlin/bisq/gradle/tasks/download/SignedBinaryDownloader.kt @@ -23,11 +23,11 @@ class SignedBinaryDownloader( private val downloadTaskFactory = DownloadTaskFactory(project, downloadDirectory) fun registerTasks() { - val binaryDownloadUrl: Provider = version.map { perOsUrlProvider(it).url } + val binaryDownloadUrl: Provider = version.map { perOsUrlProvider(it).url } val binaryDownloadTask = downloadTaskFactory.registerDownloadTask("download${binaryName}Binary", binaryDownloadUrl) - val signatureDownloadUrl: Provider = binaryDownloadUrl.map { URL("$it.asc") } + val signatureDownloadUrl: Provider = binaryDownloadUrl.map { "$it.asc" } val signatureDownloadTask = downloadTaskFactory.registerDownloadTask("download${binaryName}Signature", signatureDownloadUrl)