дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-08 19:02:17 +02:00
fix(debugger): Debug JVM scripts and Maven server goals through a JDWP agent (#185)
java-debug runs inside jdtls and is reached through its debugServer port, but configurations that aren't Application / Spring Boot and select java-debug (a Shell Script running `catalina.bat run`, say) fell through to the generic launch template, and the adapter launcher tried to start com.microsoft.java.debug.plugin.jar as a process: on Windows that failed with os error 193, elsewhere with a misleading "debug adapter not found". - Shell script / program configurations with java-debug start with a suspended JDWP agent injected through JAVA_TOOL_OPTIONS and attach once the JVM prints its port, so `catalina.bat run` / `catalina.sh run` can be debugged. - Maven goals that run the app in Maven's JVM (tomcat7:run, jetty:run(-war), exec:java, or any Maven config with java-debug) are debugged through MAVEN_OPTS. - Gradle tasks that start no JVM say why they can't be debugged; `debug.startConfig` with a single debuggable config goes through the run debug flow. - .jar adapters are never spawned as processes, and Windows adapter lookup only accepts PATHEXT files (so npm-installed adapters pick the .cmd shim instead of the POSIX one); the PATHEXT expansion moves to ide_core::process::executable_names, shared with ide-run. Not run on Windows; the Windows resolution is covered by tests with an injected platform. Fixes #179 Claude-Session: https://claude.ai/code/session_01Dq6jQQn8ZhRfkkyj3PRutA
Цей коміт міститься в:
1 джерело
1f9be73174
коміт
75e7d582d4
9 files changed
+216
-37
No files matched your search
@@ -4,15 +4,26 @@
|
||||
* (`spring-boot:run` → `-Dspring-boot.run.jvmArguments`, Surefire →
|
||||
* `-Dmaven.surefire.debug`, Gradle → `--debug-jvm`); when the agent reports
|
||||
* its port, the Java debugger attaches. Output and the test tree stay in the Run tab.
|
||||
* Maven goals that run the application inside Maven's JVM (`tomcat7:run`, `jetty:run`,
|
||||
* `exec:java`) get the agent through `MAVEN_OPTS`; any other configuration set to the Java
|
||||
* debugger (a script such as `catalina.sh run`) through `JAVA_TOOL_OPTIONS`, which every JVM reads.
|
||||
*/
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import type { RunConfig } from "@/platform/ipc";
|
||||
import { JDWP_AGENT, jdwpListeningPort } from "@/platform/javaLaunch";
|
||||
import { isJvmApplication, JDWP_AGENT, jdwpListeningPort } from "@/platform/javaLaunch";
|
||||
import { startRun, useRun } from "./store";
|
||||
|
||||
const isMavenTestGoal = (a: string) =>
|
||||
/^(test|verify|integration-test|surefire:test|failsafe:integration-test)$/.test(a);
|
||||
const isGradleJvmTask = (a: string) => /(^|:)(test|bootRun|run|integrationTest|check)$/.test(a);
|
||||
/** A plugin goal that runs the application in Maven's own JVM (`tomcat7:run`, `jetty:run-war`, `exec:java`). */
|
||||
const isMavenInProcessGoal = (a: string) => /^[\w.-]+(:[\w.-]+)*:(run|run-war|run-exploded|java)$/.test(a);
|
||||
const JAVA_ADAPTER = "java-debug";
|
||||
|
||||
function withOption(env: Record<string, string>, key: string, value: string): Record<string, string> {
|
||||
const current = env[key]?.trim();
|
||||
return { ...env, [key]: current ? `${current} ${value}` : value };
|
||||
}
|
||||
|
||||
function withProperty(args: readonly string[], key: string, value: string): string[] {
|
||||
const prefix = `-D${key}=`;
|
||||
@@ -38,12 +49,17 @@ export function jdwpLaunch(config: RunConfig): RunConfig | null {
|
||||
if (failsafe) out = withProperty(out, "maven.failsafe.debug", JDWP_AGENT);
|
||||
return { ...config, args: out };
|
||||
}
|
||||
if (config.debugAdapter === JAVA_ADAPTER || args.some(isMavenInProcessGoal))
|
||||
return { ...config, env: withOption(config.env, "MAVEN_OPTS", JDWP_AGENT) };
|
||||
return null;
|
||||
}
|
||||
if (config.kind === "gradle" || /(^|\/)gradlew?(\.bat)?$/.test(config.command)) {
|
||||
if (!args.some(isGradleJvmTask)) return null;
|
||||
return args.includes("--debug-jvm") ? config : { ...config, args: [...args, "--debug-jvm"] };
|
||||
}
|
||||
// Application / Spring Boot configurations are launched by java-debug itself.
|
||||
if (config.debugAdapter === JAVA_ADAPTER && !isJvmApplication(config))
|
||||
return { ...config, env: withOption(config.env, "JAVA_TOOL_OPTIONS", JDWP_AGENT) };
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Заблокувати користувача