From 5c4d89bd0d9c9813342e6f5d63175db3231a9e2d Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sat, 10 Oct 2020 21:13:12 +0100 Subject: [PATCH] Ugly fix to mercury classpath not having jetbrains annotations --- .../fabricmc/loom/providers/LaunchProvider.java | 5 ++++- .../fabricmc/loom/util/DependencyProvider.java | 4 ++-- .../net/fabricmc/loom/util/SourceRemapper.java | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/providers/LaunchProvider.java b/src/main/java/net/fabricmc/loom/providers/LaunchProvider.java index 8c001d6..3697874 100644 --- a/src/main/java/net/fabricmc/loom/providers/LaunchProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/LaunchProvider.java @@ -40,12 +40,15 @@ import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; import org.gradle.api.Project; +import org.gradle.api.artifacts.Dependency; import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.DependencyProvider; import net.fabricmc.loom.util.RemappedConfigurationEntry; public class LaunchProvider extends DependencyProvider { + public Dependency annotationDependency; + public LaunchProvider(Project project) { super(project); } @@ -77,7 +80,7 @@ public class LaunchProvider extends DependencyProvider { addDependency(Constants.Dependencies.DEV_LAUNCH_INJECTOR + Constants.Dependencies.Versions.DEV_LAUNCH_INJECTOR, "runtimeOnly"); addDependency(Constants.Dependencies.TERMINAL_CONSOLE_APPENDER + Constants.Dependencies.Versions.TERMINAL_CONSOLE_APPENDER, "runtimeOnly"); - addDependency(Constants.Dependencies.JETBRAINS_ANNOTATIONS + Constants.Dependencies.Versions.JETBRAINS_ANNOTATIONS, "compileOnly"); + annotationDependency = addDependency(Constants.Dependencies.JETBRAINS_ANNOTATIONS + Constants.Dependencies.Versions.JETBRAINS_ANNOTATIONS, "compileOnly"); postPopulationScheduler.accept(this::writeRemapClassPath); } diff --git a/src/main/java/net/fabricmc/loom/util/DependencyProvider.java b/src/main/java/net/fabricmc/loom/util/DependencyProvider.java index d1b19e7..10da342 100644 --- a/src/main/java/net/fabricmc/loom/util/DependencyProvider.java +++ b/src/main/java/net/fabricmc/loom/util/DependencyProvider.java @@ -67,12 +67,12 @@ public abstract class DependencyProvider { addDependency(object, "compile"); } - public void addDependency(Object object, String target) { + public Dependency addDependency(Object object, String target) { if (object instanceof File) { object = project.files(object); } - project.getDependencies().add(target, object); + return project.getDependencies().add(target, object); } public void register(LoomDependencyManager dependencyManager) { diff --git a/src/main/java/net/fabricmc/loom/util/SourceRemapper.java b/src/main/java/net/fabricmc/loom/util/SourceRemapper.java index d058675..c0750b0 100644 --- a/src/main/java/net/fabricmc/loom/util/SourceRemapper.java +++ b/src/main/java/net/fabricmc/loom/util/SourceRemapper.java @@ -30,16 +30,19 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.function.Consumer; import org.cadixdev.lorenz.MappingSet; import org.cadixdev.mercury.Mercury; import org.cadixdev.mercury.remapper.MercuryRemapper; import org.gradle.api.Project; +import org.gradle.api.artifacts.Dependency; import org.zeroturnaround.zip.ZipUtil; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.providers.MappingsProvider; +import net.fabricmc.loom.providers.LaunchProvider; import net.fabricmc.loom.util.progress.ProgressLogger; import net.fabricmc.lorenztiny.TinyMappingsReader; import net.fabricmc.mapping.tree.TinyTree; @@ -176,6 +179,18 @@ public class SourceRemapper { m.getClassPath().add(extension.getMinecraftMappedProvider().getMappedJar().toPath()); m.getClassPath().add(extension.getMinecraftMappedProvider().getIntermediaryJar().toPath()); + Dependency annotationDependency = extension.getDependencyManager().getProvider(LaunchProvider.class).annotationDependency; + Set files = project.getConfigurations().getByName("compileOnly") + .files(annotationDependency); + + if (files.size() != 1) { + throw new RuntimeException(String.format("Found %d files for the annotations, expected 1", files.size())); + } + + for (File file : files) { + m.getClassPath().add(file.toPath()); + } + m.getProcessors().add(MercuryRemapper.create(mappings)); return m;