diff options
Diffstat (limited to 'plugin/src/main/kotlin/moe/nea/archenemy/mojang/ExtractNativesTask.kt')
-rw-r--r-- | plugin/src/main/kotlin/moe/nea/archenemy/mojang/ExtractNativesTask.kt | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ExtractNativesTask.kt b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ExtractNativesTask.kt new file mode 100644 index 0000000..a3c33ed --- /dev/null +++ b/plugin/src/main/kotlin/moe/nea/archenemy/mojang/ExtractNativesTask.kt @@ -0,0 +1,45 @@ +package moe.nea.archenemy.mojang + +import moe.nea.archenemy.util.readZipFs +import org.gradle.api.DefaultTask +import org.gradle.api.file.DirectoryProperty +import org.gradle.api.provider.ListProperty +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction +import java.io.File + +abstract class ExtractNativesTask : DefaultTask() { + + @get:OutputDirectory + abstract val nativeDirectory: DirectoryProperty + + @get:Input + abstract val natives: ListProperty<MojangVersionMetadata.Library> + + @Internal + fun getNativeDirectoryPath(): File { + return nativeDirectory.get().asFile + } + + @TaskAction + fun extractNatives() { + val nativeDirectory = nativeDirectory.get().asFile + natives.get().forEach { + val extract = it.extract ?: return@forEach + val file = project.configurations + .detachedConfiguration(project.dependencies.create(it.getArtifactCoordinate())) + .files + .single().toPath() + file.readZipFs { path, inputStream -> + if (extract.exclude.any { path.startsWith(it) }) return@readZipFs + val targetFile = nativeDirectory.resolve(path) + targetFile.parentFile.mkdirs() + targetFile.outputStream().use { output -> + inputStream.copyTo(output) + } + } + } + } +}
\ No newline at end of file |