diff --git a/README.md b/README.md index 5f60b0e48..1966294ed 100644 --- a/README.md +++ b/README.md @@ -704,10 +704,10 @@ neogradle.subsystems.conventions.ide.idea.use-post-sync-task=true ``` ##### Reconfiguration of IDEA Unit Test Templates -By default, the IDEA unit test templates are reconfigured to support running unit tests from the gutter. -You can disable this behavior by setting the following property in your gradle.properties: +By default, the IDEA unit test templates are not reconfigured to support running unit tests from the gutter. +You can enable this behavior by setting the following property in your gradle.properties: ```properties -neogradle.subsystems.conventions.ide.idea.reconfigure-unit-test-templates=false +neogradle.subsystems.conventions.ide.idea.reconfigure-unit-test-templates=true ``` ### Runs diff --git a/common/src/main/java/net/neoforged/gradle/common/extensions/subsystems/ConventionsExtension.java b/common/src/main/java/net/neoforged/gradle/common/extensions/subsystems/ConventionsExtension.java index 55d1ebe04..9c4991f60 100644 --- a/common/src/main/java/net/neoforged/gradle/common/extensions/subsystems/ConventionsExtension.java +++ b/common/src/main/java/net/neoforged/gradle/common/extensions/subsystems/ConventionsExtension.java @@ -148,7 +148,7 @@ public IDEAExtension(WithEnabledProperty parent) { getShouldUseCompilerDetection().convention(getBooleanProperty("compiler-detection", true, false)); getShouldUsePostSyncTask().convention(getBooleanProperty("use-post-sync-task", false, false)); - getShouldReconfigureTemplatesForTests().convention(getBooleanProperty("reconfigure-unit-test-templates", true, false)); + getShouldReconfigureTemplatesForTests().convention(getBooleanProperty("reconfigure-unit-test-templates", false, false)); } } } 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 14e375cc5..a973d8129 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 @@ -194,9 +194,9 @@ private void createIdeaRun(Project project, Run run, RunConfigurationContainer i ideaRun.setMainClass(runImpl.getMainClass().get()); ideaRun.setWorkingDirectory(runImpl.getWorkingDirectory().get().getAsFile().getAbsolutePath()); - ideaRun.setJvmArgs(RunsUtil.escapeAndJoin(runImpl.realiseJvmArguments())); + ideaRun.setJvmArgs(RunsUtil.escapeAndJoin(RunsUtil.deduplicateElementsFollowingEachOther(runImpl.realiseJvmArguments().stream()).toList())); ideaRun.setModuleName(RunsUtil.getIntellijModuleName(run.getExtensions().getByType(IdeaRunExtension.class).getPrimarySourceSet().get())); - ideaRun.setProgramParameters(RunsUtil.escapeAndJoin(runImpl.getArguments().get())); + ideaRun.setProgramParameters(RunsUtil.escapeAndJoin(RunsUtil.deduplicateElementsFollowingEachOther(runImpl.getArguments().get().stream()).toList())); ideaRun.setEnvs(adaptEnvironment(runImpl, multimapProvider -> RunsUtil.buildRunWithIdeaModClasses(multimapProvider, RunsUtil.IdeaCompileType.Production))); ideaRun.setShortenCommandLine(ShortenCommandLine.ARGS_FILE); @@ -281,8 +281,8 @@ public void eclipse(Project project, EclipseModel eclipse) { final JavaApplicationLaunchConfig debugRun = JavaApplicationLaunchConfig.builder(eclipse.getProject().getName()) .workingDirectory(runImpl.getWorkingDirectory().get().getAsFile().getAbsolutePath()) - .vmArgs(RunsUtil.escapeStream(runImpl.realiseJvmArguments()).toArray(String[]::new)) - .args(RunsUtil.escapeStream(runImpl.getArguments().get()).toArray(String[]::new)) + .vmArgs(RunsUtil.deduplicateElementsFollowingEachOther(RunsUtil.escapeStream(runImpl.realiseJvmArguments())).toArray(String[]::new)) + .args(RunsUtil.deduplicateElementsFollowingEachOther(RunsUtil.escapeStream(runImpl.getArguments().get())).toArray(String[]::new)) .envVar(adaptEnvironment(runImpl, RunsUtil::buildRunWithEclipseModClasses)) .useArgumentsFile() .build(runImpl.getMainClass().get()); @@ -332,8 +332,8 @@ public void vscode(Project project, EclipseModel eclipse) final LaunchConfiguration cfg = launchWriter.createGroup("NG - " + project.getName(), WritingMode.REMOVE_EXISTING) .createLaunchConfiguration() - .withAdditionalJvmArgs(runImpl.realiseJvmArguments()) - .withArguments(runImpl.getArguments().get()) + .withAdditionalJvmArgs(RunsUtil.deduplicateElementsFollowingEachOther(runImpl.realiseJvmArguments().stream()).toList()) + .withArguments(RunsUtil.deduplicateElementsFollowingEachOther(runImpl.getArguments().get().stream()).toList()) .withCurrentWorkingDirectory(PathLike.ofNio(runImpl.getWorkingDirectory().get().getAsFile().toPath())) .withEnvironmentVariables(adaptEnvironment(runImpl, RunsUtil::buildRunWithEclipseModClasses)) .withShortenCommandLine(ShortCmdBehaviour.ARGUMENT_FILE) diff --git a/common/src/main/java/net/neoforged/gradle/common/runs/tasks/RunsReport.java b/common/src/main/java/net/neoforged/gradle/common/runs/tasks/RunsReport.java index b482d7da3..618d7d3ec 100644 --- a/common/src/main/java/net/neoforged/gradle/common/runs/tasks/RunsReport.java +++ b/common/src/main/java/net/neoforged/gradle/common/runs/tasks/RunsReport.java @@ -1,6 +1,7 @@ package net.neoforged.gradle.common.runs.tasks; import com.google.common.collect.Multimap; +import net.neoforged.gradle.common.util.run.RunsUtil; import net.neoforged.gradle.dsl.common.runs.run.Run; import net.neoforged.gradle.dsl.common.runs.run.RunManager; import org.gradle.api.Project; @@ -87,8 +88,8 @@ public RenderableRun(Run run) { this.environment = run.getEnvironmentVariables().get(); this.mainClass = run.getMainClass().get(); this.properties = run.getSystemProperties().get(); - this.arguments = run.getArguments().get(); - this.jvmArguments = run.getJvmArguments().get(); + this.arguments = RunsUtil.deduplicateElementsFollowingEachOther(run.getArguments().get().stream()).toList(); + this.jvmArguments = RunsUtil.deduplicateElementsFollowingEachOther(run.getJvmArguments().get().stream()).toList(); this.isSingleInstance = run.getIsSingleInstance().get(); this.workingDirectory = run.getWorkingDirectory().get().getAsFile().getAbsolutePath(); this.isClient = run.getIsClient().get(); diff --git a/common/src/main/java/net/neoforged/gradle/common/tasks/IdePostSyncExecutionTask.java b/common/src/main/java/net/neoforged/gradle/common/tasks/IdePostSyncExecutionTask.java index 16a074cb5..ee195d6d4 100644 --- a/common/src/main/java/net/neoforged/gradle/common/tasks/IdePostSyncExecutionTask.java +++ b/common/src/main/java/net/neoforged/gradle/common/tasks/IdePostSyncExecutionTask.java @@ -1,12 +1,6 @@ package net.neoforged.gradle.common.tasks; import net.neoforged.gradle.dsl.common.tasks.NeoGradleBase; -import org.gradle.api.file.ConfigurableFileCollection; -import org.gradle.api.tasks.InputFiles; public abstract class IdePostSyncExecutionTask extends NeoGradleBase { - - - @InputFiles - public abstract ConfigurableFileCollection getIdePostSyncFiles(); } diff --git a/common/src/main/java/net/neoforged/gradle/common/util/run/RunsUtil.java b/common/src/main/java/net/neoforged/gradle/common/util/run/RunsUtil.java index ed4465b6a..a6d75f6c6 100644 --- a/common/src/main/java/net/neoforged/gradle/common/util/run/RunsUtil.java +++ b/common/src/main/java/net/neoforged/gradle/common/util/run/RunsUtil.java @@ -46,9 +46,13 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.StandardOpenOption; +import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BiFunction; +import java.util.function.BinaryOperator; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -101,8 +105,8 @@ public static void createTasks(Project project, Run run) { runExec.getMainClass().convention(run.getMainClass()); runExec.setWorkingDir(workingDir); - runExec.args(run.getArguments().get()); - runExec.jvmArgs(run.getJvmArguments().get()); + runExec.args(deduplicateElementsFollowingEachOther(run.getArguments().get().stream()).toList()); + runExec.jvmArgs(deduplicateElementsFollowingEachOther(run.getJvmArguments().get().stream()).toList()); runExec.systemProperties(run.getSystemProperties().get()); runExec.environment(run.getEnvironmentVariables().get()); run.getModSources().all().get().values().stream() @@ -356,6 +360,31 @@ public static Stream escapeStream(List args, String... additiona return Stream.concat(args.stream(), Stream.of(additional)).map(RunsUtil::escape); } + public static Stream deduplicateElementsFollowingEachOther(Stream stream) { + return stream.reduce( + new ArrayList<>(), + (BiFunction, String, List>) (strings, s) -> { + if (s.isEmpty()) { + return strings; + } + + if (strings.isEmpty()) { + strings.add(s); + return strings; + } + + if (strings.get(strings.size() - 1).equals(s)) { + return strings; + } + + strings.add(s); + return strings; + }, (strings, strings2) -> { + strings.addAll(strings2); + return strings; + }).stream(); + } + /** * This expects users to escape quotes in their system arguments on their own, which matches * Gradles own behavior when used in JavaExec. @@ -384,7 +413,7 @@ private static File createArgsFile(Provider outputFile, ListPropert } } try { - final List value = inputs.get(); + final List value = deduplicateElementsFollowingEachOther(inputs.get().stream()).toList(); if (output.exists()) { if (Files.readAllLines(output.toPath()).equals(value)) { return output;