Lets get it working, and then write clean code
This commit is contained in:
parent
65bebb6fbc
commit
9e4012571a
9 changed files with 171 additions and 16 deletions
|
@ -38,7 +38,8 @@ public class OpenGradlePlugin extends AbstractPlugin {
|
|||
makeTask("mergeJars", MergeJarsTask.class).dependsOn("download");
|
||||
makeTask("processMods", ProcessModsTask.class).dependsOn("mergeJars");
|
||||
makeTask("mapJars", MapJarsTask.class).dependsOn("processMods");
|
||||
makeTask("setup", DefaultTask.class).dependsOn("mapJars").setGroup("openmodloader");
|
||||
makeTask("finaliseJars", FinaliseJar.class).dependsOn("mapJars");
|
||||
makeTask("setup", DefaultTask.class).dependsOn("finaliseJars").setGroup("openmodloader");
|
||||
|
||||
makeTask("extractNatives", ExtractNativesTask.class).dependsOn("download");
|
||||
makeTask("genIdeaWorkspace", GenIdeaProjectTask.class).dependsOn("idea").setGroup("ide");
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package net.fabricmc.loom.mixin;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.fabricmc.loom.task.ProcessModsTask;
|
||||
import net.fabricmc.loom.util.proccessing.MixinPrebaker;
|
||||
import org.spongepowered.asm.service.IClassBytecodeProvider;
|
||||
import org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper;
|
||||
|
||||
|
@ -17,6 +19,7 @@ public class MixinServiceGradle extends MixinServiceLaunchWrapper implements ICl
|
|||
|
||||
private static List<JarFile> jars = new ArrayList<>();
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "OpenModLoaderGradle";
|
||||
|
@ -24,6 +27,9 @@ public class MixinServiceGradle extends MixinServiceLaunchWrapper implements ICl
|
|||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String name) {
|
||||
if(MixinPrebaker.jarFileCache.containsKey(name)){
|
||||
return MixinPrebaker.jarFileCache.get(name);
|
||||
}
|
||||
for(JarFile file : jars){
|
||||
ZipEntry entry = file.getEntry(name);
|
||||
if(entry != null){
|
||||
|
@ -47,6 +53,14 @@ public class MixinServiceGradle extends MixinServiceLaunchWrapper implements ICl
|
|||
jars.add(new JarFile(minecraft));
|
||||
}
|
||||
|
||||
public static void addMCDeps(Set<File> deps, Object object) throws IOException {
|
||||
for(File mod : deps){
|
||||
JarFile jarFile = new JarFile(mod);
|
||||
jars.add(jarFile);
|
||||
ProcessModsTask.addFile(mod, object);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClassBytecodeProvider getBytecodeProvider() {
|
||||
return this;
|
||||
|
|
23
src/main/java/net/fabricmc/loom/task/FinaliseJar.java
Normal file
23
src/main/java/net/fabricmc/loom/task/FinaliseJar.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package net.fabricmc.loom.task;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FinaliseJar extends DefaultTask {
|
||||
|
||||
@TaskAction
|
||||
public void finalisejar() throws IOException {
|
||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
if(Constants.MINECRAFT_FINAL_JAR.get(extension).exists()){
|
||||
Constants.MINECRAFT_FINAL_JAR.get(extension).delete();
|
||||
}
|
||||
FileUtils.copyFile(Constants.MINECRAFT_MAPPED_JAR.get(extension), Constants.MINECRAFT_FINAL_JAR.get(extension));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -48,7 +48,7 @@ public class MapJarsTask extends DefaultTask {
|
|||
@TaskAction
|
||||
public void mapJars() throws IOException, MappingParseException {
|
||||
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
|
||||
if (!Constants.MINECRAFT_MAPPED_JAR.get(extension).exists() || extension.localMappings) {
|
||||
if (!Constants.MINECRAFT_MAPPED_JAR.get(extension).exists() || extension.localMappings || true) {
|
||||
if(extension.localMappings && Constants.MINECRAFT_MAPPED_JAR.get(extension).exists()){
|
||||
//Always remap the jar when using local mappings.
|
||||
Constants.MINECRAFT_MAPPED_JAR.get(extension).delete();
|
||||
|
|
|
@ -57,6 +57,7 @@ public class ProcessModsTask extends DefaultTask {
|
|||
Constants.MINECRAFT_FINAL_JAR.get(extension).delete();
|
||||
}
|
||||
if (mods.size() == 0) {
|
||||
getProject().getLogger().lifecycle(":skipping mixin prebake");
|
||||
FileUtils.copyFile(Constants.MINECRAFT_MERGED_JAR.get(extension), Constants.MINECRAFT_MIXED_JAR.get(extension));
|
||||
} else {
|
||||
downloadRequiredDeps(extension);
|
||||
|
|
|
@ -40,8 +40,9 @@ public class Constants {
|
|||
public static final IDelayed<File> MINECRAFT_CLIENT_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-client.jar"));
|
||||
public static final IDelayed<File> MINECRAFT_SERVER_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-server.jar"));
|
||||
public static final IDelayed<File> MINECRAFT_MERGED_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-merged.jar"));
|
||||
public static final IDelayed<File> MINECRAFT_MIXED_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-mixed.jar"));
|
||||
public static final IDelayed<File> MINECRAFT_MAPPED_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.getVersionString() + "-mapped-" + extension.pomfVersion + ".jar"));
|
||||
public static final IDelayed<File> MINECRAFT_FINAL_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.getVersionString() + "-mixed-" + extension.pomfVersion + ".jar"));
|
||||
public static final IDelayed<File> MINECRAFT_FINAL_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.getVersionString() + "-final-" + extension.pomfVersion + ".jar"));
|
||||
|
||||
public static final IDelayed<File> POMF_DIR = new DelayedFile(extension -> new File(extension.getUserCache(), "pomf"));
|
||||
public static IDelayed<File> MAPPINGS_ZIP = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomfVersion + ".zip"));
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
package net.fabricmc.loom.util.proccessing;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import net.fabricmc.tinyremapper.TinyUtils;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
import org.spongepowered.asm.mixin.extensibility.IRemapper;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MixinDevRemapper implements IRemapper {
|
||||
private final BiMap<String, String> classMap = HashBiMap.create();
|
||||
private final Map<TinyUtils.Mapping, TinyUtils.Mapping> fieldMap = new HashMap<>();
|
||||
private final Map<TinyUtils.Mapping, TinyUtils.Mapping> methodMap = new HashMap<>();
|
||||
|
||||
private final SimpleClassMapper classMapper = new SimpleClassMapper(classMap);
|
||||
private final SimpleClassMapper classUnmapper = new SimpleClassMapper(classMap.inverse());
|
||||
|
||||
private static class SimpleClassMapper extends Remapper {
|
||||
final Map<String, String> classMap;
|
||||
|
||||
public SimpleClassMapper(Map<String, String> map) {
|
||||
this.classMap = map;
|
||||
}
|
||||
|
||||
public String map(String typeName) {
|
||||
return this.classMap.getOrDefault(typeName, typeName);
|
||||
}
|
||||
}
|
||||
|
||||
public void readMapping(BufferedReader reader, String fromM, String toM) throws IOException {
|
||||
TinyUtils.read(reader, fromM, toM, classMap::put, fieldMap::put, methodMap::put);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapMethodName(String owner, String name, String desc) {
|
||||
TinyUtils.Mapping mapping = methodMap.get(new TinyUtils.Mapping(owner, name, desc));
|
||||
return mapping != null ? mapping.name : name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapFieldName(String owner, String name, String desc) {
|
||||
TinyUtils.Mapping mapping = fieldMap.get(new TinyUtils.Mapping(owner, name, desc));
|
||||
if(mapping == null){
|
||||
//We try again using obfed names
|
||||
owner = unmap(owner);
|
||||
desc = unmapDesc(desc);
|
||||
mapping = fieldMap.get(new TinyUtils.Mapping(owner, name, desc));
|
||||
}
|
||||
return mapping != null ? mapping.name : name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String map(String typeName) {
|
||||
return classMap.getOrDefault(typeName, typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String unmap(String typeName) {
|
||||
return classMap.inverse().getOrDefault(typeName, typeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapDesc(String desc) {
|
||||
return classMapper.mapDesc(desc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String unmapDesc(String desc) {
|
||||
return classUnmapper.mapDesc(desc);
|
||||
}
|
||||
}
|
|
@ -24,6 +24,7 @@ import com.google.gson.JsonObject;
|
|||
import net.fabricmc.loom.mixin.MixinServiceGradle;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
import org.gradle.api.Project;
|
||||
import org.objectweb.asm.*;
|
||||
import org.spongepowered.asm.launch.GlobalProperties;
|
||||
import org.spongepowered.asm.launch.MixinBootstrap;
|
||||
|
@ -31,6 +32,7 @@ import org.spongepowered.asm.mixin.EnvironmentStateTweaker;
|
|||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.Mixins;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinTransformer;
|
||||
import org.spongepowered.asm.service.MixinService;
|
||||
import org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -121,9 +123,10 @@ public class MixinPrebaker {
|
|||
|
||||
public static final String APPLIED_MIXIN_CONFIGS_FILENAME = ".oml-applied-mixin-configs";
|
||||
public static final String MAPPINGS_FILENAME = ".oml-dev-mappings.tiny";
|
||||
public static MixinTransformer mixinTransformer;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
public static Map<String, InputStream> jarFileCache = new HashMap<>();
|
||||
|
||||
public static void main(String[] args, Project project) throws IOException {
|
||||
boolean hasMappingsFile = false;
|
||||
|
||||
if (args.length < 3) {
|
||||
|
@ -144,6 +147,8 @@ public class MixinPrebaker {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Set<File> modFiles = new HashSet<>();
|
||||
for (int i = argOffset + 2; i < args.length; i++) {
|
||||
modFiles.add(new File(args[i]));
|
||||
|
@ -173,22 +178,33 @@ public class MixinPrebaker {
|
|||
|
||||
MixinServiceGradle.setupModFiles(modFiles, new File(args[argOffset + 0]));
|
||||
|
||||
|
||||
EnvironmentStateTweaker tweaker = new EnvironmentStateTweaker();
|
||||
tweaker.getLaunchArguments();
|
||||
tweaker.injectIntoClassLoader(Launch.classLoader);
|
||||
|
||||
if(mixinTransformer == null){
|
||||
mixinTransformer = GlobalProperties.get(GlobalProperties.Keys.TRANSFORMER);
|
||||
}
|
||||
//Check to ensure its not null
|
||||
if(mixinTransformer == null){
|
||||
throw new RuntimeException("Failed to get MixinTransformer!");
|
||||
}
|
||||
//MixinServiceGradle.addMCDeps(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getFiles(), tweaker);
|
||||
|
||||
MixinEnvironment mixinEnvironment = MixinEnvironment.getDefaultEnvironment();
|
||||
|
||||
System.out.println("Loading mappings: " + mappingsFile);
|
||||
InputStream mappingStream = new FileInputStream(mappingsFile);
|
||||
MixinDevRemapper devRemapper = new MixinDevRemapper();
|
||||
devRemapper.readMapping(new BufferedReader(new InputStreamReader(mappingStream)), "pomf", "mojang");
|
||||
mappingStream.close();
|
||||
mixinEnvironment.getRemappers().add(devRemapper);
|
||||
|
||||
mixinEnvironment.setSide(MixinEnvironment.Side.CLIENT); //TODO have an all side?
|
||||
|
||||
|
||||
MixinTransformer mixinTransformer = GlobalProperties.get(GlobalProperties.Keys.TRANSFORMER);
|
||||
if(mixinTransformer == null){
|
||||
MixinService.getService().beginPhase();
|
||||
mixinTransformer = GlobalProperties.get(GlobalProperties.Keys.TRANSFORMER);
|
||||
}
|
||||
mixinTransformer.audit(mixinEnvironment);
|
||||
|
||||
|
||||
try {
|
||||
JarInputStream input = new JarInputStream(new FileInputStream(new File(args[argOffset + 0])));
|
||||
JarOutputStream output = new JarOutputStream(new FileOutputStream(new File(args[argOffset + 1])));
|
||||
|
@ -272,6 +288,30 @@ public class MixinPrebaker {
|
|||
ZipEntry entry = file.getEntry("mod.json");
|
||||
if (entry == null)
|
||||
return null;
|
||||
return gson.fromJson(new InputStreamReader(file.getInputStream(entry)), JsonArray.class);
|
||||
|
||||
InputStreamReader stream = new InputStreamReader(file.getInputStream(entry));
|
||||
JsonArray jsonArray = gson.fromJson(stream, JsonArray.class);
|
||||
stream.close();
|
||||
|
||||
List<String> mixins = new ArrayList<>();
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JsonObject modObject = jsonArray.get(i).getAsJsonObject();
|
||||
mixins.addAll(findMixins(modObject.getAsJsonArray("mixins")));
|
||||
mixins.addAll(findMixins(modObject.getAsJsonArray("clientMixins")));
|
||||
mixins.addAll(findMixins(modObject.getAsJsonArray("serverMixins")));
|
||||
}
|
||||
|
||||
System.out.println("Found: " + mixins.size() + " mixins in " + file.getName());
|
||||
|
||||
mixins.forEach(s -> {
|
||||
ZipEntry entry1 = file.getEntry(s);
|
||||
try {
|
||||
jarFileCache.put(s, file.getInputStream(entry1));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to load jar", e);
|
||||
}
|
||||
});
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
}
|
|
@ -41,13 +41,13 @@ public class PreBakeMixins {
|
|||
args[0] = "-m";
|
||||
args[1] = Constants.MAPPINGS_TINY.get(extension).getAbsolutePath();
|
||||
args[2] = Constants.MINECRAFT_MERGED_JAR.get(extension).getAbsolutePath();
|
||||
args[3] = Constants.MINECRAFT_MAPPED_JAR.get(extension).getAbsolutePath();
|
||||
args[3] = Constants.MINECRAFT_MIXED_JAR.get(extension).getAbsolutePath();
|
||||
for (int i = 0; i < mods.size(); i++) {
|
||||
args[i + 4] = mods.get(i).getAbsolutePath();
|
||||
}
|
||||
project.getLogger().lifecycle(":preBaking mixins");
|
||||
ProcessModsTask.addFile(Constants.MINECRAFT_MERGED_JAR.get(extension), this);
|
||||
MixinPrebaker.main(args);
|
||||
ProcessModsTask.addFile(Constants.MINECRAFT_MIXED_JAR.get(extension), this);
|
||||
MixinPrebaker.main(args, project);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue