mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-17 16:09:36 +00:00
Run and Debug passed the configuration working directory to java_resolve_launch as the module, so changing the working directory also changed which jdtls project supplied the classpath and failed with "references non-existing project". Java application configurations now store their module at detection and creation, keep it when the working directory changes, and clear it when the main class changes. Older saved configurations resolve it from the main class source file. The Kotlin debugger check also uses the module directory. Fixes #435
73 lines
2.7 KiB
TypeScript
73 lines
2.7 KiB
TypeScript
/**
|
|
* IDEA-style "Application" run configurations for Java / Kotlin main classes
|
|
* (Spring Boot applications get their own kind), the module a source file
|
|
* belongs to, and test configurations scoped to one class or method.
|
|
*/
|
|
import type { RunConfig } from "@/platform/ipc";
|
|
import { CLASSPATH, TEST_CLASSPATH, jvmModuleDir } from "@/platform/javaLaunch";
|
|
import { isTestPath } from "@/platform/languageSettings";
|
|
import { currentRoots } from "@/platform/projectRoots";
|
|
import { simpleClassName } from "./jvmTargets";
|
|
|
|
export { jvmModuleDir } from "@/platform/javaLaunch";
|
|
|
|
/** In a test source root (detected or marked in Project Structure), or Maven's `src/test`. */
|
|
const isTestSource = (relPath: string) => /(^|\/)src\/test\//.test(relPath) || isTestPath(currentRoots(), relPath);
|
|
|
|
/** Temporary "Application" configuration that runs `className` (a binary name). */
|
|
export function applicationConfig(
|
|
target: { className: string; spring?: boolean },
|
|
relPath: string,
|
|
configs: readonly RunConfig[] = [],
|
|
): RunConfig {
|
|
const module = jvmModuleDir(relPath, configs);
|
|
return {
|
|
id: `application:${module ? `${module}:` : ""}${target.className}`,
|
|
name: simpleClassName(target.className),
|
|
kind: target.spring ? "spring-boot" : "application",
|
|
command: "java",
|
|
args: ["-cp", isTestSource(relPath) ? TEST_CLASSPATH : CLASSPATH, target.className],
|
|
cwd: module || null,
|
|
module,
|
|
env: {},
|
|
detected: true,
|
|
isTest: false,
|
|
debugAdapter: relPath.endsWith(".kt") ? "kotlin-debug-adapter" : "java-debug",
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Narrows a Maven / Gradle test configuration to a class (`method` unset) or
|
|
* one method: Surefire `-Dtest=Class#method`, Gradle `--tests Class.method`.
|
|
* `fileConfig` is the file-level configuration whose last argument is the file filter.
|
|
*/
|
|
export function jvmTestConfig(fileConfig: RunConfig, className: string, method: string | undefined): RunConfig | null {
|
|
const args = fileConfig.args.slice(0, -1);
|
|
const simple = simpleClassName(className);
|
|
const name = method ? `${simple}.${method}` : simple;
|
|
const id = `context:target:${fileConfig.id}:${className}${method ? `#${method}` : ""}`;
|
|
switch (fileConfig.kind) {
|
|
case "maven":
|
|
return {
|
|
...fileConfig,
|
|
id,
|
|
name,
|
|
env: { ...fileConfig.env },
|
|
args: [...args, `-Dtest=${className}${method ? `#${method}` : ""}`, "-Dsurefire.failIfNoSpecifiedTests=false"],
|
|
};
|
|
case "gradle":
|
|
return {
|
|
...fileConfig,
|
|
id,
|
|
name,
|
|
env: { ...fileConfig.env },
|
|
args: [
|
|
...(args[args.length - 1] === "--tests" ? args.slice(0, -1) : args),
|
|
"--tests",
|
|
method ? `${className}.${method}` : className,
|
|
],
|
|
};
|
|
}
|
|
return null;
|
|
}
|