diff --git a/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java b/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java index b4120b0c6..b5ca74f31 100644 --- a/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java +++ b/common/src/main/java/net/neoforged/gradle/common/runs/ide/IdeRunIntegrationManager.java @@ -39,6 +39,7 @@ import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * A simple manager which configures runs based on the IDE it is attached to. @@ -123,10 +124,6 @@ public void idea(Project project, IdeaModel idea, ProjectSettings ideaExtension) } - private static String quoteAndJoin(List args) { - return args.stream().map(arg -> "\"" + arg + "\"").collect(Collectors.joining(" ")); - } - @Override public void eclipse(Project project, EclipseModel eclipse) { ProjectUtils.afterEvaluate(project, () -> { @@ -147,11 +144,8 @@ public void eclipse(Project project, EclipseModel eclipse) { final JavaApplicationLaunchConfig debugRun = JavaApplicationLaunchConfig.builder(eclipse.getProject().getName()) .workingDirectory(runImpl.getWorkingDirectory().get().getAsFile().getAbsolutePath()) - .vmArgs(runImpl.realiseJvmArguments().toArray(new String[0])) - .args(runImpl.getProgramArguments().get() - .stream() - .map(arg -> "\"" + arg + "\"") - .toArray(String[]::new)) + .vmArgs(quoteStream(runImpl.realiseJvmArguments()).toArray(String[]::new)) + .args(quoteStream(runImpl.getProgramArguments().get()).toArray(String[]::new)) .envVar(adaptEnvironment(runImpl, RunsUtil::buildRunWithEclipseModClasses)) .useArgumentsFile() .build(runImpl.getMainClass().get()); @@ -179,6 +173,25 @@ public void eclipse(Project project, EclipseModel eclipse) { }); } + private static String quoteAndJoin(List args) { + return quoteStream(args).collect(Collectors.joining(" ")); + } + + private static Stream quoteStream(List args) { + return args.stream().map(RunsImportAction::quote); + } + + /** + * This expects users to escape quotes in their system arguments on their own, which matches + * Gradles own behavior when used in JavaExec. + */ + private static String quote(String arg) { + if (!arg.contains(" ")) { + return arg; + } + return "\"" + arg + "\""; + } + private TaskProvider createIdeBeforeRunTask(Project project, String name, Run run, RunImpl runImpl) { final TaskProvider ideBeforeRunTask = project.getTasks().register(CommonRuntimeUtils.buildTaskName("ideBeforeRun", name), task -> { for (SourceSet sourceSet : run.getModSources().get()) { diff --git a/common/src/main/java/net/neoforged/gradle/common/runs/run/RunImpl.java b/common/src/main/java/net/neoforged/gradle/common/runs/run/RunImpl.java index 899ec898b..bf4ed14bf 100644 --- a/common/src/main/java/net/neoforged/gradle/common/runs/run/RunImpl.java +++ b/common/src/main/java/net/neoforged/gradle/common/runs/run/RunImpl.java @@ -173,9 +173,14 @@ public void configureInternally(final @NotNull RunType spec) { public List realiseJvmArguments() { final List args = new ArrayList<>(getJvmArguments().get()); - getSystemProperties().get().forEach((key, value) -> { - args.add(String.format("-D%s=\"%s\"", key, value)); - }); + // This mirrors the logic found in Gradle itself, which also does not quote key nor value + for (Map.Entry entry : getSystemProperties().get().entrySet()) { + if (entry.getValue() != null && !entry.getValue().isEmpty()) { + args.add("-D" + entry.getKey() + "=" + entry.getValue()); + } else { + args.add("-D" + entry.getKey()); + } + } return args; }