• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.ndkports
2 
3 import org.gradle.api.DefaultTask
4 import org.gradle.api.file.DirectoryProperty
5 import org.gradle.api.file.RegularFileProperty
6 import org.gradle.api.tasks.InputFile
7 import org.gradle.api.tasks.OutputDirectory
8 import org.gradle.api.tasks.TaskAction
9 
10 abstract class SourceExtractTask : DefaultTask() {
11     @get:InputFile
12     abstract val source: RegularFileProperty
13 
14     @get:OutputDirectory
15     abstract val outDir: DirectoryProperty
16 
17     @TaskAction
runnull18     fun run() {
19         val pb = ProcessBuilder(
20             listOf(
21                 "tar",
22                 "xf",
23                 source.get().asFile.absolutePath,
24                 "--strip-components=1"
25             )
26         ).redirectErrorStream(true).directory(outDir.get().asFile)
27 
28         val result = pb.start()
29         val output = result.inputStream.bufferedReader().use { it.readText() }
30         if (result.waitFor() != 0) {
31             throw RuntimeException("Subprocess failed with:\n$output")
32         }
33     }
34 }