0.2.7 refactors (#178)
* Rough work on project based jars, skeleton for AccessEscalators? * First working draft * Minor changes * Add support for mutable, better error checking when parsing file. Code cleanup Remap if needed when reading * Fix inner classes and genSources * Fix CME * Caching, only regen jar when input changes * Some work, untested * Fix writing, fix checkstyle issues * More fixes * Move jars into a maven file structure, cleans up the file structure, and will benefit idea 2020 Add some basic validation to the AccessWidenerRemapper, will present any issues with the mappings when building (May need a way to disable?) + Some bugs fixes * Fix issues with source jars in idea 2020, should be backwards compatible with 2019 * Move to lorenz-tiny * Build fix + small cleanup * Remove accesswidener's for now * Update dev launch injector, should fix all issues with spaces in the path.dev/0.11
parent
d62a63c8bd
commit
ee462f8f9e
|
@ -48,6 +48,10 @@ dependencies {
|
||||||
transitive = false
|
transitive = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
implementation ('net.fabricmc:lorenz-tiny:1.0.0+build.1') {
|
||||||
|
transitive = false
|
||||||
|
}
|
||||||
|
|
||||||
// decompilers
|
// decompilers
|
||||||
implementation ('net.fabricmc:procyon-fabric-compilertools:0.5.35.+')
|
implementation ('net.fabricmc:procyon-fabric-compilertools:0.5.35.+')
|
||||||
implementation ('org.jetbrains:intellij-fernflower:1.1.0.11')
|
implementation ('org.jetbrains:intellij-fernflower:1.1.0.11')
|
||||||
|
|
|
@ -50,7 +50,6 @@ import org.gradle.api.tasks.bundling.AbstractArchiveTask;
|
||||||
import org.gradle.api.tasks.compile.JavaCompile;
|
import org.gradle.api.tasks.compile.JavaCompile;
|
||||||
import org.gradle.api.tasks.javadoc.Javadoc;
|
import org.gradle.api.tasks.javadoc.Javadoc;
|
||||||
import org.gradle.api.tasks.scala.ScalaCompile;
|
import org.gradle.api.tasks.scala.ScalaCompile;
|
||||||
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
|
|
||||||
import org.gradle.plugins.ide.idea.model.IdeaModel;
|
import org.gradle.plugins.ide.idea.model.IdeaModel;
|
||||||
|
|
||||||
import net.fabricmc.loom.providers.LaunchProvider;
|
import net.fabricmc.loom.providers.LaunchProvider;
|
||||||
|
@ -100,8 +99,6 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
|
|
||||||
Configuration minecraftNamedConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT_NAMED);
|
Configuration minecraftNamedConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT_NAMED);
|
||||||
minecraftNamedConfig.setTransitive(false); // The launchers do not recurse dependencies
|
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);
|
Configuration minecraftDependenciesConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT_DEPENDENCIES);
|
||||||
minecraftDependenciesConfig.setTransitive(false);
|
minecraftDependenciesConfig.setTransitive(false);
|
||||||
Configuration minecraftConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT);
|
Configuration minecraftConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT);
|
||||||
|
@ -135,7 +132,6 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
}
|
}
|
||||||
|
|
||||||
extendsFrom(Constants.MINECRAFT_NAMED, Constants.MINECRAFT_DEPENDENCIES);
|
extendsFrom(Constants.MINECRAFT_NAMED, Constants.MINECRAFT_DEPENDENCIES);
|
||||||
extendsFrom(Constants.MINECRAFT_INTERMEDIARY, Constants.MINECRAFT_DEPENDENCIES);
|
|
||||||
|
|
||||||
extendsFrom("compile", Constants.MAPPINGS_FINAL);
|
extendsFrom("compile", Constants.MAPPINGS_FINAL);
|
||||||
|
|
||||||
|
@ -224,9 +220,6 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
ideaModel.getModule().setDownloadJavadoc(true);
|
ideaModel.getModule().setDownloadJavadoc(true);
|
||||||
ideaModel.getModule().setDownloadSources(true);
|
ideaModel.getModule().setDownloadSources(true);
|
||||||
ideaModel.getModule().setInheritOutputDirs(true);
|
ideaModel.getModule().setInheritOutputDirs(true);
|
||||||
|
|
||||||
// ECLIPSE
|
|
||||||
EclipseModel eclipseModel = (EclipseModel) project.getExtensions().getByName("eclipse");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -236,7 +229,6 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
JavaPluginConvention javaModule = (JavaPluginConvention) project.getConvention().getPlugins().get("java");
|
JavaPluginConvention javaModule = (JavaPluginConvention) project.getConvention().getPlugins().get("java");
|
||||||
|
|
||||||
SourceSet main = javaModule.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
|
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 javadoc = (Javadoc) project.getTasks().getByName(JavaPlugin.JAVADOC_TASK_NAME);
|
||||||
javadoc.setClasspath(main.getOutput().plus(main.getCompileClasspath()));
|
javadoc.setClasspath(main.getOutput().plus(main.getCompileClasspath()));
|
||||||
|
@ -249,11 +241,6 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
project.afterEvaluate(project1 -> {
|
project.afterEvaluate(project1 -> {
|
||||||
LoomGradleExtension extension = project1.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project1.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
|
|
||||||
project1.getRepositories().flatDir(flatDirectoryArtifactRepository -> {
|
|
||||||
flatDirectoryArtifactRepository.dir(extension.getUserCache());
|
|
||||||
flatDirectoryArtifactRepository.setName("UserCacheFiles");
|
|
||||||
});
|
|
||||||
|
|
||||||
project1.getRepositories().flatDir(flatDirectoryArtifactRepository -> {
|
project1.getRepositories().flatDir(flatDirectoryArtifactRepository -> {
|
||||||
flatDirectoryArtifactRepository.dir(extension.getRootProjectBuildCache());
|
flatDirectoryArtifactRepository.dir(extension.getRootProjectBuildCache());
|
||||||
flatDirectoryArtifactRepository.setName("UserLocalCacheFiles");
|
flatDirectoryArtifactRepository.setName("UserLocalCacheFiles");
|
||||||
|
@ -269,11 +256,6 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
mavenArtifactRepository.setUrl("https://maven.fabricmc.net/");
|
mavenArtifactRepository.setUrl("https://maven.fabricmc.net/");
|
||||||
});
|
});
|
||||||
|
|
||||||
/* project1.getRepositories().maven(mavenArtifactRepository -> {
|
|
||||||
mavenArtifactRepository.setName("SpongePowered");
|
|
||||||
mavenArtifactRepository.setUrl("http://repo.spongepowered.org/maven");
|
|
||||||
}); */
|
|
||||||
|
|
||||||
project1.getRepositories().maven(mavenArtifactRepository -> {
|
project1.getRepositories().maven(mavenArtifactRepository -> {
|
||||||
mavenArtifactRepository.setName("Mojang");
|
mavenArtifactRepository.setName("Mojang");
|
||||||
mavenArtifactRepository.setUrl("https://libraries.minecraft.net/");
|
mavenArtifactRepository.setUrl("https://libraries.minecraft.net/");
|
||||||
|
@ -285,9 +267,9 @@ public class AbstractPlugin implements Plugin<Project> {
|
||||||
LoomDependencyManager dependencyManager = new LoomDependencyManager();
|
LoomDependencyManager dependencyManager = new LoomDependencyManager();
|
||||||
extension.setDependencyManager(dependencyManager);
|
extension.setDependencyManager(dependencyManager);
|
||||||
|
|
||||||
dependencyManager.addProvider(new MinecraftProvider());
|
dependencyManager.addProvider(new MinecraftProvider(getProject()));
|
||||||
dependencyManager.addProvider(new MappingsProvider());
|
dependencyManager.addProvider(new MappingsProvider(getProject()));
|
||||||
dependencyManager.addProvider(new LaunchProvider());
|
dependencyManager.addProvider(new LaunchProvider(getProject()));
|
||||||
|
|
||||||
dependencyManager.handleDependencies(project1);
|
dependencyManager.handleDependencies(project1);
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ import org.gradle.api.artifacts.Configuration;
|
||||||
import org.gradle.api.artifacts.Dependency;
|
import org.gradle.api.artifacts.Dependency;
|
||||||
import org.gradle.api.plugins.BasePluginConvention;
|
import org.gradle.api.plugins.BasePluginConvention;
|
||||||
|
|
||||||
|
import net.fabricmc.loom.processors.JarProcessorManager;
|
||||||
import net.fabricmc.loom.providers.MappingsProvider;
|
import net.fabricmc.loom.providers.MappingsProvider;
|
||||||
import net.fabricmc.loom.providers.MinecraftMappedProvider;
|
import net.fabricmc.loom.providers.MinecraftMappedProvider;
|
||||||
import net.fabricmc.loom.providers.MinecraftProvider;
|
import net.fabricmc.loom.providers.MinecraftProvider;
|
||||||
|
@ -58,12 +59,14 @@ public class LoomGradleExtension {
|
||||||
public boolean autoGenIDERuns = true;
|
public boolean autoGenIDERuns = true;
|
||||||
public boolean extractJars = false;
|
public boolean extractJars = false;
|
||||||
public String customManifest = null;
|
public String customManifest = null;
|
||||||
|
public File accessWidener = null;
|
||||||
|
|
||||||
private List<Path> unmappedModsBuilt = new ArrayList<>();
|
private List<Path> unmappedModsBuilt = new ArrayList<>();
|
||||||
|
|
||||||
//Not to be set in the build.gradle
|
//Not to be set in the build.gradle
|
||||||
private Project project;
|
private Project project;
|
||||||
private LoomDependencyManager dependencyManager;
|
private LoomDependencyManager dependencyManager;
|
||||||
|
private JarProcessorManager jarProcessorManager;
|
||||||
private JsonObject installerJson;
|
private JsonObject installerJson;
|
||||||
private MappingSet[] srcMappingCache = new MappingSet[2];
|
private MappingSet[] srcMappingCache = new MappingSet[2];
|
||||||
private Mercury[] srcMercuryCache = new Mercury[2];
|
private Mercury[] srcMercuryCache = new Mercury[2];
|
||||||
|
@ -116,6 +119,16 @@ public class LoomGradleExtension {
|
||||||
return projectCache;
|
return projectCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getProjectPersistentCache() {
|
||||||
|
File projectCache = new File(project.file(".gradle"), "loom-cache");
|
||||||
|
|
||||||
|
if (!projectCache.exists()) {
|
||||||
|
projectCache.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
return projectCache;
|
||||||
|
}
|
||||||
|
|
||||||
public File getRootProjectBuildCache() {
|
public File getRootProjectBuildCache() {
|
||||||
File projectCache = new File(project.getRootProject().getBuildDir(), "loom-cache");
|
File projectCache = new File(project.getRootProject().getBuildDir(), "loom-cache");
|
||||||
|
|
||||||
|
@ -167,7 +180,7 @@ public class LoomGradleExtension {
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getNativesDirectory() {
|
public File getNativesDirectory() {
|
||||||
File natives = new File(getUserCache(), "natives/" + getMinecraftProvider().minecraftVersion);
|
File natives = new File(getUserCache(), "natives/" + getMinecraftProvider().getMinecraftVersion());
|
||||||
|
|
||||||
if (!natives.exists()) {
|
if (!natives.exists()) {
|
||||||
natives.mkdirs();
|
natives.mkdirs();
|
||||||
|
@ -283,6 +296,14 @@ public class LoomGradleExtension {
|
||||||
this.dependencyManager = dependencyManager;
|
this.dependencyManager = dependencyManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JarProcessorManager getJarProcessorManager() {
|
||||||
|
return jarProcessorManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJarProcessorManager(JarProcessorManager jarProcessorManager) {
|
||||||
|
this.jarProcessorManager = jarProcessorManager;
|
||||||
|
}
|
||||||
|
|
||||||
public String getRefmapName() {
|
public String getRefmapName() {
|
||||||
if (refmapName == null || refmapName.isEmpty()) {
|
if (refmapName == null || refmapName.isEmpty()) {
|
||||||
String defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json";
|
String defaultRefmapName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() + "-refmap.json";
|
||||||
|
|
|
@ -52,7 +52,7 @@ import net.fabricmc.loom.task.RunServerTask;
|
||||||
import net.fabricmc.loom.task.fernflower.FernFlowerTask;
|
import net.fabricmc.loom.task.fernflower.FernFlowerTask;
|
||||||
|
|
||||||
public class LoomGradlePlugin extends AbstractPlugin {
|
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);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
||||||
File mappedJar = mappingsProvider.mappedProvider.getMappedJar();
|
File mappedJar = mappingsProvider.mappedProvider.getMappedJar();
|
||||||
|
@ -108,7 +108,7 @@ public class LoomGradlePlugin extends AbstractPlugin {
|
||||||
|
|
||||||
Project project = this.getProject();
|
Project project = this.getProject();
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
MinecraftLibraryProvider libraryProvider = extension.getMinecraftProvider().libraryProvider;
|
MinecraftLibraryProvider libraryProvider = extension.getMinecraftProvider().getLibraryProvider();
|
||||||
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
||||||
File mappedJar = mappingsProvider.mappedProvider.getMappedJar();
|
File mappedJar = mappingsProvider.mappedProvider.getMappedJar();
|
||||||
File linemappedJar = getMappedByproduct(project, "-linemapped.jar");
|
File linemappedJar = getMappedByproduct(project, "-linemapped.jar");
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -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<JarProcessor> 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<JarProcessor> setupProcessors() {
|
||||||
|
List<JarProcessor> 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 extends JarProcessor> T getByType(Class<T> tClass) {
|
||||||
|
//noinspection unchecked
|
||||||
|
return (T) jarProcessors.stream().filter(jarProcessor -> jarProcessor.getClass().equals(tClass)).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<Runnable> 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,27 +37,30 @@ import java.util.function.Consumer;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
|
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
|
||||||
import net.fabricmc.loom.util.Constants;
|
import net.fabricmc.loom.util.Constants;
|
||||||
import net.fabricmc.loom.util.DependencyProvider;
|
import net.fabricmc.loom.util.DependencyProvider;
|
||||||
|
|
||||||
public class LaunchProvider extends DependencyProvider {
|
public class LaunchProvider extends DependencyProvider {
|
||||||
|
public LaunchProvider(Project project) {
|
||||||
|
super(project);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension, Consumer<Runnable> postPopulationScheduler) throws IOException {
|
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws IOException {
|
||||||
final LaunchConfig launchConfig = new LaunchConfig()
|
final LaunchConfig launchConfig = new LaunchConfig()
|
||||||
.property("fabric.development", "true")
|
.property("fabric.development", "true")
|
||||||
|
|
||||||
.property("client", "java.library.path", extension.getNativesDirectory().getAbsolutePath())
|
.property("client", "java.library.path", getExtension().getNativesDirectory().getAbsolutePath())
|
||||||
.property("client", "org.lwjgl.librarypath", extension.getNativesDirectory().getAbsolutePath())
|
.property("client", "org.lwjgl.librarypath", getExtension().getNativesDirectory().getAbsolutePath())
|
||||||
|
|
||||||
.argument("client", "--assetIndex")
|
.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", "--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
|
@Override
|
||||||
|
|
|
@ -44,7 +44,6 @@ import org.zeroturnaround.zip.FileSource;
|
||||||
import org.zeroturnaround.zip.ZipEntrySource;
|
import org.zeroturnaround.zip.ZipEntrySource;
|
||||||
import org.zeroturnaround.zip.ZipUtil;
|
import org.zeroturnaround.zip.ZipUtil;
|
||||||
|
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
|
||||||
import net.fabricmc.loom.util.Constants;
|
import net.fabricmc.loom.util.Constants;
|
||||||
import net.fabricmc.loom.util.DependencyProvider;
|
import net.fabricmc.loom.util.DependencyProvider;
|
||||||
import net.fabricmc.loom.util.DownloadUtil;
|
import net.fabricmc.loom.util.DownloadUtil;
|
||||||
|
@ -54,6 +53,8 @@ import net.fabricmc.stitch.Command;
|
||||||
import net.fabricmc.stitch.commands.CommandProposeFieldNames;
|
import net.fabricmc.stitch.commands.CommandProposeFieldNames;
|
||||||
import net.fabricmc.stitch.commands.tinyv2.CommandMergeTinyV2;
|
import net.fabricmc.stitch.commands.tinyv2.CommandMergeTinyV2;
|
||||||
import net.fabricmc.stitch.commands.tinyv2.CommandReorderTinyV2;
|
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 class MappingsProvider extends DependencyProvider {
|
||||||
public MinecraftMappedProvider mappedProvider;
|
public MinecraftMappedProvider mappedProvider;
|
||||||
|
@ -71,6 +72,10 @@ public class MappingsProvider extends DependencyProvider {
|
||||||
public File tinyMappingsJar;
|
public File tinyMappingsJar;
|
||||||
public File mappingsMixinExport;
|
public File mappingsMixinExport;
|
||||||
|
|
||||||
|
public MappingsProvider(Project project) {
|
||||||
|
super(project);
|
||||||
|
}
|
||||||
|
|
||||||
public void clean() throws IOException {
|
public void clean() throws IOException {
|
||||||
FileUtils.deleteDirectory(mappingsDir.toFile());
|
FileUtils.deleteDirectory(mappingsDir.toFile());
|
||||||
}
|
}
|
||||||
|
@ -80,10 +85,10 @@ public class MappingsProvider extends DependencyProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension, Consumer<Runnable> postPopulationScheduler) throws Exception {
|
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws Exception {
|
||||||
MinecraftProvider minecraftProvider = getDependencyManager().getProvider(MinecraftProvider.class);
|
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();
|
String version = dependency.getResolvedVersion();
|
||||||
File mappingsJar = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not find yarn mappings: " + dependency));
|
File mappingsJar = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not find yarn mappings: " + dependency));
|
||||||
|
@ -92,10 +97,10 @@ public class MappingsProvider extends DependencyProvider {
|
||||||
|
|
||||||
boolean isV2 = doesJarContainV2Mappings(mappingsJar.toPath());
|
boolean isV2 = doesJarContainV2Mappings(mappingsJar.toPath());
|
||||||
|
|
||||||
this.minecraftVersion = minecraftProvider.minecraftVersion;
|
this.minecraftVersion = minecraftProvider.getMinecraftVersion();
|
||||||
this.mappingsVersion = version + (isV2 ? "-v2" : "");
|
this.mappingsVersion = version + (isV2 ? "-v2" : "");
|
||||||
|
|
||||||
initFiles(project);
|
initFiles();
|
||||||
|
|
||||||
Files.createDirectories(mappingsDir);
|
Files.createDirectories(mappingsDir);
|
||||||
Files.createDirectories(mappingsStepsDir);
|
Files.createDirectories(mappingsStepsDir);
|
||||||
|
@ -108,21 +113,30 @@ public class MappingsProvider extends DependencyProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
tinyMappings = mappingsDir.resolve(StringUtils.removeSuffix(mappingsJar.getName(), ".jar") + ".tiny").toFile();
|
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()) {
|
if (!tinyMappings.exists()) {
|
||||||
storeMappings(project, minecraftProvider, mappingsJar.toPath());
|
storeMappings(getProject(), minecraftProvider, mappingsJar.toPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tinyMappingsJar.exists()) {
|
if (!tinyMappingsJar.exists()) {
|
||||||
ZipUtil.pack(new ZipEntrySource[] {new FileSource("mappings/mappings.tiny", tinyMappings)}, tinyMappingsJar);
|
ZipUtil.pack(new ZipEntrySource[] {new FileSource("mappings/mappings.tiny", tinyMappings)}, tinyMappingsJar);
|
||||||
}
|
}
|
||||||
|
|
||||||
addDependency(tinyMappingsJar, project, Constants.MAPPINGS_FINAL);
|
addDependency(tinyMappingsJar, Constants.MAPPINGS_FINAL);
|
||||||
|
|
||||||
mappedProvider = new MinecraftMappedProvider();
|
JarProcessorManager processorManager = new JarProcessorManager(getProject());
|
||||||
mappedProvider.initFiles(project, minecraftProvider, this);
|
getExtension().setJarProcessorManager(processorManager);
|
||||||
mappedProvider.provide(dependency, project, extension, postPopulationScheduler);
|
|
||||||
|
if (processorManager.active()) {
|
||||||
|
mappedProvider = new MinecraftProcessedProvider(getProject(), processorManager);
|
||||||
|
getProject().getLogger().lifecycle("Using project based jar storage");
|
||||||
|
} else {
|
||||||
|
mappedProvider = new MinecraftMappedProvider(getProject());
|
||||||
|
}
|
||||||
|
|
||||||
|
mappedProvider.initFiles(minecraftProvider, this);
|
||||||
|
mappedProvider.provide(dependency, postPopulationScheduler);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void storeMappings(Project project, MinecraftProvider minecraftProvider, Path yarnJar) throws IOException {
|
private void storeMappings(Project project, MinecraftProvider minecraftProvider, Path yarnJar) throws IOException {
|
||||||
|
@ -225,7 +239,7 @@ public class MappingsProvider extends DependencyProvider {
|
||||||
|
|
||||||
private void suggestFieldNames(MinecraftProvider minecraftProvider, Path oldMappings, Path newMappings) {
|
private void suggestFieldNames(MinecraftProvider minecraftProvider, Path oldMappings, Path newMappings) {
|
||||||
Command command = new CommandProposeFieldNames();
|
Command command = new CommandProposeFieldNames();
|
||||||
runCommand(command, minecraftProvider.MINECRAFT_MERGED_JAR.getAbsolutePath(),
|
runCommand(command, minecraftProvider.getMergedJar().getAbsolutePath(),
|
||||||
oldMappings.toAbsolutePath().toString(),
|
oldMappings.toAbsolutePath().toString(),
|
||||||
newMappings.toAbsolutePath().toString());
|
newMappings.toAbsolutePath().toString());
|
||||||
}
|
}
|
||||||
|
@ -238,13 +252,12 @@ public class MappingsProvider extends DependencyProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFiles(Project project) {
|
private void initFiles() {
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
mappingsDir = getExtension().getUserCache().toPath().resolve("mappings");
|
||||||
mappingsDir = extension.getUserCache().toPath().resolve("mappings");
|
|
||||||
mappingsStepsDir = mappingsDir.resolve("steps");
|
mappingsStepsDir = mappingsDir.resolve("steps");
|
||||||
|
|
||||||
baseTinyMappings = mappingsDir.resolve(mappingsName + "-tiny-" + minecraftVersion + "-" + mappingsVersion + "-base");
|
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
|
@Override
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class MinecraftAssetsProvider {
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
boolean offline = project.getGradle().getStartParameter().isOffline();
|
boolean offline = project.getGradle().getStartParameter().isOffline();
|
||||||
|
|
||||||
MinecraftVersionInfo versionInfo = minecraftProvider.versionInfo;
|
MinecraftVersionInfo versionInfo = minecraftProvider.getVersionInfo();
|
||||||
MinecraftVersionInfo.AssetIndex assetIndex = versionInfo.assetIndex;
|
MinecraftVersionInfo.AssetIndex assetIndex = versionInfo.assetIndex;
|
||||||
|
|
||||||
// get existing cache files
|
// get existing cache files
|
||||||
|
@ -63,7 +63,7 @@ public class MinecraftAssetsProvider {
|
||||||
assets.mkdirs();
|
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)) {
|
if (!assetsInfo.exists() || !Checksum.equals(assetsInfo, assetIndex.sha1)) {
|
||||||
project.getLogger().lifecycle(":downloading asset index");
|
project.getLogger().lifecycle(":downloading asset index");
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class MinecraftLibraryProvider {
|
||||||
|
|
||||||
public void provide(MinecraftProvider minecraftProvider, Project project) throws IOException {
|
public void provide(MinecraftProvider minecraftProvider, Project project) throws IOException {
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
MinecraftVersionInfo versionInfo = minecraftProvider.versionInfo;
|
MinecraftVersionInfo versionInfo = minecraftProvider.getVersionInfo();
|
||||||
|
|
||||||
initFiles(project, minecraftProvider);
|
initFiles(project, minecraftProvider);
|
||||||
|
|
||||||
|
|
|
@ -30,80 +30,82 @@ import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
|
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
|
||||||
import net.fabricmc.loom.util.Constants;
|
import net.fabricmc.loom.util.Constants;
|
||||||
import net.fabricmc.loom.util.DependencyProvider;
|
import net.fabricmc.loom.util.DependencyProvider;
|
||||||
import net.fabricmc.loom.util.MapJarsTiny;
|
import net.fabricmc.loom.util.MapJarsTiny;
|
||||||
|
|
||||||
public class MinecraftMappedProvider extends DependencyProvider {
|
public class MinecraftMappedProvider extends DependencyProvider {
|
||||||
public File MINECRAFT_MAPPED_JAR;
|
private File minecraftMappedJar;
|
||||||
public File MINECRAFT_INTERMEDIARY_JAR;
|
private File minecraftIntermediaryJar;
|
||||||
|
|
||||||
public MinecraftMappedProvider() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private MinecraftProvider minecraftProvider;
|
private MinecraftProvider minecraftProvider;
|
||||||
|
|
||||||
|
public MinecraftMappedProvider(Project project) {
|
||||||
|
super(project);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension, Consumer<Runnable> postPopulationScheduler) throws Exception {
|
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws Exception {
|
||||||
if (!extension.getMappingsProvider().tinyMappings.exists()) {
|
if (!getExtension().getMappingsProvider().tinyMappings.exists()) {
|
||||||
throw new RuntimeException("mappings file not found");
|
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");
|
throw new RuntimeException("input merged jar not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!getMappedJar().exists() || !getIntermediaryJar().exists()) {
|
if (!minecraftMappedJar.exists() || !getIntermediaryJar().exists()) {
|
||||||
if (getMappedJar().exists()) {
|
if (minecraftMappedJar.exists()) {
|
||||||
getMappedJar().delete();
|
minecraftMappedJar.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getIntermediaryJar().exists()) {
|
minecraftMappedJar.getParentFile().mkdirs();
|
||||||
getIntermediaryJar().delete();
|
|
||||||
|
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");
|
throw new RuntimeException("mapped jar not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
addDependencies(dependency, postPopulationScheduler);
|
||||||
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)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initFiles(Project project, MinecraftProvider minecraftProvider, MappingsProvider mappingsProvider) {
|
protected void addDependencies(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) {
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
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(MinecraftProvider minecraftProvider, MappingsProvider mappingsProvider) {
|
||||||
this.minecraftProvider = minecraftProvider;
|
this.minecraftProvider = minecraftProvider;
|
||||||
MINECRAFT_INTERMEDIARY_JAR = new File(extension.getUserCache(),
|
minecraftIntermediaryJar = new File(getExtension().getUserCache(), "minecraft-" + getJarVersionString("intermediary") + ".jar");
|
||||||
"minecraft-" + getIntermediaryJarVersionString(mappingsProvider.mappingsName, mappingsProvider.mappingsVersion) + ".jar");
|
minecraftMappedJar = new File(getJarDirectory(getExtension().getUserCache(), "mapped"), "minecraft-" + getJarVersionString("mapped") + ".jar");
|
||||||
MINECRAFT_MAPPED_JAR = new File(extension.getUserCache(),
|
|
||||||
"minecraft-" + getNamedJarVersionString(mappingsProvider.mappingsName, mappingsProvider.mappingsVersion) + ".jar");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getNamedJarVersionString(String mappingsName, String mappingsVersion) {
|
protected File getJarDirectory(File parentDirectory, String type) {
|
||||||
return minecraftProvider.minecraftVersion + "-mapped-" + mappingsName + "-" + mappingsVersion;
|
return new File(parentDirectory, getJarVersionString(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getIntermediaryJarVersionString(String mappingsName, String mappingsVersion) {
|
protected String getJarVersionString(String type) {
|
||||||
return minecraftProvider.minecraftVersion + "-intermediary-" + mappingsName + "-" + mappingsVersion;
|
return String.format("%s-%s-%s-%s", minecraftProvider.getMinecraftVersion(), type, getExtension().getMappingsProvider().mappingsName, getExtension().getMappingsProvider().mappingsVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<File> getMapperPaths() {
|
public Collection<File> getMapperPaths() {
|
||||||
return minecraftProvider.libraryProvider.getLibraries();
|
return minecraftProvider.getLibraryProvider().getLibraries();
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getIntermediaryJar() {
|
public File getIntermediaryJar() {
|
||||||
return MINECRAFT_INTERMEDIARY_JAR;
|
return minecraftIntermediaryJar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getMappedJar() {
|
public File getMappedJar() {
|
||||||
return MINECRAFT_MAPPED_JAR;
|
return minecraftMappedJar;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -38,7 +38,7 @@ import net.fabricmc.loom.util.MinecraftVersionInfo;
|
||||||
public class MinecraftNativesProvider {
|
public class MinecraftNativesProvider {
|
||||||
public static void provide(MinecraftProvider minecraftProvider, Project project) throws IOException {
|
public static void provide(MinecraftProvider minecraftProvider, Project project) throws IOException {
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
MinecraftVersionInfo versionInfo = minecraftProvider.versionInfo;
|
MinecraftVersionInfo versionInfo = minecraftProvider.getVersionInfo();
|
||||||
|
|
||||||
File nativesDir = extension.getNativesDirectory();
|
File nativesDir = extension.getNativesDirectory();
|
||||||
File jarStore = extension.getNativesJarStore();
|
File jarStore = extension.getNativesJarStore();
|
||||||
|
|
|
@ -40,7 +40,6 @@ import org.gradle.api.GradleException;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.logging.Logger;
|
import org.gradle.api.logging.Logger;
|
||||||
|
|
||||||
import net.fabricmc.loom.LoomGradleExtension;
|
|
||||||
import net.fabricmc.loom.util.Checksum;
|
import net.fabricmc.loom.util.Checksum;
|
||||||
import net.fabricmc.loom.util.Constants;
|
import net.fabricmc.loom.util.Constants;
|
||||||
import net.fabricmc.loom.util.DependencyProvider;
|
import net.fabricmc.loom.util.DependencyProvider;
|
||||||
|
@ -51,86 +50,88 @@ import net.fabricmc.loom.util.StaticPathWatcher;
|
||||||
import net.fabricmc.stitch.merge.JarMerger;
|
import net.fabricmc.stitch.merge.JarMerger;
|
||||||
|
|
||||||
public class MinecraftProvider extends DependencyProvider {
|
public class MinecraftProvider extends DependencyProvider {
|
||||||
public String minecraftVersion;
|
private String minecraftVersion;
|
||||||
|
|
||||||
public MinecraftVersionInfo versionInfo;
|
private MinecraftVersionInfo versionInfo;
|
||||||
public MinecraftLibraryProvider libraryProvider;
|
private MinecraftLibraryProvider libraryProvider;
|
||||||
|
|
||||||
File MINECRAFT_JSON;
|
private File minecraftJson;
|
||||||
File MINECRAFT_CLIENT_JAR;
|
private File minecraftClientJar;
|
||||||
File MINECRAFT_SERVER_JAR;
|
private File minecraftServerJar;
|
||||||
File MINECRAFT_MERGED_JAR;
|
private File minecraftMergedJar;
|
||||||
|
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
|
|
||||||
|
public MinecraftProvider(Project project) {
|
||||||
|
super(project);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension, Consumer<Runnable> postPopulationScheduler) throws Exception {
|
public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws Exception {
|
||||||
minecraftVersion = dependency.getDependency().getVersion();
|
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);
|
versionInfo = gson.fromJson(reader, MinecraftVersionInfo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Loom as an annotation processor
|
// 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 (offline) {
|
||||||
if (MINECRAFT_CLIENT_JAR.exists() && MINECRAFT_SERVER_JAR.exists()) {
|
if (minecraftClientJar.exists() && minecraftServerJar.exists()) {
|
||||||
project.getLogger().debug("Found client and server jars, presuming up-to-date");
|
getProject().getLogger().debug("Found client and server jars, presuming up-to-date");
|
||||||
} else if (MINECRAFT_MERGED_JAR.exists()) {
|
} else if (minecraftMergedJar.exists()) {
|
||||||
//Strictly we don't need the split jars if the merged one exists, let's try go on
|
//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 {
|
} 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 {
|
} else {
|
||||||
downloadJars(project.getLogger());
|
downloadJars(getProject().getLogger());
|
||||||
}
|
}
|
||||||
|
|
||||||
libraryProvider = new MinecraftLibraryProvider();
|
libraryProvider = new MinecraftLibraryProvider();
|
||||||
libraryProvider.provide(this, project);
|
libraryProvider.provide(this, getProject());
|
||||||
|
|
||||||
if (!MINECRAFT_MERGED_JAR.exists()) {
|
if (!minecraftMergedJar.exists()) {
|
||||||
try {
|
try {
|
||||||
mergeJars(project.getLogger());
|
mergeJars(getProject().getLogger());
|
||||||
} catch (ZipError e) {
|
} catch (ZipError e) {
|
||||||
DownloadUtil.delete(MINECRAFT_CLIENT_JAR);
|
DownloadUtil.delete(minecraftClientJar);
|
||||||
DownloadUtil.delete(MINECRAFT_SERVER_JAR);
|
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();
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFiles(Project project) {
|
private void initFiles() {
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
minecraftJson = new File(getExtension().getUserCache(), "minecraft-" + minecraftVersion + "-info.json");
|
||||||
MINECRAFT_JSON = new File(extension.getUserCache(), "minecraft-" + minecraftVersion + "-info.json");
|
minecraftClientJar = new File(getExtension().getUserCache(), "minecraft-" + minecraftVersion + "-client.jar");
|
||||||
MINECRAFT_CLIENT_JAR = new File(extension.getUserCache(), "minecraft-" + minecraftVersion + "-client.jar");
|
minecraftServerJar = new File(getExtension().getUserCache(), "minecraft-" + minecraftVersion + "-server.jar");
|
||||||
MINECRAFT_SERVER_JAR = new File(extension.getUserCache(), "minecraft-" + minecraftVersion + "-server.jar");
|
minecraftMergedJar = new File(getExtension().getUserCache(), "minecraft-" + minecraftVersion + "-merged.jar");
|
||||||
MINECRAFT_MERGED_JAR = new File(extension.getUserCache(), "minecraft-" + minecraftVersion + "-merged.jar");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadMcJson(Project project, boolean offline) throws IOException {
|
private void downloadMcJson(boolean offline) throws IOException {
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
File manifests = new File(getExtension().getUserCache(), "version_manifest.json");
|
||||||
File manifests = new File(extension.getUserCache(), "version_manifest.json");
|
|
||||||
|
|
||||||
if (offline) {
|
if (offline) {
|
||||||
if (manifests.exists()) {
|
if (manifests.exists()) {
|
||||||
//If there is the manifests already we'll presume that's good enough
|
//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 {
|
} else {
|
||||||
//If we don't have the manifests then there's nothing more we can do
|
//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());
|
throw new GradleException("Version manifests not found at " + manifests.getAbsolutePath());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
project.getLogger().debug("Downloading version manifests");
|
getProject().getLogger().debug("Downloading version manifests");
|
||||||
DownloadUtil.downloadIfChanged(new URL("https://launchermeta.mojang.com/mc/game/version_manifest.json"), manifests, project.getLogger());
|
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();
|
String versionManifest = Files.asCharSource(manifests, StandardCharsets.UTF_8).read();
|
||||||
|
@ -138,12 +139,12 @@ public class MinecraftProvider extends DependencyProvider {
|
||||||
|
|
||||||
Optional<ManifestVersion.Versions> optionalVersion = Optional.empty();
|
Optional<ManifestVersion.Versions> optionalVersion = Optional.empty();
|
||||||
|
|
||||||
if (extension.customManifest != null) {
|
if (getExtension().customManifest != null) {
|
||||||
ManifestVersion.Versions customVersion = new ManifestVersion.Versions();
|
ManifestVersion.Versions customVersion = new ManifestVersion.Versions();
|
||||||
customVersion.id = minecraftVersion;
|
customVersion.id = minecraftVersion;
|
||||||
customVersion.url = extension.customManifest;
|
customVersion.url = getExtension().customManifest;
|
||||||
optionalVersion = Optional.of(customVersion);
|
optionalVersion = Optional.of(customVersion);
|
||||||
project.getLogger().lifecycle("Using custom minecraft manifest");
|
getProject().getLogger().lifecycle("Using custom minecraft manifest");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!optionalVersion.isPresent()) {
|
if (!optionalVersion.isPresent()) {
|
||||||
|
@ -152,17 +153,17 @@ public class MinecraftProvider extends DependencyProvider {
|
||||||
|
|
||||||
if (optionalVersion.isPresent()) {
|
if (optionalVersion.isPresent()) {
|
||||||
if (offline) {
|
if (offline) {
|
||||||
if (MINECRAFT_JSON.exists()) {
|
if (minecraftJson.exists()) {
|
||||||
//If there is the manifest already we'll presume that's good enough
|
//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 {
|
} else {
|
||||||
//If we don't have the manifests then there's nothing more we can do
|
//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 {
|
} else {
|
||||||
if (StaticPathWatcher.INSTANCE.hasFileChanged(MINECRAFT_JSON.toPath())) {
|
if (StaticPathWatcher.INSTANCE.hasFileChanged(minecraftJson.toPath())) {
|
||||||
project.getLogger().debug("Downloading Minecraft {} manifest", minecraftVersion);
|
getProject().getLogger().debug("Downloading Minecraft {} manifest", minecraftVersion);
|
||||||
DownloadUtil.downloadIfChanged(new URL(optionalVersion.get().url), MINECRAFT_JSON, project.getLogger());
|
DownloadUtil.downloadIfChanged(new URL(optionalVersion.get().url), minecraftJson, getProject().getLogger());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -171,28 +172,40 @@ public class MinecraftProvider extends DependencyProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadJars(Logger logger) 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);
|
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);
|
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 {
|
private void mergeJars(Logger logger) throws IOException {
|
||||||
logger.lifecycle(":merging jars");
|
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.enableSyntheticParamsOffset();
|
||||||
jarMerger.merge();
|
jarMerger.merge();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getMergedJar() {
|
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
|
@Override
|
||||||
|
|
|
@ -58,7 +58,7 @@ public abstract class AbstractRunTask extends JavaExec {
|
||||||
}
|
}
|
||||||
|
|
||||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||||
MinecraftVersionInfo minecraftVersionInfo = extension.getMinecraftProvider().versionInfo;
|
MinecraftVersionInfo minecraftVersionInfo = extension.getMinecraftProvider().getVersionInfo();
|
||||||
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
||||||
|
|
||||||
List<String> libs = new ArrayList<>();
|
List<String> libs = new ArrayList<>();
|
||||||
|
|
|
@ -32,18 +32,11 @@ import java.nio.file.FileSystems;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.BiFunction;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import org.cadixdev.lorenz.MappingSet;
|
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.Mercury;
|
||||||
import org.cadixdev.mercury.remapper.MercuryRemapper;
|
import org.cadixdev.mercury.remapper.MercuryRemapper;
|
||||||
import org.gradle.api.GradleException;
|
import org.gradle.api.GradleException;
|
||||||
|
@ -56,10 +49,7 @@ import net.fabricmc.loom.LoomGradleExtension;
|
||||||
import net.fabricmc.loom.providers.MappingsProvider;
|
import net.fabricmc.loom.providers.MappingsProvider;
|
||||||
import net.fabricmc.loom.providers.MinecraftMappedProvider;
|
import net.fabricmc.loom.providers.MinecraftMappedProvider;
|
||||||
import net.fabricmc.loom.util.SourceRemapper;
|
import net.fabricmc.loom.util.SourceRemapper;
|
||||||
import net.fabricmc.mapping.tree.ClassDef;
|
import net.fabricmc.lorenztiny.LorenzTiny;
|
||||||
import net.fabricmc.mapping.tree.Descriptored;
|
|
||||||
import net.fabricmc.mapping.tree.FieldDef;
|
|
||||||
import net.fabricmc.mapping.tree.MethodDef;
|
|
||||||
import net.fabricmc.mapping.tree.TinyMappingFactory;
|
import net.fabricmc.mapping.tree.TinyMappingFactory;
|
||||||
import net.fabricmc.mapping.tree.TinyTree;
|
import net.fabricmc.mapping.tree.TinyTree;
|
||||||
|
|
||||||
|
@ -159,14 +149,14 @@ public class MigrateMappingsTask extends AbstractLoomTask {
|
||||||
Path inputDir, Path outputDir, TinyTree currentMappings, TinyTree targetMappings
|
Path inputDir, Path outputDir, TinyTree currentMappings, TinyTree targetMappings
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
project.getLogger().lifecycle(":joining mappings");
|
project.getLogger().lifecycle(":joining mappings");
|
||||||
MappingSet mappingSet = new MappingsJoiner(currentMappings, targetMappings,
|
MappingSet mappingSet = LorenzTiny.readMappings(currentMappings, targetMappings,
|
||||||
"intermediary", "named").read();
|
"intermediary", "named").read();
|
||||||
|
|
||||||
project.getLogger().lifecycle(":remapping");
|
project.getLogger().lifecycle(":remapping");
|
||||||
Mercury mercury = SourceRemapper.createMercuryWithClassPath(project, false);
|
Mercury mercury = SourceRemapper.createMercuryWithClassPath(project, false);
|
||||||
|
|
||||||
mercury.getClassPath().add(minecraftMappedProvider.MINECRAFT_MAPPED_JAR.toPath());
|
mercury.getClassPath().add(minecraftMappedProvider.getMappedJar().toPath());
|
||||||
mercury.getClassPath().add(minecraftMappedProvider.MINECRAFT_INTERMEDIARY_JAR.toPath());
|
mercury.getClassPath().add(minecraftMappedProvider.getIntermediaryJar().toPath());
|
||||||
|
|
||||||
mercury.getProcessors().add(MercuryRemapper.create(mappingSet));
|
mercury.getProcessors().add(MercuryRemapper.create(mappingSet));
|
||||||
|
|
||||||
|
@ -179,72 +169,4 @@ public class MigrateMappingsTask extends AbstractLoomTask {
|
||||||
project.getLogger().lifecycle(":cleaning file descriptors");
|
project.getLogger().lifecycle(":cleaning file descriptors");
|
||||||
System.gc();
|
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<String, ClassDef> targetClasses = new HashMap<>();
|
|
||||||
Map<String, FieldDef> targetFields = new HashMap<>();
|
|
||||||
Map<String, MethodDef> 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 <T extends Descriptored> void mapMembers(Collection<T> oldMembers, Map<String, T> newMembers,
|
|
||||||
BiFunction<String, String, Mapping> 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() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,4 +58,13 @@ public class Checksum {
|
||||||
|
|
||||||
return false;
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,12 +50,10 @@ public class Constants {
|
||||||
public static final String INCLUDE = "include";
|
public static final String INCLUDE = "include";
|
||||||
public static final String MINECRAFT = "minecraft";
|
public static final String MINECRAFT = "minecraft";
|
||||||
public static final String MINECRAFT_DEPENDENCIES = "minecraftLibraries";
|
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_NAMED = "minecraftNamed";
|
||||||
public static final String MINECRAFT_LINEMAPPED = "minecraftLinemapped";
|
|
||||||
public static final String MAPPINGS = "mappings";
|
public static final String MAPPINGS = "mappings";
|
||||||
public static final String MAPPINGS_FINAL = "mappingsFinal";
|
public static final String MAPPINGS_FINAL = "mappingsFinal";
|
||||||
|
|
||||||
public static final String MIXIN_COMPILE_EXTENSIONS_VERSION = "0.3.0.4";
|
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";
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,16 +51,23 @@ import net.fabricmc.loom.LoomGradleExtension;
|
||||||
|
|
||||||
public abstract class DependencyProvider {
|
public abstract class DependencyProvider {
|
||||||
private LoomDependencyManager dependencyManager;
|
private LoomDependencyManager dependencyManager;
|
||||||
|
private final Project project;
|
||||||
|
private final LoomGradleExtension extension;
|
||||||
|
|
||||||
public abstract void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension, Consumer<Runnable> postPopulationScheduler) throws Exception;
|
public DependencyProvider(Project project) {
|
||||||
|
this.project = project;
|
||||||
|
this.extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void provide(DependencyInfo dependency, Consumer<Runnable> postPopulationScheduler) throws Exception;
|
||||||
|
|
||||||
public abstract String getTargetConfig();
|
public abstract String getTargetConfig();
|
||||||
|
|
||||||
public void addDependency(Object object, Project project) {
|
public void addDependency(Object object) {
|
||||||
addDependency(object, project, "compile");
|
addDependency(object, "compile");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDependency(Object object, Project project, String target) {
|
public void addDependency(Object object, String target) {
|
||||||
if (object instanceof File) {
|
if (object instanceof File) {
|
||||||
object = project.files(object);
|
object = project.files(object);
|
||||||
}
|
}
|
||||||
|
@ -76,6 +83,14 @@ public abstract class DependencyProvider {
|
||||||
return dependencyManager;
|
return dependencyManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Project getProject() {
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LoomGradleExtension getExtension() {
|
||||||
|
return extension;
|
||||||
|
}
|
||||||
|
|
||||||
public static class DependencyInfo {
|
public static class DependencyInfo {
|
||||||
final Project project;
|
final Project project;
|
||||||
final Dependency dependency;
|
final Dependency dependency;
|
||||||
|
|
|
@ -108,7 +108,7 @@ public class LoomDependencyManager {
|
||||||
DependencyProvider.DependencyInfo info = DependencyInfo.create(project, dependency, configuration);
|
DependencyProvider.DependencyInfo info = DependencyInfo.create(project, dependency, configuration);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
provider.provide(info, project, extension, afterTasks::add);
|
provider.provide(info, afterTasks::add);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Failed to provide " + dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion() + " : " + e.getMessage(), e);
|
throw new RuntimeException("Failed to provide " + dependency.getGroup() + ":" + dependency.getName() + ":" + dependency.getVersion() + " : " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||||
|
|
||||||
public class MapJarsTiny {
|
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";
|
String fromM = "official";
|
||||||
|
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
|
@ -48,8 +48,8 @@ public class MapJarsTiny {
|
||||||
Path[] classpath = mapProvider.getMapperPaths().stream().map(File::toPath).toArray(Path[]::new);
|
Path[] classpath = mapProvider.getMapperPaths().stream().map(File::toPath).toArray(Path[]::new);
|
||||||
|
|
||||||
Path input = jarProvider.getMergedJar().toPath();
|
Path input = jarProvider.getMergedJar().toPath();
|
||||||
Path outputMapped = mapProvider.getMappedJar().toPath();
|
Path outputMapped = mappedJar.toPath();
|
||||||
Path outputIntermediary = mapProvider.getIntermediaryJar().toPath();
|
Path outputIntermediary = intermediaryJar.toPath();
|
||||||
|
|
||||||
for (String toM : Arrays.asList("named", "intermediary")) {
|
for (String toM : Arrays.asList("named", "intermediary")) {
|
||||||
Path output = "named".equals(toM) ? outputMapped : outputIntermediary;
|
Path output = "named".equals(toM) ? outputMapped : outputIntermediary;
|
||||||
|
|
|
@ -149,7 +149,7 @@ public class ModProcessor {
|
||||||
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
MappingsProvider mappingsProvider = extension.getMappingsProvider();
|
||||||
|
|
||||||
Path inputPath = input.getAbsoluteFile().toPath();
|
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);
|
Path[] mcDeps = mappedProvider.getMapperPaths().stream().map(File::toPath).toArray(Path[]::new);
|
||||||
Set<Path> modCompiles = new HashSet<>();
|
Set<Path> modCompiles = new HashSet<>();
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class RunConfig {
|
||||||
default:
|
default:
|
||||||
runConfig.mainClass = "net.fabricmc.devlaunchinjector.Main";
|
runConfig.mainClass = "net.fabricmc.devlaunchinjector.Main";
|
||||||
runConfig.programArgs = "";
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ public class RunConfig {
|
||||||
public static RunConfig clientRunConfig(Project project) {
|
public static RunConfig clientRunConfig(Project project) {
|
||||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||||
MinecraftProvider minecraftProvider = extension.getMinecraftProvider();
|
MinecraftProvider minecraftProvider = extension.getMinecraftProvider();
|
||||||
MinecraftVersionInfo minecraftVersionInfo = minecraftProvider.versionInfo;
|
MinecraftVersionInfo minecraftVersionInfo = minecraftProvider.getVersionInfo();
|
||||||
|
|
||||||
RunConfig ideaClient = new RunConfig();
|
RunConfig ideaClient = new RunConfig();
|
||||||
populate(project, extension, ideaClient, "client");
|
populate(project, extension, ideaClient, "client");
|
||||||
|
@ -225,11 +225,20 @@ public class RunConfig {
|
||||||
return "net.fabricmc.loader.launch.knot.Knot" + side.substring(0, 1).toUpperCase(Locale.ROOT) + side.substring(1).toLowerCase(Locale.ROOT);
|
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) {
|
private static String encodeEscaped(String s) {
|
||||||
if (!input.contains(" ")) {
|
StringBuilder ret = new StringBuilder();
|
||||||
return input;
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,8 +77,8 @@ public class SourceRemapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m.getClassPath().add(extension.getMinecraftMappedProvider().MINECRAFT_MAPPED_JAR.toPath());
|
m.getClassPath().add(extension.getMinecraftMappedProvider().getMappedJar().toPath());
|
||||||
m.getClassPath().add(extension.getMinecraftMappedProvider().MINECRAFT_INTERMEDIARY_JAR.toPath());
|
m.getClassPath().add(extension.getMinecraftMappedProvider().getIntermediaryJar().toPath());
|
||||||
|
|
||||||
m.getProcessors().add(MercuryRemapper.create(mappings));
|
m.getProcessors().add(MercuryRemapper.create(mappings));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue