Fix mod obof, and add property to specify refmapName

dev/0.11
modmuss50 2016-10-20 16:55:46 +01:00
parent 14fb337330
commit 9f959ef04d
No known key found for this signature in database
GPG Key ID: 773D17BE8BF49C82
10 changed files with 172 additions and 175 deletions

View File

@ -57,7 +57,7 @@ dependencies {
shade 'commons-io:commons-io:1.4' shade 'commons-io:commons-io:1.4'
shade 'com.google.guava:guava:19.0' shade 'com.google.guava:guava:19.0'
shade 'net.fabricmc:weave:0.1.0.6' shade 'net.fabricmc:weave:0.1.0.6'
shade 'cuchaz:enigma:0.11.0.5:lib' shade 'cuchaz:enigma:0.11.0.19:lib'
shade 'net.fabricmc:tiny-remapper:+' shade 'net.fabricmc:tiny-remapper:+'
compile 'net.fabricmc:fabric-base:16w38a-0.0.4-SNAPSHOT' compile 'net.fabricmc:fabric-base:16w38a-0.0.4-SNAPSHOT'

View File

@ -30,14 +30,13 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.fabricmc.loom.task.DownloadTask; import net.fabricmc.loom.task.DownloadTask;
import net.fabricmc.loom.task.GenIdeaProjectTask; import net.fabricmc.loom.task.GenIdeaProjectTask;
import net.fabricmc.loom.util.ModRemapper;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.ModRemapper;
import net.fabricmc.loom.util.Version; import net.fabricmc.loom.util.Version;
import org.gradle.api.Plugin; import org.gradle.api.Plugin;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.Task; import org.gradle.api.Task;
import org.gradle.api.artifacts.repositories.MavenArtifactRepository; import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
import org.gradle.api.internal.file.collections.FileCollectionAdapter;
import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSet;
@ -97,7 +96,7 @@ public class AbstractPlugin implements Plugin<Project> {
Set<Task> taskSet = entry.getValue(); Set<Task> taskSet = entry.getValue();
for (Task task : taskSet) { for (Task task : taskSet) {
if (task instanceof JavaCompile if (task instanceof JavaCompile
&& !(task.getName().contains("Test")) && !(task.getName().contains("test"))) { && !(task.getName().contains("Test")) && !(task.getName().contains("test"))) {
JavaCompile javaCompileTask = (JavaCompile) task; JavaCompile javaCompileTask = (JavaCompile) task;
javaCompileTask.doFirst(task1 -> { javaCompileTask.doFirst(task1 -> {
project.getLogger().lifecycle(":setting java compiler args"); project.getLogger().lifecycle(":setting java compiler args");
@ -105,8 +104,8 @@ public class AbstractPlugin implements Plugin<Project> {
javaCompileTask.getClasspath().add(target.files(this.getClass().getProtectionDomain().getCodeSource().getLocation())); javaCompileTask.getClasspath().add(target.files(this.getClass().getProtectionDomain().getCodeSource().getLocation()));
javaCompileTask.getOptions().getCompilerArgs().add("-AinMapFilePomfMojang=" + Constants.MAPPINGS_TINY.get(extension).getCanonicalPath()); javaCompileTask.getOptions().getCompilerArgs().add("-AinMapFilePomfMojang=" + Constants.MAPPINGS_TINY.get(extension).getCanonicalPath());
javaCompileTask.getOptions().getCompilerArgs().add("-AoutMapFilePomfMojang=" + Constants.MAPPINGS_MIXIN_EXPORT.get(extension).getCanonicalPath()); javaCompileTask.getOptions().getCompilerArgs().add("-AoutMapFilePomfMojang=" + Constants.MAPPINGS_MIXIN_EXPORT.get(extension).getCanonicalPath());
javaCompileTask.getOptions().getCompilerArgs().add("-AoutRefMapFile=" + new File(javaCompileTask.getDestinationDir(), ".mixin-refmap.json").getCanonicalPath()); javaCompileTask.getOptions().getCompilerArgs().add("-AoutRefMapFile=" + new File(javaCompileTask.getDestinationDir(), extension.refmapName).getCanonicalPath());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -267,7 +266,6 @@ public class AbstractPlugin implements Plugin<Project> {
}); });
}); });
} }
protected void readModJson(LoomGradleExtension extension) { protected void readModJson(LoomGradleExtension extension) {

View File

@ -33,6 +33,7 @@ public class LoomGradleExtension {
public String runDir = "run"; public String runDir = "run";
public String fabricVersion; public String fabricVersion;
public String pomfVersion; public String pomfVersion;
public String refmapName;
//Not to be set in the build.gradle //Not to be set in the build.gradle
public Project project; public Project project;

View File

@ -37,103 +37,108 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
public class MixinMappingProviderTiny extends MappingProvider { public class MixinMappingProviderTiny extends MappingProvider {
private final String from, to; private final String from, to;
public MixinMappingProviderTiny(Messager messager, Filer filer, String from, String to) { public MixinMappingProviderTiny(Messager messager, Filer filer, String from, String to) {
super(messager, filer); super(messager, filer);
this.from = from; this.from = from;
this.to = to; this.to = to;
} }
private static final String[] removeFirst(String[] src, int count) { private static final String[] removeFirst(String[] src, int count) {
if (count >= src.length) { if (count >= src.length) {
return new String[0]; return new String[0];
} else { } else {
String[] out = new String[src.length - count]; String[] out = new String[src.length - count];
System.arraycopy(src, count, out, 0, out.length); System.arraycopy(src, count, out, 0, out.length);
return out; return out;
} }
} }
@Override
public MappingMethod getMethodMapping(MappingMethod method) {
System.out.println("processing " + method.getName() + method.getDesc());
@Override MappingMethod mapped = this.methodMap.get(method);
public MappingMethod getMethodMapping(MappingMethod method) { if (mapped != null)
System.out.println("processing " + method.getName() + method.getDesc()); return mapped;
MappingMethod mapped = this.methodMap.get(method); try {
if (mapped != null) return mapped; Class c = this.getClass().getClassLoader().loadClass(method.getOwner().replace('/', '.'));
if (c == null || c == Object.class) {
return null;
}
try { for (Class cc : c.getInterfaces()) {
Class c = this.getClass().getClassLoader().loadClass(method.getOwner().replace('/', '.')); mapped = getMethodMapping(method.move(cc.getName().replace('.', '/')));
if (c == null || c == Object.class) { if (mapped != null)
return null; return mapped;
} }
for (Class cc : c.getInterfaces()) { if (c.getSuperclass() != null) {
mapped = getMethodMapping(method.move(cc.getName().replace('.', '/'))); mapped = getMethodMapping(method.move(c.getSuperclass().getName().replace('.', '/')));
if (mapped != null) return mapped; if (mapped != null)
} return mapped;
}
if (c.getSuperclass() != null) { return null;
mapped = getMethodMapping(method.move(c.getSuperclass().getName().replace('.', '/'))); } catch (Exception e) {
if (mapped != null) return mapped; e.printStackTrace();
} return null;
}
}
return null; @Override
} catch (Exception e) { public MappingField getFieldMapping(MappingField field) {
e.printStackTrace(); System.out.println("processing " + field.getOwner() + "/" + field.getName() + field.getDesc());
return null;
}
}
@Override MappingField mapped = this.fieldMap.get(field);
public MappingField getFieldMapping(MappingField field) { if (mapped != null)
System.out.println("processing " + field.getOwner() + "/" + field.getName() + field.getDesc()); return mapped;
MappingField mapped = this.fieldMap.get(field); try {
if (mapped != null) return mapped; Class c = this.getClass().getClassLoader().loadClass(field.getOwner().replace('/', '.'));
if (c == null || c == Object.class) {
return null;
}
try { for (Class cc : c.getInterfaces()) {
Class c = this.getClass().getClassLoader().loadClass(field.getOwner().replace('/', '.')); mapped = getFieldMapping(field.move(cc.getName().replace('.', '/')));
if (c == null || c == Object.class) { if (mapped != null)
return null; return mapped;
} }
for (Class cc : c.getInterfaces()) { if (c.getSuperclass() != null) {
mapped = getFieldMapping(field.move(cc.getName().replace('.', '/'))); mapped = getFieldMapping(field.move(c.getSuperclass().getName().replace('.', '/')));
if (mapped != null) return mapped; if (mapped != null)
} return mapped;
}
if (c.getSuperclass() != null) { return null;
mapped = getFieldMapping(field.move(c.getSuperclass().getName().replace('.', '/'))); } catch (Exception e) {
if (mapped != null) return mapped; e.printStackTrace();
} return null;
}
}
return null; // TODO: Unify with tiny-remapper
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
// TODO: Unify with tiny-remapper @Override
public void read(File input) throws IOException {
BufferedReader reader = Files.newBufferedReader(input.toPath());
@Override TinyUtils.read(reader, from, to, (classFrom, classTo) -> {
public void read(File input) throws IOException { classMap.put(classFrom, classTo);
BufferedReader reader = Files.newBufferedReader(input.toPath()); }, (fieldFrom, fieldTo) -> {
fieldMap.put(
TinyUtils.read(reader, from, to, (classFrom, classTo) -> { new MappingField(fieldFrom.owner, fieldFrom.name, fieldFrom.desc),
classMap.put(classFrom, classTo); new MappingField(fieldTo.owner, fieldTo.name, fieldTo.desc)
}, (fieldFrom, fieldTo) -> { );
fieldMap.put( }, (methodFrom, methodTo) -> {
new MappingField(fieldFrom.owner, fieldFrom.name, fieldFrom.desc), methodMap.put(
new MappingField(fieldTo.owner, fieldTo.name, fieldTo.desc) new MappingMethod(methodFrom.owner, methodFrom.name, methodFrom.desc),
); new MappingMethod(methodTo.owner, methodTo.name, methodTo.desc)
}, (methodFrom, methodTo) -> { );
methodMap.put( });
new MappingMethod(methodFrom.owner, methodFrom.name, methodFrom.desc), }
new MappingMethod(methodTo.owner, methodTo.name, methodTo.desc)
);
});
}
} }

View File

@ -39,37 +39,37 @@ import java.io.PrintWriter;
* Created by asie on 10/9/16. * Created by asie on 10/9/16.
*/ */
public class MixinMappingWriterTiny extends MappingWriter { public class MixinMappingWriterTiny extends MappingWriter {
public MixinMappingWriterTiny(Messager messager, Filer filer) { public MixinMappingWriterTiny(Messager messager, Filer filer) {
super(messager, filer); super(messager, filer);
} }
@Override @Override
public void write(String output, ObfuscationType type, IMappingConsumer.MappingSet<MappingField> fields, IMappingConsumer.MappingSet<MappingMethod> methods) { public void write(String output, ObfuscationType type, IMappingConsumer.MappingSet<MappingField> fields, IMappingConsumer.MappingSet<MappingMethod> methods) {
if (output != null) { if (output != null) {
PrintWriter writer = null; PrintWriter writer = null;
try { try {
String from = type.getKey().split(":")[0]; String from = type.getKey().split(":")[0];
String to = type.getKey().split(":")[1]; String to = type.getKey().split(":")[1];
writer = this.openFileWriter(output, type + " output TinyMappings"); writer = this.openFileWriter(output, type + " output TinyMappings");
writer.println(String.format("v1\t%s\t%s", from, to)); writer.println(String.format("v1\t%s\t%s", from, to));
for (IMappingConsumer.MappingSet.Pair<MappingField> pair : fields) { for (IMappingConsumer.MappingSet.Pair<MappingField> pair : fields) {
writer.println(String.format("FIELD\t%s\t%s\t%s\t%s", pair.from.getOwner(), pair.from.getDesc(), pair.from.getSimpleName(), pair.to.getSimpleName())); writer.println(String.format("FIELD\t%s\t%s\t%s\t%s", pair.from.getOwner(), pair.from.getDesc(), pair.from.getSimpleName(), pair.to.getSimpleName()));
} }
for (IMappingConsumer.MappingSet.Pair<MappingMethod> pair : methods) { for (IMappingConsumer.MappingSet.Pair<MappingMethod> pair : methods) {
writer.println(String.format("METHOD\t%s\t%s\t%s\t%s", pair.from.getOwner(), pair.from.getDesc(), pair.from.getSimpleName(), pair.to.getSimpleName())); writer.println(String.format("METHOD\t%s\t%s\t%s\t%s", pair.from.getOwner(), pair.from.getDesc(), pair.from.getSimpleName(), pair.to.getSimpleName()));
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (writer != null) { if (writer != null) {
try { try {
writer.close(); writer.close();
} catch (Exception e) { } catch (Exception e) {
} }
} }
} }
} }
} }
} }

View File

@ -33,19 +33,19 @@ import javax.annotation.processing.Filer;
import javax.annotation.processing.Messager; import javax.annotation.processing.Messager;
public class ObfuscationEnvironmentFabric extends ObfuscationEnvironment { public class ObfuscationEnvironmentFabric extends ObfuscationEnvironment {
protected ObfuscationEnvironmentFabric(ObfuscationType type) { protected ObfuscationEnvironmentFabric(ObfuscationType type) {
super(type); super(type);
} }
@Override @Override
protected IMappingProvider getMappingProvider(Messager messager, Filer filer) { protected IMappingProvider getMappingProvider(Messager messager, Filer filer) {
String from = type.getKey().split(":")[0]; String from = type.getKey().split(":")[0];
String to = type.getKey().split(":")[1]; String to = type.getKey().split(":")[1];
return new MixinMappingProviderTiny(messager, filer, from, to); return new MixinMappingProviderTiny(messager, filer, from, to);
} }
@Override @Override
protected IMappingWriter getMappingWriter(Messager messager, Filer filer) { protected IMappingWriter getMappingWriter(Messager messager, Filer filer) {
return new MixinMappingWriterTiny(messager, filer); return new MixinMappingWriterTiny(messager, filer);
} }
} }

View File

@ -33,43 +33,43 @@ import java.util.Collection;
import java.util.Set; import java.util.Set;
public class ObfuscationServiceFabric implements IObfuscationService { public class ObfuscationServiceFabric implements IObfuscationService {
public static final String IN_MAP_FILE = "inMapFile"; public static final String IN_MAP_FILE = "inMapFile";
public static final String IN_MAP_EXTRA_FILES = "inMapExtraFiles"; public static final String IN_MAP_EXTRA_FILES = "inMapExtraFiles";
public static final String OUT_MAP_FILE = "outMapFile"; public static final String OUT_MAP_FILE = "outMapFile";
private String asSuffixed(String arg, String from, String to) { private String asSuffixed(String arg, String from, String to) {
return arg + StringUtils.capitalize(from) + StringUtils.capitalize(to); return arg + StringUtils.capitalize(from) + StringUtils.capitalize(to);
} }
private ObfuscationTypeDescriptor createObfuscationType(String from, String to) { private ObfuscationTypeDescriptor createObfuscationType(String from, String to) {
return new ObfuscationTypeDescriptor( return new ObfuscationTypeDescriptor(
from + ":" + to, from + ":" + to,
asSuffixed(ObfuscationServiceFabric.IN_MAP_FILE, from, to), asSuffixed(ObfuscationServiceFabric.IN_MAP_FILE, from, to),
asSuffixed(ObfuscationServiceFabric.IN_MAP_EXTRA_FILES, from, to), asSuffixed(ObfuscationServiceFabric.IN_MAP_EXTRA_FILES, from, to),
asSuffixed(ObfuscationServiceFabric.OUT_MAP_FILE, from, to), asSuffixed(ObfuscationServiceFabric.OUT_MAP_FILE, from, to),
ObfuscationEnvironmentFabric.class ObfuscationEnvironmentFabric.class
); );
} }
private void addSupportedOptions(ImmutableSet.Builder builder, String from, String to) { private void addSupportedOptions(ImmutableSet.Builder builder, String from, String to) {
builder.add(asSuffixed(ObfuscationServiceFabric.IN_MAP_FILE, from, to)); builder.add(asSuffixed(ObfuscationServiceFabric.IN_MAP_FILE, from, to));
builder.add(asSuffixed(ObfuscationServiceFabric.IN_MAP_EXTRA_FILES, from, to)); builder.add(asSuffixed(ObfuscationServiceFabric.IN_MAP_EXTRA_FILES, from, to));
builder.add(asSuffixed(ObfuscationServiceFabric.OUT_MAP_FILE, from, to)); builder.add(asSuffixed(ObfuscationServiceFabric.OUT_MAP_FILE, from, to));
} }
@Override @Override
public Set<String> getSupportedOptions() { public Set<String> getSupportedOptions() {
ImmutableSet.Builder builder = new ImmutableSet.Builder(); ImmutableSet.Builder builder = new ImmutableSet.Builder();
addSupportedOptions(builder, "mojang", "pomf"); addSupportedOptions(builder, "mojang", "pomf");
addSupportedOptions(builder, "pomf", "mojang"); addSupportedOptions(builder, "pomf", "mojang");
return builder.build(); return builder.build();
} }
@Override @Override
public Collection<ObfuscationTypeDescriptor> getObfuscationTypes() { public Collection<ObfuscationTypeDescriptor> getObfuscationTypes() {
return ImmutableSet.of( return ImmutableSet.of(
createObfuscationType("mojang", "pomf"), createObfuscationType("mojang", "pomf"),
createObfuscationType("pomf", "mojang") createObfuscationType("pomf", "mojang")
); );
} }
} }

View File

@ -29,9 +29,7 @@ import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.IdeaRunConfig; import net.fabricmc.loom.util.IdeaRunConfig;
import net.fabricmc.loom.util.Version; import net.fabricmc.loom.util.Version;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.tasks.TaskAction;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;

View File

@ -29,11 +29,7 @@ import cuchaz.enigma.TranslatingTypeLoader;
import cuchaz.enigma.mapping.MappingsEnigmaReader; import cuchaz.enigma.mapping.MappingsEnigmaReader;
import cuchaz.enigma.mapping.TranslationDirection; import cuchaz.enigma.mapping.TranslationDirection;
import cuchaz.enigma.throwables.MappingParseException; import cuchaz.enigma.throwables.MappingParseException;
import javassist.CtBehavior;
import javassist.CtClass; import javassist.CtClass;
import javassist.CtField;
import javassist.bytecode.AccessFlag;
import javassist.bytecode.InnerClassesAttribute;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import org.gradle.api.DefaultTask; import org.gradle.api.DefaultTask;
@ -64,7 +60,7 @@ public class MapJarsTask extends DefaultTask {
writeJar(Constants.MINECRAFT_MAPPED_JAR.get(extension), new ProgressListener(), deobfuscator); writeJar(Constants.MINECRAFT_MAPPED_JAR.get(extension), new ProgressListener(), deobfuscator);
File tempAssests = new File(Constants.CACHE_FILES, "tempAssets"); File tempAssests = new File(Constants.CACHE_FILES, "tempAssets");
if(tempAssests.exists()){ if (tempAssests.exists()) {
FileUtils.deleteDirectory(tempAssests); FileUtils.deleteDirectory(tempAssests);
} }
tempAssests.mkdir(); tempAssests.mkdir();

View File

@ -32,7 +32,6 @@ import org.gradle.api.Project;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -64,7 +63,7 @@ public class ModRemapper {
classpathFiles.addAll(project.getConfigurations().getByName("compile").getFiles()); classpathFiles.addAll(project.getConfigurations().getByName("compile").getFiles());
classpathFiles.addAll(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES_CLIENT).getFiles()); classpathFiles.addAll(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES_CLIENT).getFiles());
classpathFiles.addAll(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getFiles()); classpathFiles.addAll(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getFiles());
classpathFiles.add(new File(Constants.MINECRAFT_MERGED_JAR.get(extension).getAbsolutePath()));//Seems to fix it not finding it classpathFiles.add(new File(Constants.MINECRAFT_FINAL_JAR.get(extension).getAbsolutePath()));//Seems to fix it not finding it
Path[] classpath = new Path[classpathFiles.size()]; Path[] classpath = new Path[classpathFiles.size()];
for (int i = 0; i < classpathFiles.size(); i++) { for (int i = 0; i < classpathFiles.size(); i++) {