Skip to content

Commit

Permalink
fix(gradle): Only register a ProgressListener in debug log mode
Browse files Browse the repository at this point in the history
Not always registering a `ProgressListener` that, depening on the log
level, eventually does not nothing is good practice anyway, and it helps
to circumvent a bug with Gradle 8.5 [1] when analyzing such projects.

[1]: gradle/gradle#28464

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Mar 15, 2024
1 parent 30849b5 commit 0905a90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ class GradleInspector(
// then block execution of the plugin until a remote debug session is attached to port 5005 (by default),
// also see https://docs.gradle.org/current/userguide/troubleshooting.html#sec:troubleshooting_build_logic.
val model = connection.model(OrtDependencyTreeModel::class.java)
.addProgressListener(ProgressListener { logger.debug { it.displayName } })
.apply {
if (logger.delegate.isDebugEnabled) {
addProgressListener(ProgressListener { logger.debug(it.displayName) })
}
}
.setJvmArguments(jvmArgs)
.setStandardOutput(stdout)
.setStandardError(stderr)
Expand Down
9 changes: 6 additions & 3 deletions plugins/package-managers/gradle/src/main/kotlin/Gradle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,13 @@ class Gradle(
val stdout = ByteArrayOutputStream()
val stderr = ByteArrayOutputStream()

val dependencyTreeModel = connection
.model(OrtDependencyTreeModel::class.java)
val dependencyTreeModel = connection.model(OrtDependencyTreeModel::class.java)
.apply {
if (logger.delegate.isDebugEnabled) {
addProgressListener(ProgressListener { logger.debug(it.displayName) })
}
}
.addJvmArguments(jvmArgs)
.addProgressListener(ProgressListener { logger.debug { it.displayName } })
.setStandardOutput(stdout)
.setStandardError(stderr)
.withArguments("-Duser.home=${Os.userHomeDirectory}", "--init-script", initScriptFile.path)
Expand Down

0 comments on commit 0905a90

Please sign in to comment.