Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build-logic: Make DownloadTask cacheable #1077

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package bisq.gradle.tasks.download

import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFile
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
Expand All @@ -17,7 +16,7 @@ abstract class DownloadTask : DefaultTask() {
abstract val downloadUrl: Property<URL>

@get:OutputFile
abstract val outputFile: Property<Provider<RegularFile>>
abstract val outputFile: RegularFileProperty

@TaskAction
fun download() {
Expand All @@ -30,7 +29,7 @@ abstract class DownloadTask : DefaultTask() {
Channels.newChannel(inputStream).use { readableByteChannel ->
println("Downloading: $url")

FileOutputStream(outputFile.get().get().asFile).use { fileOutputStream ->
FileOutputStream(outputFile.get().asFile).use { fileOutputStream ->
fileOutputStream.channel
.transferFrom(readableByteChannel, 0, Long.MAX_VALUE)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DownloadTaskFactory(
private val project: Project, private val downloadDirectoryPath: String
) {
fun registerDownloadTask(taskName: String, url: Provider<URL>): TaskProvider<DownloadTask> {
val outputFileProvider: Provider<Provider<RegularFile>> = url.map {
val outputFileProvider: Provider<RegularFile> = url.flatMap {
// url.file:
// https://example.org/1.2.3/binary.exe -> 1.2.3/binary.exe
val fileName = it.file.split("/").last()
Expand Down