Skip to content

Commit 2a92e6d

Browse files
committed
fix: Redirect the logs from PMD to STDERR when writing to file CF-2115
It seems that when PMD is ran with an output file it logs the info messages to the STDOUT. But when returning results to the STDOUT does not do those logs (as most tools) On the scope of our CLI, we usually propagate a temporary file location even if we output to the STDOUT, so when such file is propagated to PMD, we need to make sure to redirect the STDOUT to STDERR
1 parent f0a5bd7 commit 2a92e6d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/pmdRunner.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,15 @@ func RunPmd(repositoryToAnalyseDirectory string, pmdBinary string, pathsToCheck
8686
// Output file
8787
if outputFile != "" {
8888
cmd.Args = append(cmd.Args, "-r", outputFile)
89+
// When storing results in a file, all the logs output should go to stderr
90+
// Note that for formats like SARIF, tools output their results to a temporary file
91+
cmd.Stdout = os.Stderr
92+
} else {
93+
cmd.Stdout = os.Stdout
8994
}
9095

91-
cmd.Dir = repositoryToAnalyseDirectory
9296
cmd.Stderr = os.Stderr
93-
cmd.Stdout = os.Stdout
97+
cmd.Dir = repositoryToAnalyseDirectory
9498

9599
// Get Java runtime info
96100
javaRuntime := config.Runtimes()["java"]

0 commit comments

Comments
 (0)