дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
feat(run): JAR Application run configurations and their import (#2409)
Fixes #2393 Importing run configurations from .run/ and .idea/ skipped every JarApplication entry because there was no equivalent type. Adds a JAR Application run configuration (path to JAR, VM options, program arguments, JRE, working directory, environment) that runs java [VM options] -jar <jar> [args] and debugs over JDWP like the Application type, and maps JarApplication on import (JAR_PATH, VM/program parameters, working directory, alternative JRE path, envs).
Цей коміт міститься в:
1 джерело
718e07c831
коміт
98cef2aa48
12 files changed
+255
-3
No files matched your search
@@ -22,6 +22,7 @@ const KIND_LABELS: Record<string, string> = {
|
||||
program: "Program",
|
||||
compound: "Compound",
|
||||
application: "Application",
|
||||
"jar-application": "JAR Application",
|
||||
"spring-boot": "Spring Boot",
|
||||
node: "Node.js",
|
||||
"java-file": "Java Single File",
|
||||
@@ -51,6 +52,7 @@ export const KIND_OPTIONS = Object.entries(KIND_LABELS).map(([value, label]) =>
|
||||
export const KIND_CATEGORIES: Record<string, string> = {
|
||||
"spring-boot": "Java",
|
||||
application: "Java",
|
||||
"jar-application": "Java",
|
||||
native: "Java",
|
||||
"java-file": "Java",
|
||||
kotlin: "Java",
|
||||
@@ -105,6 +107,7 @@ export function configIcon(config: Pick<RunConfig, "kind" | "isTest">): string {
|
||||
case "compound":
|
||||
return "gutter-run-all";
|
||||
case "program":
|
||||
case "jar-application":
|
||||
return "file-binary";
|
||||
case "spring-boot":
|
||||
return "spring-boot";
|
||||
|
||||
@@ -45,6 +45,7 @@ export function jdwpLaunch(config: RunConfig, jdwpPort?: number): RunConfig | nu
|
||||
config = applyBuildPolicyToCommand(config);
|
||||
if (config.kind === "tomcat") return { ...config, params: { ...config.params, tomcatDebug: "true" } };
|
||||
const args = config.args;
|
||||
if (config.kind === "jar-application") return { ...config, args: [JDWP_AGENT, ...args] };
|
||||
// A single source file (`java Hi.java`): the agent goes before the file. Compiled first
|
||||
// (`javac … && java -cp …`): through `JDK_JAVA_OPTIONS`, which only the `java` launcher reads.
|
||||
if (config.kind === "java-file")
|
||||
|
||||
@@ -17,10 +17,11 @@ vi.mock("@/platform/ipc", async (orig) => {
|
||||
});
|
||||
|
||||
const { usePlatform } = await import("@/platform/platformInfo");
|
||||
const { parseJavaArgs, joinJavaArgs } = await import("@/platform/javaLaunch");
|
||||
const { parseJavaArgs, joinJavaArgs, isJvmApplication, JDWP_AGENT } = await import("@/platform/javaLaunch");
|
||||
const { parseArgs } = await import("./configs");
|
||||
const { jdwpLaunch } = await import("./javaDebug");
|
||||
const { applicationType, gradleJvmArgs, joinPropertyArgs, springBootType } = await import("./jvmTypes");
|
||||
const { applicationType, jarApplicationType, gradleJvmArgs, joinPropertyArgs, springBootType } =
|
||||
await import("./jvmTypes");
|
||||
const { formParams, newConfigOfType, registerBuiltinTypes, typeFor, withParams } = await import("./types");
|
||||
|
||||
const REPORTER_VM = "-Ddemo.flag=on --add-opens java.base/java.lang=ALL-UNNAMED";
|
||||
@@ -46,6 +47,63 @@ beforeEach(() => {
|
||||
});
|
||||
afterEach(() => dispose());
|
||||
|
||||
describe("JAR Application", () => {
|
||||
it("creates, edits and recovers a JAR configuration without a source module", () => {
|
||||
const created = newConfigOfType(jarApplicationType, []);
|
||||
expect(created.debugAdapter).toBe("java-debug");
|
||||
const edited = withParams(created, {
|
||||
jarPath: "dist/my app.jar",
|
||||
vmOptions: '-Xmx1g --add-opens java.base/java.lang=ALL-UNNAMED -Dname="My App"',
|
||||
programArgs: '--config "a b.yml" "" -jar other.jar',
|
||||
jre: "/jdk 21",
|
||||
});
|
||||
expect(edited.command).toBe("/jdk 21/bin/java");
|
||||
expect(edited.args).toEqual([
|
||||
"-Xmx1g",
|
||||
"--add-opens",
|
||||
"java.base/java.lang=ALL-UNNAMED",
|
||||
"-Dname=My App",
|
||||
"-jar",
|
||||
"dist/my app.jar",
|
||||
"--config",
|
||||
"a b.yml",
|
||||
"",
|
||||
"-jar",
|
||||
"other.jar",
|
||||
]);
|
||||
const recovered = formParams({ ...edited, params: undefined });
|
||||
expect(recovered?.jarPath).toBe("dist/my app.jar");
|
||||
expect(jarApplicationType.commandLine(recovered!)).toEqual({ command: edited.command, args: edited.args });
|
||||
expect(parseJavaArgs(edited.args).mainClass).toBeNull();
|
||||
expect(isJvmApplication(edited)).toBe(false);
|
||||
const debug = jdwpLaunch(edited)!;
|
||||
expect(debug.args).toEqual([JDWP_AGENT, ...edited.args]);
|
||||
expect(debug.command).toBe(edited.command);
|
||||
});
|
||||
|
||||
it("uses java by default and keeps Windows JRE and JAR paths", () => {
|
||||
expect(jarApplicationType.commandLine({ jarPath: "app.jar" })).toEqual({
|
||||
command: "java",
|
||||
args: ["-jar", "app.jar"],
|
||||
});
|
||||
usePlatform.setState({ os: "windows" });
|
||||
try {
|
||||
expect(
|
||||
jarApplicationType.commandLine({
|
||||
jre: String.raw`C:\Program Files\jdk`,
|
||||
jarPath: String.raw`C:\apps\my app.jar`,
|
||||
programArgs: String.raw`"C:\data files\x"`,
|
||||
}),
|
||||
).toEqual({
|
||||
command: "C:\\Program Files\\jdk/bin/java.exe",
|
||||
args: ["-jar", String.raw`C:\apps\my app.jar`, String.raw`C:\data files\x`],
|
||||
});
|
||||
} finally {
|
||||
usePlatform.setState({ os: "macos" });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("Application / Spring Boot command line", () => {
|
||||
it.each([
|
||||
["application", applicationType],
|
||||
|
||||
@@ -175,6 +175,37 @@ function jvmApplicationType(spring: boolean): RunConfigTypeContribution {
|
||||
export const applicationType = jvmApplicationType(false);
|
||||
export const springBootType = jvmApplicationType(true);
|
||||
|
||||
export const jarApplicationType: RunConfigTypeContribution = {
|
||||
id: "jar-application",
|
||||
label: "JAR Application",
|
||||
icon: "file-binary",
|
||||
description: "Run an executable JAR",
|
||||
debugAdapter: "java-debug",
|
||||
fields: [
|
||||
{ key: "jarPath", label: "Path to JAR", mono: true, required: true, browse: "file" },
|
||||
vmOptionsField(),
|
||||
{ key: "programArgs", label: "Program arguments", mono: true },
|
||||
{ ...jreField, options: [{ value: "", label: "Default (java on PATH)" }] },
|
||||
],
|
||||
commandLine(p) {
|
||||
return {
|
||||
command: p.jre ? jreJava(p.jre) : p.executable || "java",
|
||||
args: [...splitJvmArgs(p.vmOptions), "-jar", p.jarPath?.trim() ?? "", ...splitJvmArgs(p.programArgs)],
|
||||
};
|
||||
},
|
||||
paramsFrom(c) {
|
||||
if (!/^java$/i.test(commandName(c.command))) return null;
|
||||
const parsed = parseJavaArgs(c.args);
|
||||
if (parsed.jarPath === undefined) return null;
|
||||
return {
|
||||
...(c.command !== "java" ? { executable: c.command } : {}),
|
||||
jarPath: parsed.jarPath,
|
||||
vmOptions: formatArgs(parsed.vmArgs),
|
||||
programArgs: formatArgs(parsed.programArgs),
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* One value for a Maven property holding JVM arguments (`spring-boot.run.jvmArguments`,
|
||||
* `argLine`): the plugins split it on whitespace, honouring "…" and '…'.
|
||||
|
||||
@@ -91,6 +91,31 @@ it.each([undefined, false])(
|
||||
);
|
||||
|
||||
describe("configuration types", () => {
|
||||
it("shows the JAR fields, validates the path and edits shared working directory and environment", () => {
|
||||
const type = typeFor("jar-application")!;
|
||||
const config = newConfigOfType(type, []);
|
||||
expect(missingParams(config)).toEqual({ jarPath: "Path to JAR is required" });
|
||||
const edited = withParams(config, { jarPath: "app.jar", vmOptions: "-Xmx1g", programArgs: "hello" });
|
||||
const change = vi.fn();
|
||||
render(
|
||||
<ConfigForm
|
||||
config={{ ...edited, cwd: "server", env: { MODE: "test" } }}
|
||||
all={[]}
|
||||
type={type}
|
||||
errors={{}}
|
||||
onChange={change}
|
||||
modifyRequest={0}
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByLabelText("Path to JAR")).toHaveValue("app.jar");
|
||||
expect(screen.getByLabelText("VM options")).toHaveValue("-Xmx1g");
|
||||
expect(screen.getByLabelText("Program arguments")).toHaveValue("hello");
|
||||
expect(screen.getByLabelText("Working directory")).toHaveValue("server");
|
||||
expect(screen.getByLabelText("Environment variables")).toHaveValue("MODE=test");
|
||||
fireEvent.change(screen.getByLabelText("Path to JAR"), { target: { value: "new.jar" } });
|
||||
expect(change.mock.calls.at(-1)?.[0]).toMatchObject({ args: ["-Xmx1g", "-jar", "new.jar", "hello"] });
|
||||
});
|
||||
|
||||
it("runs an Application with the chosen JRE and the classpath of the chosen module", () => {
|
||||
const type = typeFor("application")!;
|
||||
const base = withParams(newConfigOfType(type, []), { ...newConfigOfType(type, []).params, mainClass: "a.Main" });
|
||||
|
||||
@@ -403,6 +403,7 @@ describe("add service categories", () => {
|
||||
program: "Shell",
|
||||
compound: "Others",
|
||||
application: "Java",
|
||||
"jar-application": "Java",
|
||||
"spring-boot": "Java",
|
||||
native: "Java",
|
||||
"java-file": "Java",
|
||||
|
||||
@@ -10,6 +10,7 @@ import { formatArgs, parseArgs, uid, uniqueName } from "./configs";
|
||||
import { commandName } from "./commandName";
|
||||
import {
|
||||
applicationType,
|
||||
jarApplicationType,
|
||||
gradleForkedJvm,
|
||||
isWindows,
|
||||
mavenForkedJvm,
|
||||
@@ -447,6 +448,7 @@ export const BUILTIN_TYPES: readonly RunConfigTypeContribution[] = [
|
||||
goBuildType,
|
||||
goTestType,
|
||||
applicationType,
|
||||
jarApplicationType,
|
||||
springBootType,
|
||||
tomcatType,
|
||||
compound,
|
||||
|
||||
Reference in new issue
Заблокувати користувача