Skip to content

Commit 08616d3

Browse files
enhance PMD Java runtime fallback with improved logging and environment variable management
1 parent 713cd21 commit 08616d3

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

tools/pmdRunner.go

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,33 +120,41 @@ func RunPmd(repositoryToAnalyseDirectory string, pmdBinary string, pathsToCheck
120120
"error": err,
121121
})
122122

123+
// Not throwing - Fallback to the default Java runtime
123124
// This fallback going to be removed in the future https://codacy.atlassian.net/browse/PLUTO-1421
124125
fmt.Printf("⚠️ Warning: Java binary not found at %s: %v\n", javaBinary, err)
125126
fmt.Println("⚠️ Trying to continue with the default Java runtime")
126-
}
127-
128-
// Get current PATH
129-
pathEnv := os.Getenv("PATH")
127+
logger.Warn("Java binary not found. Continuing with the default Java runtime", logrus.Fields{
128+
"expectedPath": javaBinary,
129+
"error": err,
130+
})
131+
} else {
132+
// When java binary is found, we need to add it to the PATH
133+
134+
// Get current PATH
135+
pathEnv := os.Getenv("PATH")
136+
137+
// On Windows, use semicolon as path separator
138+
pathSeparator := ":"
139+
if runtime.GOOS == "windows" {
140+
pathSeparator = ";"
141+
}
142+
143+
// Add Java bin directory to the beginning of PATH
144+
newPath := fmt.Sprintf("PATH=%s%s%s", javaBinDir, pathSeparator, pathEnv)
145+
env = append(env, newPath)
146+
147+
logger.Debug("Updated environment variables", logrus.Fields{
148+
"javaHome": javaHome,
149+
"path": newPath,
150+
"binDir": javaBinDir,
151+
"javaBinary": javaBinary,
152+
})
130153

131-
// On Windows, use semicolon as path separator
132-
pathSeparator := ":"
133-
if runtime.GOOS == "windows" {
134-
pathSeparator = ";"
154+
// Set the environment for the command
155+
cmd.Env = env
135156
}
136157

137-
// Add Java bin directory to the beginning of PATH
138-
newPath := fmt.Sprintf("PATH=%s%s%s", javaBinDir, pathSeparator, pathEnv)
139-
env = append(env, newPath)
140-
141-
logger.Debug("Updated environment variables", logrus.Fields{
142-
"javaHome": javaHome,
143-
"path": newPath,
144-
"binDir": javaBinDir,
145-
"javaBinary": javaBinary,
146-
})
147-
148-
// Set the environment for the command
149-
cmd.Env = env
150158
} else {
151159
logger.Warn("Java runtime not found in configuration")
152160
return fmt.Errorf("java runtime not found in configuration")

0 commit comments

Comments
 (0)