| 1 |
package junitbuild.exec |
| 2 |
|
| 3 |
import org.gradle.api.DefaultTask |
| 4 |
import org.gradle.api.file.ConfigurableFileCollection |
| 5 |
import org.gradle.api.file.RegularFileProperty |
| 6 |
import org.gradle.api.provider.ListProperty |
| 7 |
import org.gradle.api.provider.Property |
| 8 |
import org.gradle.api.tasks.CacheableTask |
| 9 |
import org.gradle.api.tasks.Classpath |
| 10 |
import org.gradle.api.tasks.Input |
| 11 |
import org.gradle.api.tasks.Nested |
| 12 |
import org.gradle.api.tasks.OutputFile |
| 13 |
import org.gradle.api.tasks.TaskAction |
| 14 |
import org.gradle.process.CommandLineArgumentProvider |
| 15 |
import org.gradle.process.ExecOperations |
| 16 |
import java.nio.file.Files |
| 17 |
import javax.inject.Inject |
| 18 |
|
| 19 |
@CacheableTask |
| 20 |
abstract class CaptureJavaExecOutput @Inject constructor(private val execOperations: ExecOperations) : DefaultTask() { |
| 21 |
|
| 22 |
@get:Classpath |
| 23 |
abstract val classpath: ConfigurableFileCollection |
| 24 |
|
| 25 |
@get:Input |
| 26 |
abstract val mainClass: Property<String> |
| 27 |
|
| 28 |
@get:Input |
| 29 |
abstract val args: ListProperty<String> |
| 30 |
|
| 31 |
@get:Nested |
| 32 |
val jvmArgumentProviders = mutableListOf<CommandLineArgumentProvider>() |
| 33 |
|
| 34 |
@get:OutputFile |
| 35 |
abstract val outputFile: RegularFileProperty |
| 36 |
|
| 37 |
@TaskAction |
| 38 |
fun execute() { |
| 39 |
val outputFile = outputFile.get().asFile.toPath() |
| 40 |
Files.newOutputStream(outputFile).use { out -> |
| 41 |
execOperations.javaexec { |
| 42 |
classpath = [email protected] |
| 43 |
mainClass.set([email protected]) |
| 44 |
args = [email protected]() |
| 45 |
jvmArgumentProviders.addAll([email protected]) |
| 46 |
standardOutput = out |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
} |