Skip to content

Commit e53e362

Browse files
refactor: simplify PMD command configuration by removing default ruleset handling
1 parent 08616d3 commit e53e362

File tree

1 file changed

+4
-34
lines changed

1 file changed

+4
-34
lines changed

tools/pmdRunner.go

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"codacy/cli-v2/config"
55
"codacy/cli-v2/utils/logger"
66
"fmt"
7-
"io"
87
"os"
98
"os/exec"
109
"path/filepath"
@@ -28,47 +27,18 @@ import (
2827
// - error: nil if analysis succeeds or violations found, error otherwise
2928
func RunPmd(repositoryToAnalyseDirectory string, pmdBinary string, pathsToCheck []string, outputFile string, outputFormat string, config config.ConfigType) error {
3029
var cmd *exec.Cmd
30+
3131
if runtime.GOOS == "windows" {
3232
cmd = exec.Command(pmdBinary) // On Windows, don't add "pmd" subcommand
3333
} else {
3434
cmd = exec.Command(pmdBinary, "pmd") // On Unix, use "pmd" subcommand
3535
}
3636

37-
// Check for ruleset file in tools-configs directory
38-
configFile, exists := ConfigFileExists(config, "ruleset.xml")
39-
if !exists {
40-
// If no ruleset exists, copy the default ruleset
41-
defaultRuleset := filepath.Join("tools", "pmd", "default-ruleset.xml")
42-
targetRuleset := filepath.Join(config.ToolsConfigDirectory(), "ruleset.xml")
43-
44-
// Ensure tools config directory exists
45-
if err := os.MkdirAll(config.ToolsConfigDirectory(), 0755); err != nil {
46-
return fmt.Errorf("failed to create tools config directory: %w", err)
47-
}
48-
49-
// Copy default ruleset
50-
src, err := os.Open(defaultRuleset)
51-
if err != nil {
52-
return fmt.Errorf("failed to open default ruleset: %w", err)
53-
}
54-
defer src.Close()
55-
56-
dst, err := os.Create(targetRuleset)
57-
if err != nil {
58-
return fmt.Errorf("failed to create target ruleset: %w", err)
59-
}
60-
defer dst.Close()
61-
62-
if _, err := io.Copy(dst, src); err != nil {
63-
return fmt.Errorf("failed to copy default ruleset: %w", err)
64-
}
65-
66-
configFile = targetRuleset
37+
// Add config file from tools-configs directory if it exists
38+
if configFile, exists := ConfigFileExists(config, "ruleset.xml"); exists {
39+
cmd.Args = append(cmd.Args, "-R", configFile)
6740
}
6841

69-
// Add ruleset file to command arguments
70-
cmd.Args = append(cmd.Args, "-R", configFile)
71-
7242
// Add source directories (comma-separated list for PMD)
7343
if len(pathsToCheck) > 0 {
7444
dirArg := strings.Join(pathsToCheck, ",")

0 commit comments

Comments
 (0)