-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathpmdRunner.go
More file actions
42 lines (34 loc) · 1.02 KB
/
pmdRunner.go
File metadata and controls
42 lines (34 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package tools
import (
"os"
"os/exec"
)
// RunPmd executes PMD static code analyzer with the specified options
func RunPmd(repositoryToAnalyseDirectory string, pmdBinary string, pathsToCheck []string, outputFile string, outputFormat string, rulesetFile string) error {
cmd := exec.Command(pmdBinary, "check")
// Add ruleset file if provided
if rulesetFile != "" {
cmd.Args = append(cmd.Args, "--rulesets", rulesetFile)
}
// Add format options
if outputFormat == "sarif" {
cmd.Args = append(cmd.Args, "--format", "sarif")
}
if outputFile != "" {
cmd.Args = append(cmd.Args, "--report-file", outputFile)
}
// Add directory to scan
cmd.Args = append(cmd.Args, "--dir", repositoryToAnalyseDirectory)
cmd.Dir = repositoryToAnalyseDirectory
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
err := cmd.Run()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok && exitErr.ExitCode() == 4 {
// Exit status 4 means violations were found, which is not an error
return nil
}
return err
}
return nil
}