Skip to content

Commit

Permalink
Build/CI: pass test.log.level via CommandLineArgumentProvider and…
Browse files Browse the repository at this point in the history
… populate Quarkus console log level (#6725)

Allows passing for example `-Dtest.log.level=DEBUG` on the Gradle command line and all relevant logging configs use this value as well.

Using a `CommandLineArgumentProvider` prevents the log-level setting from influencing the Gradle cache.

Need at least INFO for Quarkus logs (to get the listen URL)
  • Loading branch information
snazy authored May 2, 2023
1 parent c595350 commit dd85a0b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
17 changes: 13 additions & 4 deletions buildSrc/src/main/kotlin/Testing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType
import org.gradle.process.CommandLineArgumentProvider
import org.gradle.testing.base.TestingExtension

class NessieTestingPlugin : Plugin<Project> {
Expand Down Expand Up @@ -100,15 +101,23 @@ class NessieTestingPlugin : Plugin<Project> {
systemProperty("user.language", "en")
systemProperty("user.country", "US")
systemProperty("user.variant", "")
systemProperty("test.log.level", testLogLevel())
jvmArgumentProviders.add(
CommandLineArgumentProvider { listOf("-Dtest.log.level=${testLogLevel()}") }
)
environment("TESTCONTAINERS_REUSE_ENABLE", "true")

if (plugins.hasPlugin("io.quarkus")) {
jvmArgs("--add-opens=java.base/java.util=ALL-UNNAMED")
// Log-levels are required to be able to parse the HTTP listen URL
systemProperty("quarkus.log.level", "INFO")
systemProperty("quarkus.log.console.level", "INFO")
systemProperty("http.access.log.level", testLogLevel())
jvmArgumentProviders.add(
CommandLineArgumentProvider {
listOf(
"-Dquarkus.log.level=${testLogLevel("INFO")}",
"-Dquarkus.log.console.level=${testLogLevel("INFO")}",
"-Dhttp.access.log.level=${testLogLevel()}"
)
}
)

minHeapSize = if (testHeapSize != null) testHeapSize as String else "512m"
maxHeapSize = if (testHeapSize != null) testHeapSize as String else "1536m"
Expand Down
10 changes: 10 additions & 0 deletions buildSrc/src/main/kotlin/Utilities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.file.FileTree
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.logging.LogLevel
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputFile
Expand Down Expand Up @@ -115,6 +116,15 @@ fun Project.libsRequiredVersion(name: String): String {

fun testLogLevel(): String = System.getProperty("test.log.level", "WARN")

fun testLogLevel(minVerbose: String): String {
val requested = LogLevel.valueOf(testLogLevel().uppercase())
val minimum = LogLevel.valueOf(minVerbose.uppercase())
if (requested.ordinal > minimum.ordinal) {
return minimum.name
}
return requested.name
}

/** Check whether the current build is run in the context of integrations-testing. */
fun isIntegrationsTestingEnabled() =
System.getProperty("nessie.integrationsTesting.enable").toBoolean()
Expand Down

0 comments on commit dd85a0b

Please sign in to comment.