From 9917f30518b61183c95451a502689300f12523c5 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sat, 26 Sep 2020 18:46:35 +0100 Subject: [PATCH] Export rumtime remap classpath to DLI (#277) * Export rumtime remap classpath for https://github.com/FabricMC/fabric-loader/pull/241 * Fix bad merge --- .../loom/providers/LaunchProvider.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/net/fabricmc/loom/providers/LaunchProvider.java b/src/main/java/net/fabricmc/loom/providers/LaunchProvider.java index 2bc52bd..8c001d6 100644 --- a/src/main/java/net/fabricmc/loom/providers/LaunchProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/LaunchProvider.java @@ -36,12 +36,14 @@ import java.util.List; import java.util.Map; import java.util.StringJoiner; import java.util.function.Consumer; +import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; import org.gradle.api.Project; import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.DependencyProvider; +import net.fabricmc.loom.util.RemappedConfigurationEntry; public class LaunchProvider extends DependencyProvider { public LaunchProvider(Project project) { @@ -52,6 +54,7 @@ public class LaunchProvider extends DependencyProvider { public void provide(DependencyInfo dependency, Consumer postPopulationScheduler) throws IOException { final LaunchConfig launchConfig = new LaunchConfig() .property("fabric.development", "true") + .property("fabric.remapClasspathFile", getRemapClasspathFile().getAbsolutePath()) .property("log4j.configurationFile", getLog4jConfigFile().getAbsolutePath()) .property("client", "java.library.path", getExtension().getNativesDirectory().getAbsolutePath()) @@ -75,12 +78,18 @@ 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"); + + postPopulationScheduler.accept(this::writeRemapClassPath); } private File getLog4jConfigFile() { return new File(getExtension().getDevLauncherConfig().getParentFile(), "log4j.xml"); } + private File getRemapClasspathFile() { + return new File(getExtension().getDevLauncherConfig().getParentFile(), "remapClasspath.txt"); + } + private void writeLog4jConfig() { try (InputStream is = LaunchProvider.class.getClassLoader().getResourceAsStream("log4j2.fabric.xml")) { Files.deleteIfExists(getLog4jConfigFile().toPath()); @@ -90,6 +99,30 @@ public class LaunchProvider extends DependencyProvider { } } + private void writeRemapClassPath() { + List inputConfigurations = new ArrayList<>(); + inputConfigurations.add(Constants.Configurations.MINECRAFT_DEPENDENCIES); + inputConfigurations.addAll(Constants.MOD_COMPILE_ENTRIES.stream().map(RemappedConfigurationEntry::getSourceConfiguration).collect(Collectors.toList())); + + List remapClasspath = new ArrayList<>(); + + for (String inputConfiguration : inputConfigurations) { + remapClasspath.addAll(getProject().getConfigurations().getByName(inputConfiguration).getFiles()); + } + + remapClasspath.add(getExtension().getMinecraftMappedProvider().getIntermediaryJar()); + + String str = remapClasspath.stream() + .map(File::getAbsolutePath) + .collect(Collectors.joining(File.pathSeparator)); + + try { + Files.write(getRemapClasspathFile().toPath(), str.getBytes(StandardCharsets.UTF_8)); + } catch (IOException e) { + throw new RuntimeException("Failed to generate remap classpath", e); + } + } + @Override public String getTargetConfig() { return Constants.Configurations.MINECRAFT_NAMED;