Skip to content

Commit

Permalink
Collect test libs correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed May 26, 2024
1 parent 8a0e733 commit 9efdc6f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,8 @@ public void runtime(final String neoFormVersion, Directory patches, Directory re
task.getLibraries().from(moduleOnlyConfiguration);
task.getModules().from(moduleOnlyConfiguration);

task.getTestLibraries().set(userdevTestImplementationConfiguration.getDependencies()
.stream().map(dep -> dep.getGroup() + ":" + dep.getName() + ":" + dep.getVersion())
.collect(Collectors.toList()));

task.getTestLibraries().from(userdevTestImplementationConfiguration);

CommonRuntimeExtension.configureCommonRuntimeTaskParameters(task, runtimeDefinition, workingDirectory);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,9 @@ public void doTask() throws Exception {
final UserdevProfile profile = getProfile().get();
final UserdevProfile clone = gson.fromJson(gson.toJson(profile), UserdevProfile.class);

final CoordinateCollector libraryCollector = new CoordinateCollector(getObjectFactory());
getLibraries().getAsFileTree().visit(libraryCollector);
clone.getAdditionalDependencyArtifactCoordinates().addAll(libraryCollector.getCoordinates());

clone.getAdditionalTestDependencyArtifactCoordinates().addAll(getTestLibraries());

final CoordinateCollector moduleCollector = new CoordinateCollector(getObjectFactory());
getModules().getAsFileTree().visit(moduleCollector);
clone.getModules().addAll(moduleCollector.getCoordinates());
collect(getLibraries(), clone.getAdditionalDependencyArtifactCoordinates());
collect(getTestLibraries(), clone.getAdditionalTestDependencyArtifactCoordinates());
collect(getModules(), clone.getModules());

final String json = gson.toJson(clone);

Expand All @@ -50,6 +44,12 @@ public void doTask() throws Exception {
throw new UncheckedIOException(e);
}
}

private void collect(ConfigurableFileCollection libraries, ListProperty<String> coords) {
final CoordinateCollector collector = new CoordinateCollector(getObjectFactory());
libraries.getAsFileTree().visit(collector);
coords.addAll(collector.getCoordinates());
}

@Nested
public abstract Property<UserdevProfile> getProfile();
Expand All @@ -58,8 +58,9 @@ public void doTask() throws Exception {
@PathSensitive(PathSensitivity.NONE)
public abstract ConfigurableFileCollection getLibraries();

@Input
public abstract ListProperty<String> getTestLibraries();
@InputFiles
@PathSensitive(PathSensitivity.NONE)
public abstract ConfigurableFileCollection getTestLibraries();

@InputFiles
@PathSensitive(PathSensitivity.NONE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.neoforged.gradle.common.runtime.extensions.CommonRuntimeExtension;
import net.neoforged.gradle.common.runtime.tasks.SourceAccessTransformer;
import net.neoforged.gradle.common.util.CommonRuntimeTaskUtils;
import net.neoforged.gradle.common.util.ProjectUtils;
import net.neoforged.gradle.common.util.constants.RunsConstants;
import net.neoforged.gradle.common.util.run.TypesUtil;
import net.neoforged.gradle.dsl.common.extensions.Mappings;
Expand All @@ -25,6 +26,8 @@
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.artifacts.dsl.DependencyCollector;
import org.gradle.api.file.FileTree;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.TaskProvider;
Expand Down Expand Up @@ -92,9 +95,15 @@ public UserDevRuntimeExtension(Project project) {
spec.setMinecraftVersion(mcpRuntimeDefinition.getSpecification().getMinecraftVersion());

final NamedDomainObjectContainer<Run> runs = (NamedDomainObjectContainer<Run>) getProject().getExtensions().getByName(RunsConstants.Extensions.RUNS);
spec.getProject().afterEvaluate(project -> runs.stream().filter(run -> run.getIsJUnit().get())
.forEach(run -> spec.getProfile().getAdditionalTestDependencyArtifactCoordinates()
.get().forEach(run.getDependencies().get().getRuntime()::add)));
ProjectUtils.afterEvaluate(spec.getProject(), () -> runs.stream()
.filter(run -> run.getIsJUnit().get())
.flatMap(run -> run.getUnitTestSources().get().stream())
.distinct()
.forEach(src -> {
DependencyCollector coll = spec.getProject().getObjects().dependencyCollector();
spec.getProfile().getAdditionalTestDependencyArtifactCoordinates().get().forEach(coll::add);
spec.getProject().getConfigurations().getByName(src.getImplementationConfigurationName()).fromDependencyCollector(coll);
}));

final NamedDomainObjectContainer<RunType> runTypes = (NamedDomainObjectContainer<RunType>) getProject().getExtensions().getByName(RunsConstants.Extensions.RUN_TYPES);
userdevProfile.getRunTypes().forEach((type) -> {
Expand Down

0 comments on commit 9efdc6f

Please sign in to comment.