-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change custom registry to work on non-linux platforms
- Loading branch information
Nigel Banks
committed
Jun 20, 2022
1 parent
c18c5bd
commit 6d67cb2
Showing
6 changed files
with
209 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package tasks; | ||
|
||
import org.apache.commons.io.FileUtils | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.tasks.* | ||
import org.gradle.internal.hash.Hashing | ||
import org.gradle.kotlin.dsl.property | ||
import java.net.URI | ||
|
||
@CacheableTask | ||
open class Download : DefaultTask() { | ||
@Input | ||
val url = project.objects.property<String>() | ||
|
||
@Input | ||
val sha256 = project.objects.property<String>() | ||
|
||
@OutputFile | ||
val dest = project.objects.fileProperty().convention(url.flatMap { | ||
val uri = URI(it) | ||
val segments = uri.path.split("/").toTypedArray() | ||
val filename = segments[segments.size - 1] | ||
project.layout.buildDirectory.file("downloads/$filename") | ||
}) | ||
|
||
@TaskAction | ||
fun exec() { | ||
val uri = URI(url.get()) | ||
dest.get().asFile.delete() | ||
FileUtils.copyURLToFile(uri.toURL(), dest.get().asFile) | ||
val calculated = Hashing.sha256().hashFile(dest.get().asFile).toString() | ||
if (sha256.get() != calculated) | ||
throw GradleException("Checksum does not match. Expected: ${sha256.get()}, Calculated: $calculated") | ||
} | ||
} |
Oops, something went wrong.