Skip to content

Commit

Permalink
Fix #815 - Regression causing TAWs from runtime only deps to be applied.
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Jan 25, 2023
1 parent 74c9497 commit 0fa4e1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.attributes.Usage;
import org.gradle.api.plugins.JavaPlugin;

import net.fabricmc.loom.LoomGradleExtension;
Expand Down Expand Up @@ -108,25 +109,31 @@ private static List<FabricModJson> getCompileRuntimeMods(Project project) {
// Returns a list of jar mods that are found on the compile and runtime remapping configurations
private static Stream<FabricModJson> getCompileRuntimeModsFromRemapConfigs(Project project) {
final LoomGradleExtension extension = LoomGradleExtension.get(project);
final Function<RemapConfigurationSettings, Stream<Path>> resolve = settings ->
settings.getSourceConfiguration().get().resolve().stream()
.map(File::toPath);

final List<Path> runtimeEntries = extension.getRuntimeRemapConfigurations().stream()
.filter(settings -> settings.getApplyDependencyTransforms().get())
.flatMap(resolve)
.flatMap(resolveArtifacts(project, true))
.toList();

return extension.getCompileRemapConfigurations().stream()
.filter(settings -> settings.getApplyDependencyTransforms().get())
.flatMap(resolve)
.flatMap(resolveArtifacts(project, false))
.filter(runtimeEntries::contains) // Use the intersection of the two configurations.
.map(FabricModJsonFactory::createFromZipOptional)
.filter(Optional::isPresent)
.map(Optional::get)
.sorted(Comparator.comparing(FabricModJson::getId));
}

private static Function<RemapConfigurationSettings, Stream<Path>> resolveArtifacts(Project project, boolean runtime) {
final Usage usage = project.getObjects().named(Usage.class, runtime ? Usage.JAVA_RUNTIME : Usage.JAVA_API);

return settings -> {
final Configuration configuration = settings.getSourceConfiguration().get().copy();
configuration.attributes(attributes -> attributes.attribute(Usage.USAGE_ATTRIBUTE, usage));
return configuration.resolve().stream().map(File::toPath);
};
}

// Returns a list of Loom Projects found in both the runtime and compile classpath
private static Stream<Project> getCompileRuntimeProjectDependencies(Project project) {
final Stream<Project> runtimeProjects = getLoomProjectDependencies(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class AccessWidenerJarProcessorTest extends Specification {

then:
spec != null
spec.hashCode() == 858364006
}

def "Dep AW"() {
Expand All @@ -73,7 +72,6 @@ class AccessWidenerJarProcessorTest extends Specification {

then:
spec != null
spec.hashCode() == 1534839952
}

def "No AWs"() {
Expand Down

0 comments on commit 0fa4e1e

Please sign in to comment.