Skip to content
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 @@ -97,7 +97,7 @@ private static List<FabricModJson> getDependentMods(SpecContextProjectView proje
}
}

return sorted(AsyncCache.joinList(futures));
return distinctSorted(AsyncCache.joinList(futures));
}

private static Stream<Project> getDependentProjects(SpecContextProjectView projectView) {
Expand Down Expand Up @@ -129,6 +129,7 @@ private static List<ModHolder> getCompileRuntimeMods(SpecContextProjectView proj
private static List<ModHolder> getCompileRuntimeModsFromRemapConfigs(SpecContextProjectView projectView, AsyncCache<List<FabricModJson>> fmjCache) {
// A set of mod ids from all remap configurations that are considered for dependency transforms.
final Set<String> runtimeModIds = getModIds(
SpecContextProjectView.ArtifactUsage.RUNTIME,
projectView,
fmjCache,
projectView.extension().getRuntimeRemapConfigurations().stream()
Expand All @@ -138,6 +139,7 @@ private static List<ModHolder> getCompileRuntimeModsFromRemapConfigs(SpecContext
// A set of mod ids that are found on one or more remap configurations that target the common source set.
// Null when split source sets are not enabled, meaning all mods are common.
final Set<String> commonRuntimeModIds = projectView.extension().areEnvironmentSourceSetsSplit() ? getModIds(
SpecContextProjectView.ArtifactUsage.RUNTIME,
projectView,
fmjCache,
projectView.extension().getRuntimeRemapConfigurations().stream()
Expand All @@ -146,6 +148,7 @@ private static List<ModHolder> getCompileRuntimeModsFromRemapConfigs(SpecContext
: null;

Stream<FabricModJson> compileMods = getMods(
SpecContextProjectView.ArtifactUsage.COMPILE,
projectView,
fmjCache,
projectView.extension().getCompileRemapConfigurations().stream()
Expand All @@ -161,14 +164,14 @@ private static List<ModHolder> getCompileRuntimeModsFromRemapConfigs(SpecContext
.toList();
}

private static Stream<FabricModJson> getMods(SpecContextProjectView projectView, AsyncCache<List<FabricModJson>> fmjCache, Stream<RemapConfigurationSettings> stream) {
return stream.flatMap(projectView.resolveArtifacts(true))
private static Stream<FabricModJson> getMods(SpecContextProjectView.ArtifactUsage artifactUsage, SpecContextProjectView projectView, AsyncCache<List<FabricModJson>> fmjCache, Stream<RemapConfigurationSettings> stream) {
return stream.flatMap(projectView.resolveArtifacts(artifactUsage))
.map(modFromZip(fmjCache))
.filter(Objects::nonNull);
}

private static Set<String> getModIds(SpecContextProjectView projectView, AsyncCache<List<FabricModJson>> fmjCache, Stream<RemapConfigurationSettings> stream) {
return getMods(projectView, fmjCache, stream)
private static Set<String> getModIds(SpecContextProjectView.ArtifactUsage artifactUsage, SpecContextProjectView projectView, AsyncCache<List<FabricModJson>> fmjCache, Stream<RemapConfigurationSettings> stream) {
return getMods(artifactUsage, projectView, fmjCache, stream)
.map(FabricModJson::getId)
.collect(Collectors.toSet());
}
Expand Down Expand Up @@ -198,8 +201,11 @@ private static Stream<Project> getCompileRuntimeProjectDependencies(SpecContextP
}

// Sort to ensure stable caching
private static List<FabricModJson> sorted(List<FabricModJson> mods) {
return mods.stream().sorted(Comparator.comparing(FabricModJson::getId)).toList();
private static List<FabricModJson> distinctSorted(List<FabricModJson> mods) {
return mods.stream()
.distinct()
.sorted(Comparator.comparing(FabricModJson::getId))
.toList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,23 @@ public interface SpecContextProjectView {
// Returns a list of Loom Projects found in the specified Configuration
Stream<Project> getLoomProjectDependencies(String name);

Function<RemapConfigurationSettings, Stream<Path>> resolveArtifacts(boolean runtime);
Function<RemapConfigurationSettings, Stream<Path>> resolveArtifacts(ArtifactUsage artifactUsage);

List<FabricModJson> getMods();

boolean disableProjectDependantMods();

enum ArtifactUsage {
RUNTIME(Usage.JAVA_RUNTIME),
COMPILE(Usage.JAVA_API);

private final String gradleUsage;

ArtifactUsage(String gradleUsage) {
this.gradleUsage = gradleUsage;
}
}

record Impl(Project project, LoomGradleExtension extension) implements SpecContextProjectView {
@Override
public Stream<Project> getLoomProjectDependencies(String name) {
Expand All @@ -67,8 +78,8 @@ public Stream<Project> getLoomProjectDependencies(String name) {
}

@Override
public Function<RemapConfigurationSettings, Stream<Path>> resolveArtifacts(boolean runtime) {
final Usage usage = project.getObjects().named(Usage.class, runtime ? Usage.JAVA_RUNTIME : Usage.JAVA_API);
public Function<RemapConfigurationSettings, Stream<Path>> resolveArtifacts(ArtifactUsage artifactUsage) {
final Usage usage = project.getObjects().named(Usage.class, artifactUsage.gradleUsage);

return settings -> {
final Configuration configuration = settings.getSourceConfiguration().get().copyRecursive();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class SpecContextTest extends Specification {

when(projectView.extension()).thenReturn(extension)
when(extension.getRemapConfigurations()).thenReturn(remapConfigurations)
when(projectView.resolveArtifacts(true)).thenReturn(resolve(runtimeArtifacts))
when(projectView.resolveArtifacts(false)).thenReturn(resolve(apiArtifacts))
when(projectView.resolveArtifacts(SpecContextProjectView.ArtifactUsage.RUNTIME)).thenReturn(resolve(runtimeArtifacts))
when(projectView.resolveArtifacts(SpecContextProjectView.ArtifactUsage.COMPILE)).thenReturn(resolve(apiArtifacts))

implementation = createConfigurationSettings("implementation")
runtimeOnly = createConfigurationSettings("runtimeOnly")
Expand Down Expand Up @@ -165,7 +165,6 @@ class SpecContextTest extends Specification {
specContext.allMods().size() == 1
}

// TODO I believe this test is testing broken behaviour
def "compile only runtime only dependency"() {
setup:
def test1 = mod("test1")
Expand All @@ -179,11 +178,11 @@ class SpecContextTest extends Specification {
def specContext = SpecContextImpl.create(projectView)

then:
specContext.modDependencies().size() == 2
specContext.modDependencies().size() == 1
specContext.localMods().size() == 0
specContext.modDependenciesCompileRuntime().size() == 0
specContext.modDependenciesCompileRuntime().size() == 1
specContext.modDependenciesCompileRuntimeClient().size() == 0
specContext.allMods().size() == 2
specContext.allMods().size() == 1
}

private void dependencies(Map<Object, List<Path>> files) {
Expand Down