-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8c3f9d
commit 981c8ec
Showing
2 changed files
with
99 additions
and
54 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
buildSrc/src/main/kotlin/org/junit/gradle/exec/RunConsoleLauncher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.junit.gradle.exec | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.ConfigurableFileCollection | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Classpath | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.Internal | ||
import org.gradle.api.tasks.OutputDirectory | ||
import org.gradle.api.tasks.SourceSetContainer | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.kotlin.dsl.get | ||
import org.gradle.kotlin.dsl.the | ||
import org.gradle.process.CommandLineArgumentProvider | ||
import org.gradle.process.ExecOperations | ||
import trackOperationSystemAsInput | ||
import java.io.ByteArrayOutputStream | ||
import javax.inject.Inject | ||
|
||
abstract class RunConsoleLauncher @Inject constructor(private val execOperations: ExecOperations): DefaultTask() { | ||
|
||
@get:Classpath | ||
abstract val runtimeClasspath: ConfigurableFileCollection | ||
|
||
@get:Input | ||
abstract val args: ListProperty<String> | ||
|
||
@get:OutputDirectory | ||
abstract val reportsDir: DirectoryProperty | ||
|
||
@get:Internal | ||
abstract val debugging: Property<Boolean> | ||
|
||
@get:Internal | ||
abstract val hideOutput: Property<Boolean> | ||
|
||
init { | ||
runtimeClasspath.from(project.the<SourceSetContainer>()["test"].runtimeClasspath) | ||
reportsDir.convention(project.layout.buildDirectory.dir("test-results")) | ||
|
||
debugging.convention( | ||
project.providers.gradleProperty("consoleLauncherTestDebug") | ||
.map { it != "false" } | ||
.orElse(false) | ||
) | ||
outputs.cacheIf { !debugging.get() } | ||
outputs.upToDateWhen { !debugging.get() } | ||
|
||
hideOutput.convention(debugging.map { !it }) | ||
|
||
trackOperationSystemAsInput() | ||
} | ||
|
||
@TaskAction | ||
fun execute() { | ||
val output = ByteArrayOutputStream() | ||
val result = execOperations.javaexec { | ||
classpath = runtimeClasspath | ||
mainClass.set("org.junit.platform.console.ConsoleLauncher") | ||
args("--scan-classpath") | ||
args("--config=junit.platform.reporting.open.xml.enabled=true") | ||
args(this@RunConsoleLauncher.args.get()) | ||
argumentProviders += CommandLineArgumentProvider { | ||
listOf( | ||
"--reports-dir=${reportsDir.get()}", | ||
"--config=junit.platform.reporting.output.dir=${reportsDir.get()}" | ||
|
||
) | ||
} | ||
systemProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager") | ||
debug = debugging.get() | ||
if (hideOutput.get()) { | ||
standardOutput = output | ||
errorOutput = output | ||
} | ||
isIgnoreExitValue = true | ||
} | ||
if (result.exitValue != 0 && hideOutput.get()) { | ||
System.out.write(output.toByteArray()) | ||
System.out.flush() | ||
} | ||
result.rethrowFailure().assertNormalExitValue() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters