Skip to content

Commit

Permalink
Fix unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans committed Aug 11, 2024
1 parent 92403a3 commit 7b930f6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -356,6 +360,31 @@ public static Stream<String> escapeStream(List<String> args, String... additiona
return Stream.concat(args.stream(), Stream.of(additional)).map(RunsUtil::escape);
}

public static Stream<String> deduplicateElementsFollowingEachOther(Stream<String> stream) {
return stream.reduce(
new ArrayList<>(),
(BiFunction<List<String>, String, List<String>>) (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.
Expand Down Expand Up @@ -384,7 +413,7 @@ private static File createArgsFile(Provider<RegularFile> outputFile, ListPropert
}
}
try {
final List<String> value = inputs.get();
final List<String> value = deduplicateElementsFollowingEachOther(inputs.get().stream()).toList();
if (output.exists()) {
if (Files.readAllLines(output.toPath()).equals(value)) {
return output;
Expand Down

0 comments on commit 7b930f6

Please sign in to comment.