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

[HotFix] Fix an issue with Gradle 8.10 and worker threads realising values on Properties #261

Merged
merged 1 commit into from
Jan 18, 2025
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 @@ -187,17 +187,26 @@ private void createIdeaRun(Project project, Run run, RunConfigurationContainer i
ideBeforeRunTask.configure(task -> copyProcessResourcesTasks.forEach(task::dependsOn));
}

//We can eagerly initialize here, as we are in an afterEvaluate after the run configuration has happened.
final List<String> jvmArguments = runImpl.realiseJvmArguments();
final List<String> programArguments = runImpl.getArguments().get();
final Map<String, String> productionEnvironment = adaptEnvironment(runImpl, multimapProvider -> RunsUtil.buildRunWithIdeaModClasses(multimapProvider, RunsUtil.IdeaCompileType.Production));
final Map<String, String> testEnvironment = adaptEnvironment(runImpl,
multimapProvider -> RunsUtil.buildRunWithIdeaModClasses(multimapProvider, RunsUtil.IdeaCompileType.Production),
multimapProvider -> RunsUtil.buildRunWithIdeaModClasses(multimapProvider, RunsUtil.IdeaCompileType.Test)
);

//Do not generate a run configuration for unit tests
if (!runImpl.getIsJUnit().get()) {
ideaRuns.register(runName, Application.class, ideaRun -> {
runImpl.getWorkingDirectory().get().getAsFile().mkdirs();

ideaRun.setMainClass(runImpl.getMainClass().get());
ideaRun.setWorkingDirectory(runImpl.getWorkingDirectory().get().getAsFile().getAbsolutePath());
ideaRun.setJvmArgs(RunsUtil.escapeAndJoin(RunsUtil.deduplicateElementsFollowingEachOther(runImpl.realiseJvmArguments().stream()).toList()));
ideaRun.setJvmArgs(RunsUtil.escapeAndJoin(RunsUtil.deduplicateElementsFollowingEachOther(jvmArguments.stream()).toList()));
ideaRun.setModuleName(RunsUtil.getIntellijModuleName(run.getExtensions().getByType(IdeaRunExtension.class).getPrimarySourceSet().get()));
ideaRun.setProgramParameters(RunsUtil.escapeAndJoin(RunsUtil.deduplicateElementsFollowingEachOther(runImpl.getArguments().get().stream()).toList()));
ideaRun.setEnvs(adaptEnvironment(runImpl, multimapProvider -> RunsUtil.buildRunWithIdeaModClasses(multimapProvider, RunsUtil.IdeaCompileType.Production)));
ideaRun.setProgramParameters(RunsUtil.escapeAndJoin(RunsUtil.deduplicateElementsFollowingEachOther(programArguments.stream()).toList()));
ideaRun.setEnvs(productionEnvironment);
ideaRun.setShortenCommandLine(ShortenCommandLine.ARGS_FILE);

ideaRun.beforeRun(beforeRuns -> {
Expand All @@ -212,7 +221,7 @@ private void createIdeaRun(Project project, Run run, RunConfigurationContainer i
});
} else {
ideaRuns.register(runName, JUnitWithBeforeRun.class, ideaRun -> {
final RunsUtil.PreparedUnitTestEnvironment preparedUnitTestEnvironment = RunsUtil.prepareUnitTestEnvironment(run);
final RunsUtil.PreparedUnitTestEnvironment preparedUnitTestEnvironment = RunsUtil.prepareUnitTestEnvironment(run, jvmArguments, programArguments);

ideaRun.setWorkingDirectory(runImpl.getWorkingDirectory().get().getAsFile().getAbsolutePath());
ideaRun.setModuleName(RunsUtil.getIntellijModuleName(run.getExtensions().getByType(IdeaRunExtension.class).getPrimarySourceSet().get()));
Expand All @@ -225,14 +234,11 @@ private void createIdeaRun(Project project, Run run, RunConfigurationContainer i
ideaRun.setCategory(runImpl.getTestScope().getCategory().getOrNull());

ideaRun.setWorkingDirectory(runImpl.getWorkingDirectory().get().getAsFile().getAbsolutePath());
ideaRun.setVmParameters(RunsUtil.escapeAndJoin(runImpl.realiseJvmArguments(),
ideaRun.setVmParameters(RunsUtil.escapeAndJoin(jvmArguments,
"-Dfml.junit.argsfile=%s".formatted(preparedUnitTestEnvironment.programArgumentsFile().getAbsolutePath()),
"@%s".formatted(preparedUnitTestEnvironment.jvmArgumentsFile().getAbsolutePath())
));
ideaRun.setEnvs(adaptEnvironment(runImpl,
multimapProvider -> RunsUtil.buildRunWithIdeaModClasses(multimapProvider, RunsUtil.IdeaCompileType.Production),
multimapProvider -> RunsUtil.buildRunWithIdeaModClasses(multimapProvider, RunsUtil.IdeaCompileType.Test))
);
ideaRun.setEnvs(testEnvironment);
ideaRun.setShortenCommandLine(ShortenCommandLine.ARGS_FILE);

ideaRun.beforeRun(beforeRuns -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,16 @@ private static String escape(String arg) {
public record PreparedUnitTestEnvironment(File programArgumentsFile, File jvmArgumentsFile) {
}

public static PreparedUnitTestEnvironment prepareUnitTestEnvironment(Run run) {

public static PreparedUnitTestEnvironment prepareUnitTestEnvironment(Run run,
List<String> jvmArguments,
List<String> programArguments) {
return new PreparedUnitTestEnvironment(
createArgsFile(run.getWorkingDirectory().file("%s_test_args.txt".formatted(run.getName())), run.getArguments()),
createArgsFile(run.getWorkingDirectory().file("%s_jvm_args.txt".formatted(run.getName())), run.getJvmArguments())
createArgsFile(run.getWorkingDirectory().file("%s_test_args.txt".formatted(run.getName())), jvmArguments),
createArgsFile(run.getWorkingDirectory().file("%s_jvm_args.txt".formatted(run.getName())), programArguments)
);
}

private static File createArgsFile(Provider<RegularFile> outputFile, ListProperty<String> inputs) {
private static File createArgsFile(Provider<RegularFile> outputFile, List<String> inputs) {
final File output = outputFile.get().getAsFile();

if (!output.getParentFile().exists()) {
Expand All @@ -408,7 +409,7 @@ private static File createArgsFile(Provider<RegularFile> outputFile, ListPropert
}
}
try {
final List<String> value = deduplicateElementsFollowingEachOther(inputs.get().stream()).toList();
final List<String> value = deduplicateElementsFollowingEachOther(inputs.stream()).toList();
if (output.exists()) {
if (Files.readAllLines(output.toPath()).equals(value)) {
return output;
Expand All @@ -429,7 +430,11 @@ private static File createArgsFile(Provider<RegularFile> outputFile, ListPropert

private static void configureTestTask(Project project, TaskProvider<Test> testTaskProvider, Run run) {
testTaskProvider.configure(testTask -> {
PreparedUnitTestEnvironment preparedEnvironment = prepareUnitTestEnvironment(run);
PreparedUnitTestEnvironment preparedEnvironment = prepareUnitTestEnvironment(
run,
run.getJvmArguments().get(),
run.getArguments().get()
);

addRunSourcesDependenciesToTask(testTask, run, true);
testTask.getDependsOn().add(run.getDependsOn());
Expand Down
Loading