diff options
author | Linnea Gräf <nea@nea.moe> | 2024-11-13 13:40:50 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-11-13 13:40:50 +0100 |
commit | d267913e206f5f7bfc16607c0dc058290e6b556f (patch) | |
tree | ae586ff39bb970f51b84f89c7e0b96130e9f4e3b /buildSrc/src/RepoDownload.kt | |
parent | db87e5293846e27dc684dd141744390ae6e8bc67 (diff) | |
download | Firmament-d267913e206f5f7bfc16607c0dc058290e6b556f.tar.gz Firmament-d267913e206f5f7bfc16607c0dc058290e6b556f.tar.bz2 Firmament-d267913e206f5f7bfc16607c0dc058290e6b556f.zip |
test: Add sack util test
Diffstat (limited to 'buildSrc/src/RepoDownload.kt')
-rw-r--r-- | buildSrc/src/RepoDownload.kt | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/buildSrc/src/RepoDownload.kt b/buildSrc/src/RepoDownload.kt new file mode 100644 index 0000000..42a09b3 --- /dev/null +++ b/buildSrc/src/RepoDownload.kt @@ -0,0 +1,41 @@ +import java.net.URI +import java.util.zip.ZipInputStream +import org.gradle.api.DefaultTask +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction + +abstract class RepoDownload : DefaultTask() { + @get:Input + abstract val hash: Property<String> + + @get:OutputDirectory + abstract val outputDirectory: DirectoryProperty + + init { + outputDirectory.convention(project.layout.buildDirectory.dir("extracted-test-repo")) + } + + @TaskAction + fun performDownload() { + val outputDir = outputDirectory.asFile.get().absoluteFile + outputDir.mkdirs() + URI("https://github.com/notEnoughUpdates/notEnoughUpdates-rEPO/archive/${hash.get()}.zip").toURL().openStream() + .let(::ZipInputStream) + .use { zipInput -> + while (true) { + val entry = zipInput.nextEntry ?: break + val destination = outputDir.resolve( + entry.name.substringAfter('/')).absoluteFile + require(outputDir in generateSequence(destination) { it.parentFile }) + if (entry.isDirectory) continue + destination.parentFile.mkdirs() + destination.outputStream().use { output -> + zipInput.copyTo(output) + } + } + } + } +} |