Split mappings and minecraft

dev/0.11
modmuss50 2018-11-05 15:54:14 +00:00
parent 8e3822dec7
commit 94c7137086
14 changed files with 77 additions and 66 deletions

View File

@ -27,6 +27,7 @@ package net.fabricmc.loom;
import com.google.common.collect.ImmutableMap;
import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.providers.ModRemapperProvider;
import net.fabricmc.loom.providers.PomfProvider;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.LoomDependencyManager;
import net.fabricmc.loom.util.ModRemapper;
@ -74,6 +75,8 @@ public class AbstractPlugin implements Plugin<Project> {
Configuration minecraftConfig = project.getConfigurations().maybeCreate(Constants.MINECRAFT);
minecraftConfig.setTransitive(false); // The launchers do not recurse dependencies
project.getConfigurations().maybeCreate(Constants.MAPPINGS);
configureIDEs();
configureCompile();
@ -88,8 +91,8 @@ public class AbstractPlugin implements Plugin<Project> {
javaCompileTask.doFirst(task1 -> {
project.getLogger().lifecycle(":setting java compiler args");
try {
javaCompileTask.getOptions().getCompilerArgs().add("-AinMapFileNamedIntermediary=" + extension.getMinecraftProvider().pomfProvider.MAPPINGS_TINY.getCanonicalPath());
javaCompileTask.getOptions().getCompilerArgs().add("-AoutMapFileNamedIntermediary=" + extension.getMinecraftProvider().pomfProvider.MAPPINGS_MIXIN_EXPORT.getCanonicalPath());
javaCompileTask.getOptions().getCompilerArgs().add("-AinMapFileNamedIntermediary=" + extension.getPomfProvider().MAPPINGS_TINY.getCanonicalPath());
javaCompileTask.getOptions().getCompilerArgs().add("-AoutMapFileNamedIntermediary=" + extension.getPomfProvider().MAPPINGS_MIXIN_EXPORT.getCanonicalPath());
if(extension.refmapName == null || extension.refmapName.isEmpty()){
project.getLogger().error("Could not find refmap definition, will be using default name: " + project.getName() + "-refmap.json");
extension.refmapName = project.getName() + "-refmap.json";
@ -207,6 +210,7 @@ public class AbstractPlugin implements Plugin<Project> {
LoomDependencyManager dependencyManager = new LoomDependencyManager();
extension.setDependencyManager(dependencyManager);
dependencyManager.addProvider(new PomfProvider());
dependencyManager.addProvider(new MinecraftProvider());
dependencyManager.addProvider(new ModRemapperProvider());

View File

@ -25,6 +25,7 @@
package net.fabricmc.loom;
import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.providers.PomfProvider;
import net.fabricmc.loom.util.LoomDependencyManager;
import org.gradle.api.Project;
@ -58,6 +59,10 @@ public class LoomGradleExtension {
return getDependencyManager().getProvider(MinecraftProvider.class);
}
public PomfProvider getPomfProvider(){
return getDependencyManager().getProvider(PomfProvider.class);
}
public void setDependencyManager(LoomDependencyManager dependencyManager) {
this.dependencyManager = dependencyManager;
}

View File

@ -88,16 +88,13 @@ public class MinecraftJarProvider {
private void initFiles(Project project, MinecraftProvider minecraftProvider) {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
PomfProvider pomfProvider = extension.getPomfProvider();
MINECRAFT_INTERMEDIARY_JAR = new File(extension.getUserCache(), minecraftProvider.minecraftVersion + "-intermediary.jar");
MINECRAFT_MERGED_JAR = new File(extension.getUserCache(), minecraftProvider.minecraftVersion + "-merged.jar");
MINECRAFT_MAPPED_JAR = new File(extension.getUserCache(), minecraftProvider.minecraftVersion + "-mapped-" + minecraftProvider.pomfVersion + ".jar");
MINECRAFT_MAPPED_JAR = new File(extension.getUserCache(), minecraftProvider.minecraftVersion + "-mapped-" + pomfProvider.pomfVersion + ".jar");
}
public File getMappingFile() {
return minecraftProvider.pomfProvider.MAPPINGS_TINY;
}
public Collection<File> getMapperPaths() {
return minecraftProvider.libraryProvider.getLibraries();
}

View File

@ -42,9 +42,7 @@ import java.util.Optional;
public class MinecraftProvider extends DependencyProvider {
public String minecraftVersion;
public String pomfVersion;
public PomfProvider pomfProvider;
public MinecraftVersionInfo versionInfo;
public MinecraftLibraryProvider libraryProvider;
public MinecraftJarProvider jarProvider;
@ -58,8 +56,7 @@ public class MinecraftProvider extends DependencyProvider {
@Override
public void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension) throws Exception {
minecraftVersion = dependency.getDependency().getName();
pomfVersion = dependency.getDependency().getVersion();
minecraftVersion = dependency.getDependency().getVersion();
initFiles(project);
@ -74,8 +71,6 @@ public class MinecraftProvider extends DependencyProvider {
libraryProvider = new MinecraftLibraryProvider();
libraryProvider.provide(this, project);
pomfProvider = new PomfProvider(pomfVersion, minecraftVersion, project);
jarProvider = new MinecraftJarProvider(project, this);
}
@ -96,7 +91,7 @@ public class MinecraftProvider extends DependencyProvider {
if (optionalVersion.isPresent()) {
FileUtils.copyURLToFile(new URL(optionalVersion.get().url), MINECRAFT_JSON);
} else {
throw new RuntimeException("Failed to download minecraft json");
throw new RuntimeException("Failed to find minecraft version: " + minecraftVersion);
}
}

View File

@ -39,13 +39,20 @@ public class ModRemapperProvider extends DependencyProvider {
project.getLogger().lifecycle("Providing " + dependency.getDepString());
MinecraftProvider minecraftProvider = getDependencyManager().getProvider(MinecraftProvider.class);
PomfProvider pomfProvider = getDependencyManager().getProvider(PomfProvider.class);
String outputName = input.getName().substring(0, input.getName().length() - 4) + "-mapped-" + minecraftProvider.pomfVersion + ".jar";//TODO use the hash of the input file or something?
String outputName = input.getName().substring(0, input.getName().length() - 4) + "-mapped-" + pomfProvider.pomfVersion + ".jar";//TODO use the hash of the input file or something?
File output = new File(Constants.REMAPPED_MODS_STORE, outputName);
if(output.exists()){
output.delete();
}
ModProcessor.handleMod(input, output, project);
if(!output.exists()){
throw new RuntimeException("Failed to remap mod");
}
addDependency(output, project);
}

View File

@ -26,63 +26,52 @@ package net.fabricmc.loom.providers;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants;
import org.apache.commons.io.FileUtils;
import net.fabricmc.loom.util.DependencyProvider;
import org.gradle.api.Project;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.zip.GZIPInputStream;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
//TODO fix local mappings
//TODO possibly use maven for mappings, can fix above at the same time
public class PomfProvider {
public class PomfProvider extends DependencyProvider {
public String minecraftVersion;
public String pomfVersion;
public File POMF_DIR;
public File MAPPINGS_TINY_GZ;
private File POMF_DIR;
public File MAPPINGS_TINY;
public File MAPPINGS_MIXIN_EXPORT;
public PomfProvider(String pomfVersion, String minecraftVersion, Project project) {
this.pomfVersion = pomfVersion;
this.minecraftVersion = minecraftVersion;
initFiles(project);
try {
init(project);
} catch (Exception e) {
throw new RuntimeException("Failed to setup pomf", e);
}
}
@Override
public void provide(DependencyInfo dependency, Project project, LoomGradleExtension extension) throws Exception {
project.getLogger().lifecycle(":setting up pomf " + dependency.getDependency().getVersion());
public void init(Project project) throws IOException {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
project.getLogger().lifecycle(":setting up pomf " + pomfVersion);
String version = dependency.getDependency().getVersion();
String[] split = version.split("\\.");
File mappingsJar = dependency.resolveFile();
this.pomfVersion = split[0];
this.minecraftVersion = split[1];
initFiles(project);
if (!POMF_DIR.exists()) {
POMF_DIR.mkdir();
}
if (!MAPPINGS_TINY_GZ.exists()) {
FileUtils.copyURLToFile(
new URL(String.format("%1$s%2$s.%3$s/pomf-%2$s.%3$s-tiny.gz", Constants.POMF_MAVEN_SERVER, minecraftVersion, pomfVersion)),
MAPPINGS_TINY_GZ);
}
if (!MAPPINGS_TINY.exists()) {
GZIPInputStream gzipInputStream = new GZIPInputStream(new FileInputStream(MAPPINGS_TINY_GZ));
FileOutputStream fileOutputStream = new FileOutputStream(MAPPINGS_TINY);
int length;
byte[] buffer = new byte[4096];
while ((length = gzipInputStream.read(buffer)) > 0) {
fileOutputStream.write(buffer, 0, length);
project.getLogger().lifecycle(":extracting " + mappingsJar.getName());
try (FileSystem fileSystem = FileSystems.newFileSystem(mappingsJar.toPath(), null)) {
Path fileToExtract = fileSystem.getPath("mappings/mappings.tiny");
Files.copy(fileToExtract, MAPPINGS_TINY.toPath());
}
gzipInputStream.close();
fileOutputStream.close();
}
}
@ -90,9 +79,12 @@ public class PomfProvider {
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
POMF_DIR = new File(extension.getUserCache(), "pomf");
MAPPINGS_TINY_GZ = new File(POMF_DIR, "pomf-tiny-" + minecraftVersion + "." + pomfVersion + ".gz");
MAPPINGS_TINY = new File(POMF_DIR, "pomf-tiny-" + minecraftVersion + "." + pomfVersion);
MAPPINGS_MIXIN_EXPORT = new File(Constants.CACHE_FILES, "mixin-map-" + minecraftVersion + "." + pomfVersion + ".tiny");
}
@Override
public String getTargetConfig() {
return Constants.MAPPINGS;
}
}

View File

@ -25,6 +25,7 @@
package net.fabricmc.loom.task;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.PomfProvider;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.MinecraftVersionInfo;
import org.gradle.api.tasks.JavaExec;
@ -39,6 +40,7 @@ public class RunClientTask extends JavaExec {
public void exec() {
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
MinecraftVersionInfo minecraftVersionInfo = extension.getMinecraftProvider().versionInfo;
PomfProvider pomfProvider = extension.getPomfProvider();
List<String> libs = new ArrayList<>();
@ -53,7 +55,7 @@ public class RunClientTask extends JavaExec {
}
classpath(libs);
args("--tweakClass", Constants.FABRIC_CLIENT_TWEAKER, "--assetIndex", minecraftVersionInfo.assetIndex.getFabricId(extension.getMinecraftProvider().minecraftVersion), "--assetsDir", new File(extension.getUserCache(), "assets").getAbsolutePath(), "--fabricMappingFile", extension.getMinecraftProvider().pomfProvider.MAPPINGS_TINY.getAbsolutePath());
args("--tweakClass", Constants.FABRIC_CLIENT_TWEAKER, "--assetIndex", minecraftVersionInfo.assetIndex.getFabricId(extension.getMinecraftProvider().minecraftVersion), "--assetsDir", new File(extension.getUserCache(), "assets").getAbsolutePath(), "--fabricMappingFile", pomfProvider.MAPPINGS_TINY.getAbsolutePath());
setWorkingDir(new File(getProject().getRootDir(), "run"));

View File

@ -50,7 +50,7 @@ public class RunServerTask extends JavaExec {
}
classpath(libs);
args("--tweakClass", Constants.FABRIC_SERVER_TWEAKER, "--fabricMappingFile", extension.getMinecraftProvider().pomfProvider.MAPPINGS_TINY.getAbsolutePath());
args("--tweakClass", Constants.FABRIC_SERVER_TWEAKER, "--fabricMappingFile", extension.getPomfProvider().MAPPINGS_TINY.getAbsolutePath());
setWorkingDir(new File(getProject().getRootDir(), "run"));

View File

@ -44,4 +44,5 @@ public class Constants {
public static final String COMPILE_MODS = "modCompile";
public static final String MINECRAFT = "minecraft";
public static final String MAPPINGS = "mappings";
}

View File

@ -28,6 +28,7 @@ import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.providers.PomfProvider;
import org.apache.commons.io.IOUtils;
import org.gradle.api.Project;
import org.w3c.dom.Document;
@ -84,7 +85,8 @@ public class IdeaRunConfig {
public static IdeaRunConfig clientRunConfig(Project project){
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
MinecraftProvider minecraftProvider = extension.getDependencyManager().getProvider(MinecraftProvider.class);
MinecraftProvider minecraftProvider = extension.getMinecraftProvider();
PomfProvider pomfProvider = extension.getPomfProvider();
MinecraftVersionInfo minecraftVersionInfo = minecraftProvider.versionInfo;
IdeaRunConfig ideaClient = new IdeaRunConfig();
@ -93,15 +95,14 @@ public class IdeaRunConfig {
ideaClient.configName = "Minecraft Client";
ideaClient.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
ideaClient.vmArgs = "-Dfabric.development=true";
ideaClient.programArgs = "--tweakClass " + Constants.FABRIC_CLIENT_TWEAKER + " --assetIndex " + minecraftVersionInfo.assetIndex.getFabricId(extension.getMinecraftProvider().minecraftVersion) + " --assetsDir \"" + new File(extension.getUserCache(), "assets").getAbsolutePath() + "\" --fabricMappingFile \"" + minecraftProvider.pomfProvider.MAPPINGS_TINY.getAbsolutePath() + "\"";
ideaClient.programArgs = "--tweakClass " + Constants.FABRIC_CLIENT_TWEAKER + " --assetIndex " + minecraftVersionInfo.assetIndex.getFabricId(extension.getMinecraftProvider().minecraftVersion) + " --assetsDir \"" + new File(extension.getUserCache(), "assets").getAbsolutePath() + "\" --fabricMappingFile \"" + pomfProvider.MAPPINGS_TINY.getAbsolutePath() + "\"";
return ideaClient;
}
public static IdeaRunConfig serverRunConfig(Project project){
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
MinecraftProvider minecraftProvider = extension.getDependencyManager().getProvider(MinecraftProvider.class);
MinecraftVersionInfo minecraftVersionInfo = minecraftProvider.versionInfo;
PomfProvider pomfProvider = extension.getPomfProvider();
IdeaRunConfig ideaServer = new IdeaRunConfig();
ideaServer.mainClass = "net.minecraft.launchwrapper.Launch";
@ -109,7 +110,7 @@ public class IdeaRunConfig {
ideaServer.configName = "Minecraft Server";
ideaServer.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
ideaServer.vmArgs = "-Dfabric.development=true";
ideaServer.programArgs = "--tweakClass " + Constants.FABRIC_SERVER_TWEAKER + " --fabricMappingFile \"" + minecraftProvider.pomfProvider.MAPPINGS_TINY.getAbsolutePath() + "\"";
ideaServer.programArgs = "--tweakClass " + Constants.FABRIC_SERVER_TWEAKER + " --fabricMappingFile \"" + pomfProvider.MAPPINGS_TINY.getAbsolutePath() + "\"";
return ideaServer;
}

View File

@ -29,9 +29,7 @@ import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class LoomDependencyManager {
@ -60,7 +58,7 @@ public class LoomDependencyManager {
public void handleDependencies(Project project){
project.getLogger().lifecycle(":setting up loom dependencies");
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
Set<String> targetConfigs = new HashSet<>();
List<String> targetConfigs = new ArrayList<>();
for(DependencyProvider provider : dependencyProviderList){
targetConfigs.add(provider.getTargetConfig());
}

View File

@ -25,7 +25,9 @@
package net.fabricmc.loom.util;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MinecraftJarProvider;
import net.fabricmc.loom.providers.PomfProvider;
import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils;
@ -41,7 +43,10 @@ public class MapJarsTiny {
public void mapJars(MinecraftJarProvider jarProvider, Project project) throws IOException {
String fromM = "official";
Path mappings = jarProvider.getMappingFile().toPath();
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
PomfProvider pomfProvider = extension.getPomfProvider();
Path mappings = pomfProvider.MAPPINGS_TINY.toPath();
Path[] classpath = jarProvider.getMapperPaths().stream()
.map(File::toPath)
.toArray(Path[]::new);

View File

@ -30,6 +30,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.providers.PomfProvider;
import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils;
@ -79,8 +80,9 @@ public class ModProcessor {
String toM = "named";
MinecraftProvider minecraftProvider = extension.getMinecraftProvider();
PomfProvider pomfProvider = extension.getPomfProvider();
File mappingsFile = minecraftProvider.pomfProvider.MAPPINGS_TINY;
File mappingsFile = pomfProvider.MAPPINGS_TINY;
Path mappings = mappingsFile.toPath();
Path mc = minecraftProvider.jarProvider.MINECRAFT_INTERMEDIARY_JAR.toPath();
Path[] mcDeps = minecraftProvider.jarProvider.getMapperPaths().stream()

View File

@ -26,6 +26,7 @@ package net.fabricmc.loom.util;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.providers.PomfProvider;
import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils;
@ -51,8 +52,9 @@ public class ModRemapper {
}
MinecraftProvider minecraftProvider = extension.getMinecraftProvider();
PomfProvider pomfProvider = extension.getPomfProvider();
Path mappings = minecraftProvider.pomfProvider.MAPPINGS_TINY.toPath();
Path mappings = pomfProvider.MAPPINGS_TINY.toPath();
String fromM = "named";
String toM = "intermediary";
@ -62,7 +64,7 @@ public class ModRemapper {
Path[] classpath = classpathFiles.stream().map(File::toPath).toArray(Path[]::new);
File mixinMapFile = extension.getMinecraftProvider().pomfProvider.MAPPINGS_MIXIN_EXPORT;
File mixinMapFile = pomfProvider.MAPPINGS_MIXIN_EXPORT;
Path mixinMapPath = mixinMapFile.toPath();
TinyRemapper.Builder remapperBuilder = TinyRemapper.newRemapper();