aboutsummaryrefslogtreecommitdiff
path: root/build-src/src/main/kotlin/RepoDownload.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-01-07 14:07:14 +0100
committerLinnea Gräf <nea@nea.moe>2025-01-07 14:07:14 +0100
commit34334396178eec3f72f1228b400cb9ec81c4ce4c (patch)
tree416d05a1193aa787c3fcbe44431a87d9ec555f3b /build-src/src/main/kotlin/RepoDownload.kt
parentf2783ceea23147d2702c47c9b47c06ad7fc707a8 (diff)
downloadLocalTransactionLedger-34334396178eec3f72f1228b400cb9ec81c4ce4c.tar.gz
LocalTransactionLedger-34334396178eec3f72f1228b400cb9ec81c4ce4c.tar.bz2
LocalTransactionLedger-34334396178eec3f72f1228b400cb9ec81c4ce4c.zip
build: Split up dependency injection into its own package
Diffstat (limited to 'build-src/src/main/kotlin/RepoDownload.kt')
-rw-r--r--build-src/src/main/kotlin/RepoDownload.kt41
1 files changed, 41 insertions, 0 deletions
diff --git a/build-src/src/main/kotlin/RepoDownload.kt b/build-src/src/main/kotlin/RepoDownload.kt
new file mode 100644
index 0000000..182c66f
--- /dev/null
+++ b/build-src/src/main/kotlin/RepoDownload.kt
@@ -0,0 +1,41 @@
+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
+import java.net.URI
+import java.util.zip.ZipInputStream
+
+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)
+ }
+ }
+ }
+ }
+} \ No newline at end of file