|
9 | 9 | "strings" |
10 | 10 | "testing" |
11 | 11 |
|
| 12 | + "codacy/cli-v2/plugins" |
| 13 | + |
12 | 14 | "github.com/stretchr/testify/assert" |
13 | 15 | ) |
14 | 16 |
|
@@ -58,18 +60,48 @@ func TestRunPmdToFile(t *testing.T) { |
58 | 60 | tempResultFile := filepath.Join(os.TempDir(), "pmd.sarif") |
59 | 61 | defer os.Remove(tempResultFile) |
60 | 62 |
|
61 | | - config := *config.NewConfigType(testDirectory, repositoryCache, globalCache) |
| 63 | + // Create a test configuration with PMD tool info |
| 64 | + config := config.NewConfigType(testDirectory, repositoryCache, globalCache) |
| 65 | + |
| 66 | + // Add PMD tool configuration |
| 67 | + pmdBinaryPath := filepath. Join( globalCache, "tools/[email protected]/pmd-bin-6.55.0/bin/run.sh") |
| 68 | + |
| 69 | + // Process runtime configuration |
| 70 | + javaRuntime := plugins.RuntimeConfig{ |
| 71 | + Name: "java", |
| 72 | + Version: "17.0.10", |
| 73 | + } |
| 74 | + runtimesDir := filepath.Join(globalCache, "runtimes") |
| 75 | + runtimeInfoMap, err := plugins.ProcessRuntimes([]plugins.RuntimeConfig{javaRuntime}, runtimesDir) |
| 76 | + if err != nil { |
| 77 | + t.Fatalf("Failed to process runtime configuration: %v", err) |
| 78 | + } |
| 79 | + |
| 80 | + // Process tool configuration |
| 81 | + pmdTool := plugins.ToolConfig{ |
| 82 | + Name: "pmd", |
| 83 | + Version: "6.55.0", |
| 84 | + } |
| 85 | + toolsDir := filepath.Join(globalCache, "tools") |
| 86 | + _, err = plugins.ProcessTools([]plugins.ToolConfig{pmdTool}, toolsDir, runtimeInfoMap) |
| 87 | + if err != nil { |
| 88 | + t.Fatalf("Failed to process tool configuration: %v", err) |
| 89 | + } |
| 90 | + |
| 91 | + // Add configurations to config object |
| 92 | + err = config.AddRuntimes([]plugins.RuntimeConfig{javaRuntime}) |
| 93 | + if err != nil { |
| 94 | + t.Fatalf("Failed to add runtime configuration: %v", err) |
| 95 | + } |
| 96 | + err = config.AddTools([]plugins.ToolConfig{pmdTool}) |
| 97 | + if err != nil { |
| 98 | + t.Fatalf("Failed to add tool configuration: %v", err) |
| 99 | + } |
62 | 100 |
|
63 | 101 | // Use absolute paths |
64 | 102 | repositoryToAnalyze := testDirectory |
65 | | - // Use the standard ruleset file for testing the PMD runner functionality |
66 | | - //rulesetFile := filepath.Join(testDirectory, "ruleset.xml") |
67 | | - |
68 | | - // Use the same path as defined in plugin.yaml |
69 | | - pmdBinary := filepath. Join( globalCache, "tools/[email protected]/pmd-bin-6.55.0/bin/run.sh") |
70 | 103 |
|
71 | | - // Run PMD |
72 | | - err = RunPmd(repositoryToAnalyze, pmdBinary, nil, tempResultFile, "sarif", config) |
| 104 | + err = RunPmd(repositoryToAnalyze, pmdBinaryPath, nil, tempResultFile, "sarif", *config) |
73 | 105 | if err != nil { |
74 | 106 | t.Fatalf("Failed to run pmd: %v", err) |
75 | 107 | } |
|
0 commit comments