-
Notifications
You must be signed in to change notification settings - Fork 23
👻 Notify user when java and/or mvn not installed #919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ | |
| import { Logger } from "winston"; | ||
| import { executeExtensionCommand } from "../commands"; | ||
|
|
||
| const uid = (() => { | ||
| let counter = 0; | ||
| return (prefix: string = "") => `${prefix}${counter++}`; | ||
| })(); | ||
|
|
@@ -111,29 +111,6 @@ | |
|
|
||
| const pipeName = rpc.generateRandomPipeName(); | ||
| const [analyzerRpcServer, analyzerPid] = this.startAnalysisServer(pipeName); | ||
| analyzerRpcServer.on("exit", (code, signal) => { | ||
| this.logger.info(`Analyzer RPC server terminated [signal: ${signal}, code: ${code}]`); | ||
| if (code) { | ||
| vscode.window.showErrorMessage( | ||
| `Analyzer RPC server failed. Status code: ${code}. Please see the output channel for details.`, | ||
| ); | ||
| } | ||
| this.fireServerStateChange("stopped"); | ||
| this.analyzerRpcServer = null; | ||
| }); | ||
| analyzerRpcServer.on("close", (code, signal) => { | ||
| this.logger.info(`Analyzer RPC server closed [signal: ${signal}, code: ${code}]`); | ||
| this.fireServerStateChange("stopped"); | ||
| this.analyzerRpcServer = null; | ||
| }); | ||
| analyzerRpcServer.on("error", (err) => { | ||
| this.logger.error("Analyzer RPC server error", err); | ||
| this.fireServerStateChange("startFailed"); | ||
| this.analyzerRpcServer = null; | ||
| vscode.window.showErrorMessage( | ||
| `Analyzer RPC server failed - ${err instanceof Error ? err.message : String(err)}`, | ||
| ); | ||
| }); | ||
| this.analyzerRpcServer = analyzerRpcServer; | ||
| this.logger.info(`Analyzer RPC server started successfully [pid: ${analyzerPid}]`); | ||
|
|
||
|
|
@@ -311,9 +288,80 @@ | |
| }, | ||
| ); | ||
|
|
||
| // Buffer to collect stderr for error analysis | ||
| let stderrBuffer = ""; | ||
|
|
||
| analyzerRpcServer.stderr.on("data", (data) => { | ||
| const asString: string = data.toString().trimEnd(); | ||
| this.logger.error(`${asString}`); | ||
| // Collect stderr for potential Java/Maven error detection | ||
| stderrBuffer += asString + "\n"; | ||
| }); | ||
|
|
||
| // Handle exit event with Java/Maven error detection | ||
| analyzerRpcServer.on("exit", (code, signal) => { | ||
| this.logger.info(`Analyzer RPC server terminated [signal: ${signal}, code: ${code}]`); | ||
|
|
||
| if (code) { | ||
| // Check if it's the specific Java error | ||
| if (stderrBuffer.toLowerCase().includes("java is not installed")) { | ||
| // Show user-friendly Java error with action button | ||
| vscode.window | ||
| .showErrorMessage( | ||
| "Java runtime is required for the analyzer server but was not found. " + | ||
| "Please install Red Hat OpenJDK (JDK 11 or later) and ensure the 'java' " + | ||
| "command is available in your system PATH.", | ||
| "Install Red Hat OpenJDK", | ||
| ) | ||
| .then((selection) => { | ||
| if (selection === "Install Red Hat OpenJDK") { | ||
| vscode.env.openExternal( | ||
| vscode.Uri.parse("https://developers.redhat.com/products/openjdk/download"), | ||
| ); | ||
| } | ||
| }); | ||
| } else if (stderrBuffer.toLowerCase().includes("maven is not installed")) { | ||
| // Show user-friendly Maven error with action button | ||
| vscode.window | ||
| .showErrorMessage( | ||
| "Maven is required for the analyzer server but was not found. " + | ||
| "Please install Maven (version 3.6 or later) and ensure the 'mvn' " + | ||
| "command is available in your system PATH.", | ||
| "Install Maven", | ||
| "Maven Setup Guide", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Make Maven error detection more robust. Similar to the Java check, this Maven detection using Use a regex pattern: - } else if (stderrBuffer.toLowerCase().includes("maven is not installed")) {
+ const mavenErrorPattern = /maven.*not\s+(found|installed)|command\s+not\s+found.*(mvn|maven)|mvn.*not\s+recognized/i;
+ } else if (mavenErrorPattern.test(stderrBuffer)) {
// Show user-friendly Maven error with action button
🤖 Prompt for AI Agents |
||
| ) | ||
| .then((selection) => { | ||
| if (selection === "Install Maven") { | ||
| vscode.env.openExternal(vscode.Uri.parse("https://maven.apache.org/download.cgi")); | ||
| } else if (selection === "Maven Setup Guide") { | ||
| vscode.env.openExternal(vscode.Uri.parse("https://maven.apache.org/install.html")); | ||
| } | ||
| }); | ||
| } else { | ||
| // Show generic error as before | ||
| vscode.window.showErrorMessage( | ||
| `Analyzer RPC server failed. Status code: ${code}. Please see the output channel for details.`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| this.fireServerStateChange("stopped"); | ||
| this.analyzerRpcServer = null; | ||
| }); | ||
|
|
||
| analyzerRpcServer.on("close", (code, signal) => { | ||
| this.logger.info(`Analyzer RPC server closed [signal: ${signal}, code: ${code}]`); | ||
| this.fireServerStateChange("stopped"); | ||
| this.analyzerRpcServer = null; | ||
| }); | ||
|
|
||
| analyzerRpcServer.on("error", (err) => { | ||
| this.logger.error("Analyzer RPC server error", err); | ||
| this.fireServerStateChange("startFailed"); | ||
| this.analyzerRpcServer = null; | ||
| vscode.window.showErrorMessage( | ||
| `Analyzer RPC server failed - ${err instanceof Error ? err.message : String(err)}`, | ||
| ); | ||
| }); | ||
|
|
||
| return [analyzerRpcServer, analyzerRpcServer.pid]; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
Verify the Java error message across platforms.
The detection relies on an exact string match (case-insensitive) for
"java is not installed or not on the path". Error message text can vary across operating systems, Java implementations, or analyzer versions.Run this script to search for the error message generation in the analyzer codebase:
Consider using a regex pattern or checking for multiple known Java error indicators (e.g., "java.*not found", "JAVA_HOME.*not set", "command not found.*java") to make the detection more robust across different environments.
🏁 Script executed:
Length of output: 278104
Improve Java‐not‐available detection
Relying on a single text check for “java is not installed or not on the path” is brittle. Update this to match multiple known error patterns (e.g.
/java.*not found/,/command not found.*java/,/JAVA_HOME.*not set/) or consolidate into one regex to catch variations across platforms.Location: vscode/src/client/analyzerClient.ts:307
🤖 Prompt for AI Agents