diff --git a/build.gradle b/build.gradle index caf97f102..d7cc36548 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,10 @@ dependencies { transitive = false } + implementation ('net.fabricmc:lorenz-tiny:1.0.0+build.1') { + transitive = false + } + // decompilers implementation ('net.fabricmc:procyon-fabric-compilertools:0.5.35.+') implementation ('org.jetbrains:intellij-fernflower:1.1.0.11') diff --git a/src/main/java/net/fabricmc/loom/AbstractPlugin.java b/src/main/java/net/fabricmc/loom/AbstractPlugin.java index 68e7cf815..63375364d 100644 --- a/src/main/java/net/fabricmc/loom/AbstractPlugin.java +++ b/src/main/java/net/fabricmc/loom/AbstractPlugin.java @@ -50,7 +50,6 @@ import org.gradle.api.tasks.compile.JavaCompile; import org.gradle.api.tasks.javadoc.Javadoc; import org.gradle.api.tasks.scala.ScalaCompile; -import org.gradle.plugins.ide.eclipse.model.EclipseModel; import org.gradle.plugins.ide.idea.model.IdeaModel; import net.fabricmc.loom.providers.LaunchProvider; @@ -100,8 +99,6 @@ public void apply(Project target) { Configuration minecraftNamedConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT_NAMED); minecraftNamedConfig.setTransitive(false); // The launchers do not recurse dependencies - Configuration minecraftIntermediaryConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT_INTERMEDIARY); - minecraftIntermediaryConfig.setTransitive(false); Configuration minecraftDependenciesConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT_DEPENDENCIES); minecraftDependenciesConfig.setTransitive(false); Configuration minecraftConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT); @@ -135,7 +132,6 @@ public void apply(Project target) { } extendsFrom(Constants.MINECRAFT_NAMED, Constants.MINECRAFT_DEPENDENCIES); - extendsFrom(Constants.MINECRAFT_INTERMEDIARY, Constants.MINECRAFT_DEPENDENCIES); extendsFrom("compile", Constants.MAPPINGS_FINAL); @@ -224,9 +220,6 @@ protected void configureIDEs() { ideaModel.getModule().setDownloadJavadoc(true); ideaModel.getModule().setDownloadSources(true); ideaModel.getModule().setInheritOutputDirs(true); - - // ECLIPSE - EclipseModel eclipseModel = (EclipseModel) project.getExtensions().getByName("eclipse"); } /** @@ -236,7 +229,6 @@ protected void configureCompile() { JavaPluginConvention javaModule = (JavaPluginConvention) project.getConvention().getPlugins().get("java"); SourceSet main = javaModule.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); - SourceSet test = javaModule.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME); Javadoc javadoc = (Javadoc) project.getTasks().getByName(JavaPlugin.JAVADOC_TASK_NAME); javadoc.setClasspath(main.getOutput().plus(main.getCompileClasspath())); @@ -249,11 +241,6 @@ protected void configureCompile() { project.afterEvaluate(project1 -> { LoomGradleExtension extension = project1.getExtensions().getByType(LoomGradleExtension.class); - project1.getRepositories().flatDir(flatDirectoryArtifactRepository -> { - flatDirectoryArtifactRepository.dir(extension.getUserCache()); - flatDirectoryArtifactRepository.setName("UserCacheFiles"); - }); - project1.getRepositories().flatDir(flatDirectoryArtifactRepository -> { flatDirectoryArtifactRepository.dir(extension.getRootProjectBuildCache()); flatDirectoryArtifactRepository.setName("UserLocalCacheFiles"); @@ -269,11 +256,6 @@ protected void configureCompile() { mavenArtifactRepository.setUrl("https://maven.fabricmc.net/"); }); - /* project1.getRepositories().maven(mavenArtifactRepository -> { - mavenArtifactRepository.setName("SpongePowered"); - mavenArtifactRepository.setUrl("http://repo.spongepowered.org/maven"); - }); */ - project1.getRepositories().maven(mavenArtifactRepository -> { mavenArtifactRepository.setName("Mojang"); mavenArtifactRepository.setUrl("https://libraries.minecraft.net/"); @@ -285,9 +267,9 @@ protected void configureCompile() { LoomDependencyManager dependencyManager = new LoomDependencyManager(); extension.setDependencyManager(dependencyManager); - dependencyManager.addProvider(new MinecraftProvider()); - dependencyManager.addProvider(new MappingsProvider()); - dependencyManager.addProvider(new LaunchProvider()); + dependencyManager.addProvider(new MinecraftProvider(getProject())); + dependencyManager.addProvider(new MappingsProvider(getProject())); + dependencyManager.addProvider(new LaunchProvider(getProject())); dependencyManager.handleDependencies(project1); diff --git a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java index bbef92411..a86738094 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java +++ b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java @@ -45,6 +45,7 @@ import org.gradle.api.artifacts.Dependency; import org.gradle.api.plugins.BasePluginConvention; +import net.fabricmc.loom.processors.JarProcessorManager; import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.providers.MinecraftMappedProvider; import net.fabricmc.loom.providers.MinecraftProvider; @@ -58,12 +59,14 @@ public class LoomGradleExtension { public boolean autoGenIDERuns = true; public boolean extractJars = false; public String customManifest = null; + public File accessWidener = null; private List unmappedModsBuilt = new ArrayList<>(); //Not to be set in the build.gradle private Project project; private LoomDependencyManager dependencyManager; + private JarProcessorManager jarProcessorManager; private JsonObject installerJson; private MappingSet[] srcMappingCache = new MappingSet[2]; private Mercury[] srcMercuryCache = new Mercury[2]; @@ -116,6 +119,16 @@ public File getRootProjectPersistentCache() { return projectCache; } + public File getProjectPersistentCache() { + File projectCache = new File(project.file(".gradle"), "loom-cache"); + + if (!projectCache.exists()) { + projectCache.mkdirs(); + } + + return projectCache; + } + public File getRootProjectBuildCache() { File projectCache = new File(project.getRootProject().getBuildDir(), "loom-cache"); @@ -167,7 +180,7 @@ public File getNativesJarStore() { } public File getNativesDirectory() { - File natives = new File(getUserCache(), "natives/" + getMinecraftProvider().minecraftVersion); + File natives = new File(getUserCache(), "natives/" + getMinecraftProvider().getMinecraftVersion()); if (!natives.exists()) { natives.mkdirs(); @@ -283,6 +296,14 @@ public void setDependencyManager(LoomDependencyManager dependencyManager) { this.dependencyManager = dependencyManager; } + public JarProcessorManager getJarProcessorManager() { + return jarProcessorManager; + } + + public void setJarProcessorManager(JarProcessorManager jarProcessorManager) { + this.jarProcessorManager = jarProcessorManager; + } + public String getRefmapName() { if (refmapName == null || refmapName.isEmpty()) { String defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json"; diff --git a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java index 624fabde0..ca31004c1 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java +++ b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java @@ -52,7 +52,7 @@ import net.fabricmc.loom.task.fernflower.FernFlowerTask; public class LoomGradlePlugin extends AbstractPlugin { - private static File getMappedByproduct(Project project, String suffix) { + public static File getMappedByproduct(Project project, String suffix) { LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); MappingsProvider mappingsProvider = extension.getMappingsProvider(); File mappedJar = mappingsProvider.mappedProvider.getMappedJar(); @@ -108,7 +108,7 @@ public void apply(Project target) { Project project = this.getProject(); LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); - MinecraftLibraryProvider libraryProvider = extension.getMinecraftProvider().libraryProvider; + MinecraftLibraryProvider libraryProvider = extension.getMinecraftProvider().getLibraryProvider(); MappingsProvider mappingsProvider = extension.getMappingsProvider(); File mappedJar = mappingsProvider.mappedProvider.getMappedJar(); File linemappedJar = getMappedByproduct(project, "-linemapped.jar"); diff --git a/src/main/java/net/fabricmc/loom/processors/JarProcessor.java b/src/main/java/net/fabricmc/loom/processors/JarProcessor.java new file mode 100644 index 000000000..59bd5485d --- /dev/null +++ b/src/main/java/net/fabricmc/loom/processors/JarProcessor.java @@ -0,0 +1,37 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2016, 2017, 2018 FabricMC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package net.fabricmc.loom.processors; + +import java.io.File; + +import org.gradle.api.Project; + +public interface JarProcessor { + void setup(Project project); + + void process(File file); + + boolean isInvalid(File file); +} diff --git a/src/main/java/net/fabricmc/loom/processors/JarProcessorManager.java b/src/main/java/net/fabricmc/loom/processors/JarProcessorManager.java new file mode 100644 index 000000000..b71efdad6 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/processors/JarProcessorManager.java @@ -0,0 +1,78 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2016, 2017, 2018 FabricMC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package net.fabricmc.loom.processors; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.gradle.api.Project; + +import net.fabricmc.loom.LoomGradleExtension; + +public class JarProcessorManager { + private final Project project; + private final LoomGradleExtension extension; + + private final List jarProcessors; + + public JarProcessorManager(Project project) { + this.project = project; + this.extension = project.getExtensions().getByType(LoomGradleExtension.class); + jarProcessors = setupProcessors(); + } + + //TODO possibly expand via an API? + private List setupProcessors() { + List jarProcessors = new ArrayList<>(); + + jarProcessors.forEach(jarProcessor -> jarProcessor.setup(project)); + return Collections.unmodifiableList(jarProcessors); + } + + public boolean active() { + return !jarProcessors.isEmpty(); + } + + public boolean isInvalid(File file) { + if (!file.exists()) { + return true; + } + + return jarProcessors.stream().anyMatch(jarProcessor -> jarProcessor.isInvalid(file)); + } + + public void process(File file) { + for (JarProcessor jarProcessor : jarProcessors) { + jarProcessor.process(file); + } + } + + public T getByType(Class tClass) { + //noinspection unchecked + return (T) jarProcessors.stream().filter(jarProcessor -> jarProcessor.getClass().equals(tClass)).findFirst().orElse(null); + } +} diff --git a/src/main/java/net/fabricmc/loom/processors/MinecraftProcessedProvider.java b/src/main/java/net/fabricmc/loom/processors/MinecraftProcessedProvider.java new file mode 100644 index 000000000..d4c966529 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/processors/MinecraftProcessedProvider.java @@ -0,0 +1,97 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2016, 2017, 2018 FabricMC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package net.fabricmc.loom.processors; + +import java.io.File; +import java.io.IOException; +import java.util.function.Consumer; + +import org.apache.commons.io.FileUtils; +import org.gradle.api.Project; + +import net.fabricmc.loom.providers.MappingsProvider; +import net.fabricmc.loom.providers.MinecraftMappedProvider; +import net.fabricmc.loom.providers.MinecraftProvider; +import net.fabricmc.loom.util.Constants; + +public class MinecraftProcessedProvider extends MinecraftMappedProvider { + public static final String PROJECT_MAPPED_CLASSIFIER = "projectmapped"; + + private File projectMappedJar; + + private final JarProcessorManager jarProcessorManager; + + public MinecraftProcessedProvider(Project project, JarProcessorManager jarProcessorManager) { + super(project); + this.jarProcessorManager = jarProcessorManager; + } + + @Override + protected void addDependencies(DependencyInfo dependency, Consumer postPopulationScheduler) { + if (jarProcessorManager.isInvalid(projectMappedJar)) { + getProject().getLogger().lifecycle(":processing mapped jar"); + invalidateJars(); + + try { + FileUtils.copyFile(super.getMappedJar(), projectMappedJar); + } catch (IOException e) { + throw new RuntimeException("Failed to copy source jar", e); + } + + jarProcessorManager.process(projectMappedJar); + } + + getProject().getRepositories().flatDir(repository -> repository.dir(getJarDirectory(getExtension().getProjectPersistentCache(), PROJECT_MAPPED_CLASSIFIER))); + + getProject().getDependencies().add(Constants.MINECRAFT_NAMED, + getProject().getDependencies().module("net.minecraft:minecraft:" + getJarVersionString(PROJECT_MAPPED_CLASSIFIER))); + } + + private void invalidateJars() { + File dir = getJarDirectory(getExtension().getUserCache(), PROJECT_MAPPED_CLASSIFIER); + + if (dir.exists()) { + getProject().getLogger().warn("Invalidating project jars"); + + try { + FileUtils.cleanDirectory(dir); + } catch (IOException e) { + throw new RuntimeException("Failed to invalidate jars, try stopping gradle daemon or closing the game", e); + } + } + } + + @Override + public void initFiles(MinecraftProvider minecraftProvider, MappingsProvider mappingsProvider) { + super.initFiles(minecraftProvider, mappingsProvider); + + projectMappedJar = new File(getJarDirectory(getExtension().getProjectPersistentCache(), PROJECT_MAPPED_CLASSIFIER), "minecraft-" + getJarVersionString(PROJECT_MAPPED_CLASSIFIER) + ".jar"); + } + + @Override + public File getMappedJar() { + return projectMappedJar; + } +} diff --git a/src/main/java/net/fabricmc/loom/providers/LaunchProvider.java b/src/main/java/net/fabricmc/loom/providers/LaunchProvider.java index 65a982528..c4be38774 100644 --- a/src/main/java/net/fabricmc/loom/providers/LaunchProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/LaunchProvider.java @@ -37,27 +37,30 @@ import org.apache.commons.io.FileUtils; import org.gradle.api.Project; -import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.DependencyProvider; public class LaunchProvider extends DependencyProvider { + public LaunchProvider(Project project) { + super(project); + } + @Override - public void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension, Consumer postPopulationScheduler) throws IOException { + public void provide(DependencyInfo dependency, Consumer postPopulationScheduler) throws IOException { final LaunchConfig launchConfig = new LaunchConfig() .property("fabric.development", "true") - .property("client", "java.library.path", extension.getNativesDirectory().getAbsolutePath()) - .property("client", "org.lwjgl.librarypath", extension.getNativesDirectory().getAbsolutePath()) + .property("client", "java.library.path", getExtension().getNativesDirectory().getAbsolutePath()) + .property("client", "org.lwjgl.librarypath", getExtension().getNativesDirectory().getAbsolutePath()) .argument("client", "--assetIndex") - .argument("client", extension.getMinecraftProvider().versionInfo.assetIndex.getFabricId(extension.getMinecraftProvider().minecraftVersion)) + .argument("client", getExtension().getMinecraftProvider().getVersionInfo().assetIndex.getFabricId(getExtension().getMinecraftProvider().getMinecraftVersion())) .argument("client", "--assetsDir") - .argument("client", new File(extension.getUserCache(), "assets").getAbsolutePath()); + .argument("client", new File(getExtension().getUserCache(), "assets").getAbsolutePath()); - FileUtils.writeStringToFile(extension.getDevLauncherConfig(), launchConfig.asString(), StandardCharsets.UTF_8); + FileUtils.writeStringToFile(getExtension().getDevLauncherConfig(), launchConfig.asString(), StandardCharsets.UTF_8); - addDependency("net.fabricmc:dev-launch-injector:" + Constants.DEV_LAUNCH_INJECTOR_VERSION, project, "runtimeOnly"); + addDependency("net.fabricmc:dev-launch-injector:" + Constants.DEV_LAUNCH_INJECTOR_VERSION, "runtimeOnly"); } @Override diff --git a/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java b/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java index fa7137784..887f3f7eb 100644 --- a/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java @@ -44,7 +44,6 @@ import org.zeroturnaround.zip.ZipEntrySource; import org.zeroturnaround.zip.ZipUtil; -import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.DependencyProvider; import net.fabricmc.loom.util.DownloadUtil; @@ -54,6 +53,8 @@ import net.fabricmc.stitch.commands.CommandProposeFieldNames; import net.fabricmc.stitch.commands.tinyv2.CommandMergeTinyV2; import net.fabricmc.stitch.commands.tinyv2.CommandReorderTinyV2; +import net.fabricmc.loom.processors.JarProcessorManager; +import net.fabricmc.loom.processors.MinecraftProcessedProvider; public class MappingsProvider extends DependencyProvider { public MinecraftMappedProvider mappedProvider; @@ -71,6 +72,10 @@ public class MappingsProvider extends DependencyProvider { public File tinyMappingsJar; public File mappingsMixinExport; + public MappingsProvider(Project project) { + super(project); + } + public void clean() throws IOException { FileUtils.deleteDirectory(mappingsDir.toFile()); } @@ -80,10 +85,10 @@ public TinyTree getMappings() throws IOException { } @Override - public void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension, Consumer postPopulationScheduler) throws Exception { + public void provide(DependencyInfo dependency, Consumer postPopulationScheduler) throws Exception { MinecraftProvider minecraftProvider = getDependencyManager().getProvider(MinecraftProvider.class); - project.getLogger().lifecycle(":setting up mappings (" + dependency.getDependency().getName() + " " + dependency.getResolvedVersion() + ")"); + getProject().getLogger().lifecycle(":setting up mappings (" + dependency.getDependency().getName() + " " + dependency.getResolvedVersion() + ")"); String version = dependency.getResolvedVersion(); File mappingsJar = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not find yarn mappings: " + dependency)); @@ -92,10 +97,10 @@ public void provide(DependencyInfo dependency, Project project, LoomGradleExtens boolean isV2 = doesJarContainV2Mappings(mappingsJar.toPath()); - this.minecraftVersion = minecraftProvider.minecraftVersion; + this.minecraftVersion = minecraftProvider.getMinecraftVersion(); this.mappingsVersion = version + (isV2 ? "-v2" : ""); - initFiles(project); + initFiles(); Files.createDirectories(mappingsDir); Files.createDirectories(mappingsStepsDir); @@ -108,21 +113,30 @@ public void provide(DependencyInfo dependency, Project project, LoomGradleExtens } tinyMappings = mappingsDir.resolve(StringUtils.removeSuffix(mappingsJar.getName(), ".jar") + ".tiny").toFile(); - tinyMappingsJar = new File(extension.getUserCache(), mappingsJar.getName().replace(".jar", "-" + jarClassifier + ".jar")); + tinyMappingsJar = new File(getExtension().getUserCache(), mappingsJar.getName().replace(".jar", "-" + jarClassifier + ".jar")); if (!tinyMappings.exists()) { - storeMappings(project, minecraftProvider, mappingsJar.toPath()); + storeMappings(getProject(), minecraftProvider, mappingsJar.toPath()); } if (!tinyMappingsJar.exists()) { ZipUtil.pack(new ZipEntrySource[] {new FileSource("mappings/mappings.tiny", tinyMappings)}, tinyMappingsJar); } - addDependency(tinyMappingsJar, project, Constants.MAPPINGS_FINAL); + addDependency(tinyMappingsJar, Constants.MAPPINGS_FINAL); + + JarProcessorManager processorManager = new JarProcessorManager(getProject()); + getExtension().setJarProcessorManager(processorManager); + + if (processorManager.active()) { + mappedProvider = new MinecraftProcessedProvider(getProject(), processorManager); + getProject().getLogger().lifecycle("Using project based jar storage"); + } else { + mappedProvider = new MinecraftMappedProvider(getProject()); + } - mappedProvider = new MinecraftMappedProvider(); - mappedProvider.initFiles(project, minecraftProvider, this); - mappedProvider.provide(dependency, project, extension, postPopulationScheduler); + mappedProvider.initFiles(minecraftProvider, this); + mappedProvider.provide(dependency, postPopulationScheduler); } private void storeMappings(Project project, MinecraftProvider minecraftProvider, Path yarnJar) throws IOException { @@ -225,7 +239,7 @@ private void mergeMappings(Path intermediaryMappings, Path yarnMappings, Path ne private void suggestFieldNames(MinecraftProvider minecraftProvider, Path oldMappings, Path newMappings) { Command command = new CommandProposeFieldNames(); - runCommand(command, minecraftProvider.MINECRAFT_MERGED_JAR.getAbsolutePath(), + runCommand(command, minecraftProvider.getMergedJar().getAbsolutePath(), oldMappings.toAbsolutePath().toString(), newMappings.toAbsolutePath().toString()); } @@ -238,13 +252,12 @@ private void runCommand(Command command, String... args) { } } - private void initFiles(Project project) { - LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); - mappingsDir = extension.getUserCache().toPath().resolve("mappings"); + private void initFiles() { + mappingsDir = getExtension().getUserCache().toPath().resolve("mappings"); mappingsStepsDir = mappingsDir.resolve("steps"); baseTinyMappings = mappingsDir.resolve(mappingsName + "-tiny-" + minecraftVersion + "-" + mappingsVersion + "-base"); - mappingsMixinExport = new File(extension.getProjectBuildCache(), "mixin-map-" + minecraftVersion + "-" + mappingsVersion + ".tiny"); + mappingsMixinExport = new File(getExtension().getProjectBuildCache(), "mixin-map-" + minecraftVersion + "-" + mappingsVersion + ".tiny"); } @Override diff --git a/src/main/java/net/fabricmc/loom/providers/MinecraftAssetsProvider.java b/src/main/java/net/fabricmc/loom/providers/MinecraftAssetsProvider.java index 16b9dfa4e..3f2e39d9c 100644 --- a/src/main/java/net/fabricmc/loom/providers/MinecraftAssetsProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MinecraftAssetsProvider.java @@ -53,7 +53,7 @@ public static void provide(MinecraftProvider minecraftProvider, Project project) LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); boolean offline = project.getGradle().getStartParameter().isOffline(); - MinecraftVersionInfo versionInfo = minecraftProvider.versionInfo; + MinecraftVersionInfo versionInfo = minecraftProvider.getVersionInfo(); MinecraftVersionInfo.AssetIndex assetIndex = versionInfo.assetIndex; // get existing cache files @@ -63,7 +63,7 @@ public static void provide(MinecraftProvider minecraftProvider, Project project) assets.mkdirs(); } - File assetsInfo = new File(assets, "indexes" + File.separator + assetIndex.getFabricId(minecraftProvider.minecraftVersion) + ".json"); + File assetsInfo = new File(assets, "indexes" + File.separator + assetIndex.getFabricId(minecraftProvider.getMinecraftVersion()) + ".json"); if (!assetsInfo.exists() || !Checksum.equals(assetsInfo, assetIndex.sha1)) { project.getLogger().lifecycle(":downloading asset index"); diff --git a/src/main/java/net/fabricmc/loom/providers/MinecraftLibraryProvider.java b/src/main/java/net/fabricmc/loom/providers/MinecraftLibraryProvider.java index 59583190f..7255acb4e 100644 --- a/src/main/java/net/fabricmc/loom/providers/MinecraftLibraryProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MinecraftLibraryProvider.java @@ -42,7 +42,7 @@ public class MinecraftLibraryProvider { public void provide(MinecraftProvider minecraftProvider, Project project) throws IOException { LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); - MinecraftVersionInfo versionInfo = minecraftProvider.versionInfo; + MinecraftVersionInfo versionInfo = minecraftProvider.getVersionInfo(); initFiles(project, minecraftProvider); diff --git a/src/main/java/net/fabricmc/loom/providers/MinecraftMappedProvider.java b/src/main/java/net/fabricmc/loom/providers/MinecraftMappedProvider.java index 3a398a867..a584e19a5 100644 --- a/src/main/java/net/fabricmc/loom/providers/MinecraftMappedProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MinecraftMappedProvider.java @@ -30,80 +30,82 @@ import org.gradle.api.Project; -import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.DependencyProvider; import net.fabricmc.loom.util.MapJarsTiny; public class MinecraftMappedProvider extends DependencyProvider { - public File MINECRAFT_MAPPED_JAR; - public File MINECRAFT_INTERMEDIARY_JAR; - - public MinecraftMappedProvider() { - } + private File minecraftMappedJar; + private File minecraftIntermediaryJar; private MinecraftProvider minecraftProvider; + public MinecraftMappedProvider(Project project) { + super(project); + } + @Override - public void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension, Consumer postPopulationScheduler) throws Exception { - if (!extension.getMappingsProvider().tinyMappings.exists()) { + public void provide(DependencyInfo dependency, Consumer postPopulationScheduler) throws Exception { + if (!getExtension().getMappingsProvider().tinyMappings.exists()) { throw new RuntimeException("mappings file not found"); } - if (!extension.getMinecraftProvider().getMergedJar().exists()) { + if (!getExtension().getMinecraftProvider().getMergedJar().exists()) { throw new RuntimeException("input merged jar not found"); } - if (!getMappedJar().exists() || !getIntermediaryJar().exists()) { - if (getMappedJar().exists()) { - getMappedJar().delete(); + if (!minecraftMappedJar.exists() || !getIntermediaryJar().exists()) { + if (minecraftMappedJar.exists()) { + minecraftMappedJar.delete(); } - if (getIntermediaryJar().exists()) { - getIntermediaryJar().delete(); + minecraftMappedJar.getParentFile().mkdirs(); + + if (minecraftIntermediaryJar.exists()) { + minecraftIntermediaryJar.delete(); } - new MapJarsTiny().mapJars(minecraftProvider, this, project); + new MapJarsTiny().mapJars(minecraftProvider, this, this.minecraftMappedJar, this.minecraftIntermediaryJar, getProject()); } - if (!MINECRAFT_MAPPED_JAR.exists()) { + if (!minecraftMappedJar.exists()) { throw new RuntimeException("mapped jar not found"); } - MappingsProvider mappingsProvider = extension.getMappingsProvider(); - project.getDependencies().add(Constants.MINECRAFT_NAMED, - project.getDependencies().module("net.minecraft:minecraft:" + getNamedJarVersionString(mappingsProvider.mappingsName, mappingsProvider.mappingsVersion))); - project.getDependencies().add(Constants.MINECRAFT_INTERMEDIARY, - project.getDependencies().module("net.minecraft:minecraft:" + getIntermediaryJarVersionString(mappingsProvider.mappingsName, mappingsProvider.mappingsVersion))); + addDependencies(dependency, postPopulationScheduler); + } + + protected void addDependencies(DependencyInfo dependency, Consumer postPopulationScheduler) { + getProject().getRepositories().flatDir(repository -> repository.dir(getJarDirectory(getExtension().getUserCache(), "mapped"))); + + getProject().getDependencies().add(Constants.MINECRAFT_NAMED, + getProject().getDependencies().module("net.minecraft:minecraft:" + getJarVersionString("mapped"))); } - public void initFiles(Project project, MinecraftProvider minecraftProvider, MappingsProvider mappingsProvider) { - LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); + public void initFiles(MinecraftProvider minecraftProvider, MappingsProvider mappingsProvider) { this.minecraftProvider = minecraftProvider; - MINECRAFT_INTERMEDIARY_JAR = new File(extension.getUserCache(), - "minecraft-" + getIntermediaryJarVersionString(mappingsProvider.mappingsName, mappingsProvider.mappingsVersion) + ".jar"); - MINECRAFT_MAPPED_JAR = new File(extension.getUserCache(), - "minecraft-" + getNamedJarVersionString(mappingsProvider.mappingsName, mappingsProvider.mappingsVersion) + ".jar"); + minecraftIntermediaryJar = new File(getExtension().getUserCache(), "minecraft-" + getJarVersionString("intermediary") + ".jar"); + minecraftMappedJar = new File(getJarDirectory(getExtension().getUserCache(), "mapped"), "minecraft-" + getJarVersionString("mapped") + ".jar"); } - private String getNamedJarVersionString(String mappingsName, String mappingsVersion) { - return minecraftProvider.minecraftVersion + "-mapped-" + mappingsName + "-" + mappingsVersion; + protected File getJarDirectory(File parentDirectory, String type) { + return new File(parentDirectory, getJarVersionString(type)); } - private String getIntermediaryJarVersionString(String mappingsName, String mappingsVersion) { - return minecraftProvider.minecraftVersion + "-intermediary-" + mappingsName + "-" + mappingsVersion; + protected String getJarVersionString(String type) { + return String.format("%s-%s-%s-%s", minecraftProvider.getMinecraftVersion(), type, getExtension().getMappingsProvider().mappingsName, getExtension().getMappingsProvider().mappingsVersion); } public Collection getMapperPaths() { - return minecraftProvider.libraryProvider.getLibraries(); + return minecraftProvider.getLibraryProvider().getLibraries(); } public File getIntermediaryJar() { - return MINECRAFT_INTERMEDIARY_JAR; + return minecraftIntermediaryJar; } public File getMappedJar() { - return MINECRAFT_MAPPED_JAR; + return minecraftMappedJar; } @Override diff --git a/src/main/java/net/fabricmc/loom/providers/MinecraftNativesProvider.java b/src/main/java/net/fabricmc/loom/providers/MinecraftNativesProvider.java index 34f3a0b9d..fbd032d48 100644 --- a/src/main/java/net/fabricmc/loom/providers/MinecraftNativesProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MinecraftNativesProvider.java @@ -38,7 +38,7 @@ public class MinecraftNativesProvider { public static void provide(MinecraftProvider minecraftProvider, Project project) throws IOException { LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); - MinecraftVersionInfo versionInfo = minecraftProvider.versionInfo; + MinecraftVersionInfo versionInfo = minecraftProvider.getVersionInfo(); File nativesDir = extension.getNativesDirectory(); File jarStore = extension.getNativesJarStore(); diff --git a/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java b/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java index 2fca2f46d..860d9df32 100644 --- a/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MinecraftProvider.java @@ -40,7 +40,6 @@ import org.gradle.api.Project; import org.gradle.api.logging.Logger; -import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.util.Checksum; import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.DependencyProvider; @@ -51,86 +50,88 @@ import net.fabricmc.stitch.merge.JarMerger; public class MinecraftProvider extends DependencyProvider { - public String minecraftVersion; + private String minecraftVersion; - public MinecraftVersionInfo versionInfo; - public MinecraftLibraryProvider libraryProvider; + private MinecraftVersionInfo versionInfo; + private MinecraftLibraryProvider libraryProvider; - File MINECRAFT_JSON; - File MINECRAFT_CLIENT_JAR; - File MINECRAFT_SERVER_JAR; - File MINECRAFT_MERGED_JAR; + private File minecraftJson; + private File minecraftClientJar; + private File minecraftServerJar; + private File minecraftMergedJar; Gson gson = new Gson(); + public MinecraftProvider(Project project) { + super(project); + } + @Override - public void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension, Consumer postPopulationScheduler) throws Exception { + public void provide(DependencyInfo dependency, Consumer postPopulationScheduler) throws Exception { minecraftVersion = dependency.getDependency().getVersion(); - boolean offline = project.getGradle().getStartParameter().isOffline(); + boolean offline = getProject().getGradle().getStartParameter().isOffline(); - initFiles(project); + initFiles(); - downloadMcJson(project, offline); + downloadMcJson(offline); - try (FileReader reader = new FileReader(MINECRAFT_JSON)) { + try (FileReader reader = new FileReader(minecraftJson)) { versionInfo = gson.fromJson(reader, MinecraftVersionInfo.class); } // Add Loom as an annotation processor - addDependency(project.files(this.getClass().getProtectionDomain().getCodeSource().getLocation()), project, "compileOnly"); + addDependency(getProject().files(this.getClass().getProtectionDomain().getCodeSource().getLocation()), "compileOnly"); if (offline) { - if (MINECRAFT_CLIENT_JAR.exists() && MINECRAFT_SERVER_JAR.exists()) { - project.getLogger().debug("Found client and server jars, presuming up-to-date"); - } else if (MINECRAFT_MERGED_JAR.exists()) { + if (minecraftClientJar.exists() && minecraftServerJar.exists()) { + getProject().getLogger().debug("Found client and server jars, presuming up-to-date"); + } else if (minecraftMergedJar.exists()) { //Strictly we don't need the split jars if the merged one exists, let's try go on - project.getLogger().warn("Missing game jar but merged jar present, things might end badly"); + getProject().getLogger().warn("Missing game jar but merged jar present, things might end badly"); } else { - throw new GradleException("Missing jar(s); Client: " + MINECRAFT_CLIENT_JAR.exists() + ", Server: " + MINECRAFT_SERVER_JAR.exists()); + throw new GradleException("Missing jar(s); Client: " + minecraftClientJar.exists() + ", Server: " + minecraftServerJar.exists()); } } else { - downloadJars(project.getLogger()); + downloadJars(getProject().getLogger()); } libraryProvider = new MinecraftLibraryProvider(); - libraryProvider.provide(this, project); + libraryProvider.provide(this, getProject()); - if (!MINECRAFT_MERGED_JAR.exists()) { + if (!minecraftMergedJar.exists()) { try { - mergeJars(project.getLogger()); + mergeJars(getProject().getLogger()); } catch (ZipError e) { - DownloadUtil.delete(MINECRAFT_CLIENT_JAR); - DownloadUtil.delete(MINECRAFT_SERVER_JAR); + DownloadUtil.delete(minecraftClientJar); + DownloadUtil.delete(minecraftServerJar); - project.getLogger().error("Could not merge JARs! Deleting source JARs - please re-run the command and move on.", e); + getProject().getLogger().error("Could not merge JARs! Deleting source JARs - please re-run the command and move on.", e); throw new RuntimeException(); } } } - private void initFiles(Project project) { - LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); - MINECRAFT_JSON = new File(extension.getUserCache(), "minecraft-" + minecraftVersion + "-info.json"); - MINECRAFT_CLIENT_JAR = new File(extension.getUserCache(), "minecraft-" + minecraftVersion + "-client.jar"); - MINECRAFT_SERVER_JAR = new File(extension.getUserCache(), "minecraft-" + minecraftVersion + "-server.jar"); - MINECRAFT_MERGED_JAR = new File(extension.getUserCache(), "minecraft-" + minecraftVersion + "-merged.jar"); + private void initFiles() { + minecraftJson = new File(getExtension().getUserCache(), "minecraft-" + minecraftVersion + "-info.json"); + minecraftClientJar = new File(getExtension().getUserCache(), "minecraft-" + minecraftVersion + "-client.jar"); + minecraftServerJar = new File(getExtension().getUserCache(), "minecraft-" + minecraftVersion + "-server.jar"); + minecraftMergedJar = new File(getExtension().getUserCache(), "minecraft-" + minecraftVersion + "-merged.jar"); } - private void downloadMcJson(Project project, boolean offline) throws IOException { - LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); - File manifests = new File(extension.getUserCache(), "version_manifest.json"); + private void downloadMcJson(boolean offline) throws IOException { + File manifests = new File(getExtension().getUserCache(), "version_manifest.json"); if (offline) { if (manifests.exists()) { //If there is the manifests already we'll presume that's good enough - project.getLogger().debug("Found version manifests, presuming up-to-date"); + getProject().getLogger().debug("Found version manifests, presuming up-to-date"); } else { //If we don't have the manifests then there's nothing more we can do throw new GradleException("Version manifests not found at " + manifests.getAbsolutePath()); } } else { - project.getLogger().debug("Downloading version manifests"); - DownloadUtil.downloadIfChanged(new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json"), manifests, project.getLogger()); + getProject().getLogger().debug("Downloading version manifests"); + DownloadUtil.downloadIfChanged(new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json"), manifests, getProject().getLogger()); } String versionManifest = Files.asCharSource(manifests, StandardCharsets.UTF_8).read(); @@ -138,12 +139,12 @@ private void downloadMcJson(Project project, boolean offline) throws IOException Optional optionalVersion = Optional.empty(); - if (extension.customManifest != null) { + if (getExtension().customManifest != null) { ManifestVersion.Versions customVersion = new ManifestVersion.Versions(); customVersion.id = minecraftVersion; - customVersion.url = extension.customManifest; + customVersion.url = getExtension().customManifest; optionalVersion = Optional.of(customVersion); - project.getLogger().lifecycle("Using custom minecraft manifest"); + getProject().getLogger().lifecycle("Using custom minecraft manifest"); } if (!optionalVersion.isPresent()) { @@ -152,17 +153,17 @@ private void downloadMcJson(Project project, boolean offline) throws IOException if (optionalVersion.isPresent()) { if (offline) { - if (MINECRAFT_JSON.exists()) { + if (minecraftJson.exists()) { //If there is the manifest already we'll presume that's good enough - project.getLogger().debug("Found Minecraft {} manifest, presuming up-to-date", minecraftVersion); + getProject().getLogger().debug("Found Minecraft {} manifest, presuming up-to-date", minecraftVersion); } else { //If we don't have the manifests then there's nothing more we can do - throw new GradleException("Minecraft " + minecraftVersion + " manifest not found at " + MINECRAFT_JSON.getAbsolutePath()); + throw new GradleException("Minecraft " + minecraftVersion + " manifest not found at " + minecraftJson.getAbsolutePath()); } } else { - if (StaticPathWatcher.INSTANCE.hasFileChanged(MINECRAFT_JSON.toPath())) { - project.getLogger().debug("Downloading Minecraft {} manifest", minecraftVersion); - DownloadUtil.downloadIfChanged(new URL(optionalVersion.get().url), MINECRAFT_JSON, project.getLogger()); + if (StaticPathWatcher.INSTANCE.hasFileChanged(minecraftJson.toPath())) { + getProject().getLogger().debug("Downloading Minecraft {} manifest", minecraftVersion); + DownloadUtil.downloadIfChanged(new URL(optionalVersion.get().url), minecraftJson, getProject().getLogger()); } } } else { @@ -171,28 +172,40 @@ private void downloadMcJson(Project project, boolean offline) throws IOException } private void downloadJars(Logger logger) throws IOException { - if (!MINECRAFT_CLIENT_JAR.exists() || (!Checksum.equals(MINECRAFT_CLIENT_JAR, versionInfo.downloads.get("client").sha1) && StaticPathWatcher.INSTANCE.hasFileChanged(MINECRAFT_CLIENT_JAR.toPath()))) { + if (!minecraftClientJar.exists() || (!Checksum.equals(minecraftClientJar, versionInfo.downloads.get("client").sha1) && StaticPathWatcher.INSTANCE.hasFileChanged(minecraftClientJar.toPath()))) { logger.debug("Downloading Minecraft {} client jar", minecraftVersion); - DownloadUtil.downloadIfChanged(new URL(versionInfo.downloads.get("client").url), MINECRAFT_CLIENT_JAR, logger); + DownloadUtil.downloadIfChanged(new URL(versionInfo.downloads.get("client").url), minecraftClientJar, logger); } - if (!MINECRAFT_SERVER_JAR.exists() || (!Checksum.equals(MINECRAFT_SERVER_JAR, versionInfo.downloads.get("server").sha1) && StaticPathWatcher.INSTANCE.hasFileChanged(MINECRAFT_SERVER_JAR.toPath()))) { + if (!minecraftServerJar.exists() || (!Checksum.equals(minecraftServerJar, versionInfo.downloads.get("server").sha1) && StaticPathWatcher.INSTANCE.hasFileChanged(minecraftServerJar.toPath()))) { logger.debug("Downloading Minecraft {} server jar", minecraftVersion); - DownloadUtil.downloadIfChanged(new URL(versionInfo.downloads.get("server").url), MINECRAFT_SERVER_JAR, logger); + DownloadUtil.downloadIfChanged(new URL(versionInfo.downloads.get("server").url), minecraftServerJar, logger); } } private void mergeJars(Logger logger) throws IOException { logger.lifecycle(":merging jars"); - try (JarMerger jarMerger = new JarMerger(MINECRAFT_CLIENT_JAR, MINECRAFT_SERVER_JAR, MINECRAFT_MERGED_JAR)) { + try (JarMerger jarMerger = new JarMerger(minecraftClientJar, minecraftServerJar, minecraftMergedJar)) { jarMerger.enableSyntheticParamsOffset(); jarMerger.merge(); } } public File getMergedJar() { - return MINECRAFT_MERGED_JAR; + return minecraftMergedJar; + } + + public String getMinecraftVersion() { + return minecraftVersion; + } + + public MinecraftVersionInfo getVersionInfo() { + return versionInfo; + } + + public MinecraftLibraryProvider getLibraryProvider() { + return libraryProvider; } @Override diff --git a/src/main/java/net/fabricmc/loom/task/AbstractRunTask.java b/src/main/java/net/fabricmc/loom/task/AbstractRunTask.java index d48d4a5d8..bd492bf67 100644 --- a/src/main/java/net/fabricmc/loom/task/AbstractRunTask.java +++ b/src/main/java/net/fabricmc/loom/task/AbstractRunTask.java @@ -58,7 +58,7 @@ public void exec() { } LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class); - MinecraftVersionInfo minecraftVersionInfo = extension.getMinecraftProvider().versionInfo; + MinecraftVersionInfo minecraftVersionInfo = extension.getMinecraftProvider().getVersionInfo(); MappingsProvider mappingsProvider = extension.getMappingsProvider(); List libs = new ArrayList<>(); diff --git a/src/main/java/net/fabricmc/loom/task/MigrateMappingsTask.java b/src/main/java/net/fabricmc/loom/task/MigrateMappingsTask.java index e38e10629..a410c0f7c 100644 --- a/src/main/java/net/fabricmc/loom/task/MigrateMappingsTask.java +++ b/src/main/java/net/fabricmc/loom/task/MigrateMappingsTask.java @@ -32,18 +32,11 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; import java.util.Set; -import java.util.function.BiFunction; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import org.cadixdev.lorenz.MappingSet; -import org.cadixdev.lorenz.io.MappingsReader; -import org.cadixdev.lorenz.model.ClassMapping; -import org.cadixdev.lorenz.model.Mapping; import org.cadixdev.mercury.Mercury; import org.cadixdev.mercury.remapper.MercuryRemapper; import org.gradle.api.GradleException; @@ -56,10 +49,7 @@ import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.providers.MinecraftMappedProvider; import net.fabricmc.loom.util.SourceRemapper; -import net.fabricmc.mapping.tree.ClassDef; -import net.fabricmc.mapping.tree.Descriptored; -import net.fabricmc.mapping.tree.FieldDef; -import net.fabricmc.mapping.tree.MethodDef; +import net.fabricmc.lorenztiny.LorenzTiny; import net.fabricmc.mapping.tree.TinyMappingFactory; import net.fabricmc.mapping.tree.TinyTree; @@ -159,14 +149,14 @@ private static void migrateMappings(Project project, MinecraftMappedProvider min Path inputDir, Path outputDir, TinyTree currentMappings, TinyTree targetMappings ) throws IOException { project.getLogger().lifecycle(":joining mappings"); - MappingSet mappingSet = new MappingsJoiner(currentMappings, targetMappings, + MappingSet mappingSet = LorenzTiny.readMappings(currentMappings, targetMappings, "intermediary", "named").read(); project.getLogger().lifecycle(":remapping"); Mercury mercury = SourceRemapper.createMercuryWithClassPath(project, false); - mercury.getClassPath().add(minecraftMappedProvider.MINECRAFT_MAPPED_JAR.toPath()); - mercury.getClassPath().add(minecraftMappedProvider.MINECRAFT_INTERMEDIARY_JAR.toPath()); + mercury.getClassPath().add(minecraftMappedProvider.getMappedJar().toPath()); + mercury.getClassPath().add(minecraftMappedProvider.getIntermediaryJar().toPath()); mercury.getProcessors().add(MercuryRemapper.create(mappingSet)); @@ -179,72 +169,4 @@ private static void migrateMappings(Project project, MinecraftMappedProvider min project.getLogger().lifecycle(":cleaning file descriptors"); System.gc(); } - - private static class MappingsJoiner extends MappingsReader { - private final TinyTree sourceMappings, targetMappings; - private final String fromNamespace, toNamespace; - - /** - * Say A is the source mappings and B is the target mappings. - * It does not map from intermediary to named but rather maps from named-A to named-B, by matching intermediary names. - * It goes through all of the intermediary names of A, and for every such intermediary name, call it I, - * matches the named mapping of I in A, with the named mapping of I in B. - * As you might imagine, this requires intermediary mappings to be stable across all versions. - * Since we only use intermediary names (and not descriptors) to match, and intermediary names are unique, - * this will migrate methods that have had their signature changed too. - */ - private MappingsJoiner(TinyTree sourceMappings, TinyTree targetMappings, String fromNamespace, String toNamespace) { - this.sourceMappings = sourceMappings; - this.targetMappings = targetMappings; - this.fromNamespace = fromNamespace; - this.toNamespace = toNamespace; - } - - @Override - public MappingSet read(MappingSet mappings) { - Map targetClasses = new HashMap<>(); - Map targetFields = new HashMap<>(); - Map targetMethods = new HashMap<>(); - - for (ClassDef newClass : targetMappings.getClasses()) { - targetClasses.put(newClass.getName(fromNamespace), newClass); - - for (FieldDef field : newClass.getFields()) { - targetFields.put(field.getName(fromNamespace), field); - } - - for (MethodDef method : newClass.getMethods()) { - targetMethods.put(method.getName(fromNamespace), method); - } - } - - for (ClassDef oldClass : sourceMappings.getClasses()) { - String namedMappingOfSourceMapping = oldClass.getName(toNamespace); - String namedMappingOfTargetMapping = targetClasses.getOrDefault(oldClass.getName(fromNamespace), oldClass).getName(toNamespace); - - ClassMapping classMapping = mappings.getOrCreateClassMapping(namedMappingOfSourceMapping).setDeobfuscatedName(namedMappingOfTargetMapping); - - mapMembers(oldClass.getFields(), targetFields, classMapping::getOrCreateFieldMapping); - mapMembers(oldClass.getMethods(), targetMethods, classMapping::getOrCreateMethodMapping); - } - - return mappings; - } - - private void mapMembers(Collection oldMembers, Map newMembers, - BiFunction mapper) { - for (T oldMember : oldMembers) { - String oldName = oldMember.getName(toNamespace); - String oldDescriptor = oldMember.getDescriptor(toNamespace); - // We only use the intermediary name (and not the descriptor) because every method has a unique intermediary name - String newName = newMembers.getOrDefault(oldMember.getName(fromNamespace), oldMember).getName(toNamespace); - - mapper.apply(oldName, oldDescriptor).setDeobfuscatedName(newName); - } - } - - @Override - public void close() { - } - } } diff --git a/src/main/java/net/fabricmc/loom/util/Checksum.java b/src/main/java/net/fabricmc/loom/util/Checksum.java index ab6ab8e02..c83623e21 100644 --- a/src/main/java/net/fabricmc/loom/util/Checksum.java +++ b/src/main/java/net/fabricmc/loom/util/Checksum.java @@ -58,4 +58,13 @@ public static boolean equals(File file, String checksum) { return false; } + + public static byte[] sha256(File file) { + try { + HashCode hash = Files.asByteSource(file).hash(Hashing.sha256()); + return hash.asBytes(); + } catch (IOException e) { + throw new RuntimeException("Failed to get file hash"); + } + } } diff --git a/src/main/java/net/fabricmc/loom/util/Constants.java b/src/main/java/net/fabricmc/loom/util/Constants.java index 7c8b32fa1..a6ee82d90 100644 --- a/src/main/java/net/fabricmc/loom/util/Constants.java +++ b/src/main/java/net/fabricmc/loom/util/Constants.java @@ -50,12 +50,10 @@ public class Constants { public static final String INCLUDE = "include"; public static final String MINECRAFT = "minecraft"; public static final String MINECRAFT_DEPENDENCIES = "minecraftLibraries"; - public static final String MINECRAFT_INTERMEDIARY = "minecraftIntermediary"; public static final String MINECRAFT_NAMED = "minecraftNamed"; - public static final String MINECRAFT_LINEMAPPED = "minecraftLinemapped"; public static final String MAPPINGS = "mappings"; public static final String MAPPINGS_FINAL = "mappingsFinal"; public static final String MIXIN_COMPILE_EXTENSIONS_VERSION = "0.3.0.4"; - public static final String DEV_LAUNCH_INJECTOR_VERSION = "0.1.0+build.3"; + public static final String DEV_LAUNCH_INJECTOR_VERSION = "0.2.0+build.6"; } diff --git a/src/main/java/net/fabricmc/loom/util/DependencyProvider.java b/src/main/java/net/fabricmc/loom/util/DependencyProvider.java index 067db9fdc..bb998e7ce 100644 --- a/src/main/java/net/fabricmc/loom/util/DependencyProvider.java +++ b/src/main/java/net/fabricmc/loom/util/DependencyProvider.java @@ -51,16 +51,23 @@ public abstract class DependencyProvider { private LoomDependencyManager dependencyManager; + private final Project project; + private final LoomGradleExtension extension; - public abstract void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension, Consumer postPopulationScheduler) throws Exception; + public DependencyProvider(Project project) { + this.project = project; + this.extension = project.getExtensions().getByType(LoomGradleExtension.class); + } + + public abstract void provide(DependencyInfo dependency, Consumer postPopulationScheduler) throws Exception; public abstract String getTargetConfig(); - public void addDependency(Object object, Project project) { - addDependency(object, project, "compile"); + public void addDependency(Object object) { + addDependency(object, "compile"); } - public void addDependency(Object object, Project project, String target) { + public void addDependency(Object object, String target) { if (object instanceof File) { object = project.files(object); } @@ -76,6 +83,14 @@ public LoomDependencyManager getDependencyManager() { return dependencyManager; } + public Project getProject() { + return project; + } + + public LoomGradleExtension getExtension() { + return extension; + } + public static class DependencyInfo { final Project project; final Dependency dependency; diff --git a/src/main/java/net/fabricmc/loom/util/LoomDependencyManager.java b/src/main/java/net/fabricmc/loom/util/LoomDependencyManager.java index c2fa6d213..a8fb1a0c4 100644 --- a/src/main/java/net/fabricmc/loom/util/LoomDependencyManager.java +++ b/src/main/java/net/fabricmc/loom/util/LoomDependencyManager.java @@ -108,7 +108,7 @@ public void handleDependencies(Project project) { DependencyProvider.DependencyInfo info = DependencyInfo.create(project, dependency, configuration); try { - provider.provide(info, project, extension, afterTasks::add); + provider.provide(info, afterTasks::add); } catch (Exception e) { throw new RuntimeException("Failed to provide " + dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion() + " : " + e.getMessage(), e); } diff --git a/src/main/java/net/fabricmc/loom/util/MapJarsTiny.java b/src/main/java/net/fabricmc/loom/util/MapJarsTiny.java index 3e6719234..bac57f4f8 100644 --- a/src/main/java/net/fabricmc/loom/util/MapJarsTiny.java +++ b/src/main/java/net/fabricmc/loom/util/MapJarsTiny.java @@ -39,7 +39,7 @@ import net.fabricmc.tinyremapper.TinyRemapper; public class MapJarsTiny { - public void mapJars(MinecraftProvider jarProvider, MinecraftMappedProvider mapProvider, Project project) throws IOException { + public void mapJars(MinecraftProvider jarProvider, MinecraftMappedProvider mapProvider, File mappedJar, File intermediaryJar, Project project) throws IOException { String fromM = "official"; LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); @@ -48,8 +48,8 @@ public void mapJars(MinecraftProvider jarProvider, MinecraftMappedProvider mapPr Path[] classpath = mapProvider.getMapperPaths().stream().map(File::toPath).toArray(Path[]::new); Path input = jarProvider.getMergedJar().toPath(); - Path outputMapped = mapProvider.getMappedJar().toPath(); - Path outputIntermediary = mapProvider.getIntermediaryJar().toPath(); + Path outputMapped = mappedJar.toPath(); + Path outputIntermediary = intermediaryJar.toPath(); for (String toM : Arrays.asList("named", "intermediary")) { Path output = "named".equals(toM) ? outputMapped : outputIntermediary; diff --git a/src/main/java/net/fabricmc/loom/util/ModProcessor.java b/src/main/java/net/fabricmc/loom/util/ModProcessor.java index 795ce3ac1..07401ecc8 100644 --- a/src/main/java/net/fabricmc/loom/util/ModProcessor.java +++ b/src/main/java/net/fabricmc/loom/util/ModProcessor.java @@ -149,7 +149,7 @@ private static void remapJar(File input, File output, Project project, ResolvedA MappingsProvider mappingsProvider = extension.getMappingsProvider(); Path inputPath = input.getAbsoluteFile().toPath(); - Path mc = mappedProvider.MINECRAFT_INTERMEDIARY_JAR.toPath(); + Path mc = mappedProvider.getIntermediaryJar().toPath(); Path[] mcDeps = mappedProvider.getMapperPaths().stream().map(File::toPath).toArray(Path[]::new); Set modCompiles = new HashSet<>(); diff --git a/src/main/java/net/fabricmc/loom/util/RunConfig.java b/src/main/java/net/fabricmc/loom/util/RunConfig.java index e48710492..2b9117002 100644 --- a/src/main/java/net/fabricmc/loom/util/RunConfig.java +++ b/src/main/java/net/fabricmc/loom/util/RunConfig.java @@ -107,7 +107,7 @@ private static void populate(Project project, LoomGradleExtension extension, Run default: runConfig.mainClass = "net.fabricmc.devlaunchinjector.Main"; runConfig.programArgs = ""; - runConfig.vmArgs = "-Dfabric.dli.config=" + quoteIfNeeded(extension.getDevLauncherConfig().getAbsolutePath()) + " -Dfabric.dli.env=" + mode.toLowerCase(); + runConfig.vmArgs = "-Dfabric.dli.config=" + encodeEscaped(extension.getDevLauncherConfig().getAbsolutePath()) + " -Dfabric.dli.env=" + mode.toLowerCase(); break; } @@ -144,7 +144,7 @@ private static void populate(Project project, LoomGradleExtension extension, Run public static RunConfig clientRunConfig(Project project) { LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); MinecraftProvider minecraftProvider = extension.getMinecraftProvider(); - MinecraftVersionInfo minecraftVersionInfo = minecraftProvider.versionInfo; + MinecraftVersionInfo minecraftVersionInfo = minecraftProvider.getVersionInfo(); RunConfig ideaClient = new RunConfig(); populate(project, extension, ideaClient, "client"); @@ -225,11 +225,20 @@ private static String getMainClass(String side, LoomGradleExtension extension) { return "net.fabricmc.loader.launch.knot.Knot" + side.substring(0, 1).toUpperCase(Locale.ROOT) + side.substring(1).toLowerCase(Locale.ROOT); } - private static String quoteIfNeeded(String input) { - if (!input.contains(" ")) { - return input; + private static String encodeEscaped(String s) { + StringBuilder ret = new StringBuilder(); + + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + + if (c == '@' && i > 0 && s.charAt(i - 1) == '@' || c == ' ') { + ret.append("@@"); + ret.append(Integer.toString(c, 16)); + } else { + ret.append(c); + } } - return String.format("\"%s\"", input); + return ret.toString(); } } diff --git a/src/main/java/net/fabricmc/loom/util/SourceRemapper.java b/src/main/java/net/fabricmc/loom/util/SourceRemapper.java index e2eff620b..fd22e4df6 100644 --- a/src/main/java/net/fabricmc/loom/util/SourceRemapper.java +++ b/src/main/java/net/fabricmc/loom/util/SourceRemapper.java @@ -77,8 +77,8 @@ private static void remapSourcesInner(Project project, File source, File destina } } - m.getClassPath().add(extension.getMinecraftMappedProvider().MINECRAFT_MAPPED_JAR.toPath()); - m.getClassPath().add(extension.getMinecraftMappedProvider().MINECRAFT_INTERMEDIARY_JAR.toPath()); + m.getClassPath().add(extension.getMinecraftMappedProvider().getMappedJar().toPath()); + m.getClassPath().add(extension.getMinecraftMappedProvider().getIntermediaryJar().toPath()); m.getProcessors().add(MercuryRemapper.create(mappings));