Skip to content
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

Switch to Gradles approach for serializing System properties #59

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -123,10 +124,6 @@ public void idea(Project project, IdeaModel idea, ProjectSettings ideaExtension)

}

private static String quoteAndJoin(List<String> args) {
return args.stream().map(arg -> "\"" + arg + "\"").collect(Collectors.joining(" "));
}

@Override
public void eclipse(Project project, EclipseModel eclipse) {
ProjectUtils.afterEvaluate(project, () -> {
Expand All @@ -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());
Expand Down Expand Up @@ -179,6 +173,25 @@ public void eclipse(Project project, EclipseModel eclipse) {
});
}

private static String quoteAndJoin(List<String> args) {
return quoteStream(args).collect(Collectors.joining(" "));
}

private static Stream<String> quoteStream(List<String> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,14 @@ public void configureInternally(final @NotNull RunType spec) {
public List<String> realiseJvmArguments() {
final List<String> 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<String, String> 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;
}
Expand Down