Skip to content

Commit 7c99776

Browse files
fixed small issues
1 parent 27dc5a3 commit 7c99776

File tree

3 files changed

+47
-15
lines changed

3 files changed

+47
-15
lines changed

cmd/analyze.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,21 +263,28 @@ func getToolName(toolName string, version string) string {
263263
func runToolByTooName(toolName string, workDirectory string, pathsToCheck []string, autoFix bool, outputFile string, outputFormat string, tool *plugins.ToolInfo, runtime *plugins.RuntimeInfo) error {
264264
switch toolName {
265265
case "eslint":
266-
return tools.RunEslint(workDirectory, tool.InstallDir, runtime.Binaries[tool.Runtime], pathsToCheck, autoFix, outputFile, outputFormat)
266+
binaryPath := runtime.Binaries[tool.Runtime]
267+
return tools.RunEslint(workDirectory, tool.InstallDir, binaryPath, pathsToCheck, autoFix, outputFile, outputFormat)
267268
case "trivy":
268-
return tools.RunTrivy(workDirectory, tool.Binaries[tool.Runtime], pathsToCheck, outputFile, outputFormat)
269+
binaryPath := tool.Binaries[toolName]
270+
return tools.RunTrivy(workDirectory, binaryPath, pathsToCheck, outputFile, outputFormat)
269271
case "pmd":
270-
return tools.RunPmd(workDirectory, tool.Binaries[tool.Runtime], pathsToCheck, outputFile, outputFormat, config.Config)
272+
binaryPath := tool.Binaries[toolName]
273+
return tools.RunPmd(workDirectory, binaryPath, pathsToCheck, outputFile, outputFormat, config.Config)
271274
case "pylint":
272-
return tools.RunPylint(workDirectory, tool.Binaries[tool.Runtime], pathsToCheck, outputFile, outputFormat)
275+
binaryPath := tool.Binaries[tool.Runtime]
276+
return tools.RunPylint(workDirectory, binaryPath, pathsToCheck, outputFile, outputFormat)
273277
case "dartanalyzer":
274-
return tools.RunDartAnalyzer(workDirectory, tool.InstallDir, tool.Binaries[tool.Runtime], pathsToCheck, outputFile, outputFormat)
278+
binaryPath := tool.Binaries[tool.Runtime]
279+
return tools.RunDartAnalyzer(workDirectory, tool.InstallDir, binaryPath, pathsToCheck, outputFile, outputFormat)
275280
case "semgrep":
276-
return tools.RunSemgrep(workDirectory, tool.Binaries[tool.Runtime], pathsToCheck, outputFile, outputFormat)
281+
binaryPath := tool.Binaries[toolName]
282+
return tools.RunSemgrep(workDirectory, binaryPath, pathsToCheck, outputFile, outputFormat)
277283
case "lizard":
278-
return lizard.RunLizard(workDirectory, tool.Binaries[tool.Runtime], pathsToCheck, outputFile, outputFormat)
279-
case "enigma":
280-
return tools.RunEnigma(workDirectory, tool.InstallDir, tool.Binaries[tool.Runtime], pathsToCheck, outputFile, outputFormat)
284+
binaryPath := tool.Binaries[tool.Runtime]
285+
return lizard.RunLizard(workDirectory, binaryPath, pathsToCheck, outputFile, outputFormat)
286+
case "codacy-enigma-cli":
287+
return tools.RunEnigma(workDirectory, tool.InstallDir, tool.Binaries["codacy-enigma-cli"], pathsToCheck, outputFile, outputFormat)
281288
case "revive":
282289
return reviveTool.RunRevive(workDirectory, tool.Binaries["revive"], pathsToCheck, outputFile, outputFormat)
283290
}
@@ -286,7 +293,12 @@ func runToolByTooName(toolName string, workDirectory string, pathsToCheck []stri
286293

287294
func genericRunTool(toolName string, workDirectory string, pathsToCheck []string, autoFix bool, outputFile string, outputFormat string) error {
288295
tool := config.Config.Tools()[toolName]
289-
isToolInstalled := config.Config.IsToolInstalled(toolName, tool)
296+
var isToolInstalled bool
297+
if tool == nil {
298+
isToolInstalled = false
299+
} else {
300+
isToolInstalled = config.Config.IsToolInstalled(toolName, tool)
301+
}
290302
var isRuntimeInstalled bool
291303

292304
var runtime *plugins.RuntimeInfo

config/runtimes-installer.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,15 @@ func InstallRuntime(name string, runtimeInfo *plugins.RuntimeInfo) error {
7676

7777
// downloadAndExtractRuntime downloads and extracts a runtime
7878
func downloadAndExtractRuntime(runtimeInfo *plugins.RuntimeInfo) error {
79+
// Ensure the runtimes directory exists
80+
runtimesDir := Config.RuntimesDirectory()
81+
if err := os.MkdirAll(runtimesDir, utils.DefaultDirPerms); err != nil {
82+
return fmt.Errorf("failed to create runtimes directory: %w", err)
83+
}
84+
7985
// Create a file name for the downloaded archive
8086
fileName := filepath.Base(runtimeInfo.DownloadURL)
81-
downloadPath := filepath.Join(Config.RuntimesDirectory(), fileName)
87+
downloadPath := filepath.Join(runtimesDir, fileName)
8288

8389
// Check if the file already exists
8490
_, err := os.Stat(downloadPath)
@@ -90,7 +96,7 @@ func downloadAndExtractRuntime(runtimeInfo *plugins.RuntimeInfo) error {
9096
"downloadURL": runtimeInfo.DownloadURL,
9197
"downloadPath": downloadPath,
9298
})
93-
downloadPath, err = utils.DownloadFile(runtimeInfo.DownloadURL, Config.RuntimesDirectory())
99+
downloadPath, err = utils.DownloadFile(runtimeInfo.DownloadURL, runtimesDir)
94100
if err != nil {
95101
return fmt.Errorf("failed to download runtime: %w", err)
96102
}
@@ -116,13 +122,13 @@ func downloadAndExtractRuntime(runtimeInfo *plugins.RuntimeInfo) error {
116122
"runtime": runtimeInfo.Name,
117123
"version": runtimeInfo.Version,
118124
"fileName": fileName,
119-
"extractDirectory": Config.RuntimesDirectory(),
125+
"extractDirectory": runtimesDir,
120126
})
121127

122128
if strings.HasSuffix(fileName, ".zip") {
123-
err = utils.ExtractZip(file.Name(), Config.RuntimesDirectory())
129+
err = utils.ExtractZip(file.Name(), runtimesDir)
124130
} else {
125-
err = utils.ExtractTarGz(file, Config.RuntimesDirectory())
131+
err = utils.ExtractTarGz(file, runtimesDir)
126132
}
127133

128134
if err != nil {

tools/pmdRunner.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ import (
2828
func RunPmd(repositoryToAnalyseDirectory string, pmdBinary string, pathsToCheck []string, outputFile string, outputFormat string, config config.ConfigType) error {
2929
var cmd *exec.Cmd
3030

31+
// Debug: Log the binary path being used
32+
logger.Debug("PMD binary path", logrus.Fields{
33+
"pmdBinary": pmdBinary,
34+
})
35+
36+
// Check if the binary exists
37+
if _, err := os.Stat(pmdBinary); err != nil {
38+
logger.Error("PMD binary not found", logrus.Fields{
39+
"pmdBinary": pmdBinary,
40+
"error": err,
41+
})
42+
return fmt.Errorf("PMD binary not found at %s: %w", pmdBinary, err)
43+
}
44+
3145
// Get tool info to check version
3246
toolInfo := config.Tools()["pmd"]
3347
if toolInfo == nil {

0 commit comments

Comments
 (0)