Turn RemapperPreprocessor into RemapperProcessor and provide support for calling one before remap and one after remap.

This commit is contained in:
md_5 2013-11-30 09:29:43 +11:00
parent 4615bf5727
commit 1ce1d91291
2 changed files with 21 additions and 21 deletions

View File

@ -38,30 +38,29 @@ import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import net.md_5.specialsource.repo.ClassRepo;
import net.md_5.specialsource.repo.JarRepo;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import net.md_5.specialsource.CustomRemapper;
import org.objectweb.asm.tree.ClassNode;
import static org.objectweb.asm.ClassWriter.*;
public class JarRemapper extends CustomRemapper {
private static final int CLASS_LEN = ".class".length();
private RemapperProcessor preProcessor;
public final JarMapping jarMapping;
public RemapperPreprocessor remapperPreprocessor;
private RemapperProcessor postProcessor;
private int writerFlags = COMPUTE_MAXS;
private int readerFlags = 0;
private boolean copyResources = true;
public JarRemapper(RemapperPreprocessor remapperPreprocessor, JarMapping jarMapping) {
this.remapperPreprocessor = remapperPreprocessor;
public JarRemapper(RemapperProcessor preProcessor, JarMapping jarMapping, RemapperProcessor postProcessor) {
this.preProcessor = preProcessor;
this.jarMapping = jarMapping;
this.postProcessor = postProcessor;
}
public JarRemapper(RemapperProcessor remapperPreprocessor, JarMapping jarMapping) {
this(remapperPreprocessor, jarMapping, null);
}
public JarRemapper(JarMapping jarMapping) {
@ -235,8 +234,8 @@ public class JarRemapper extends CustomRemapper {
@SuppressWarnings("unchecked")
private byte[] remapClassFile(ClassReader reader, final ClassRepo repo) {
if (remapperPreprocessor != null) {
byte[] pre = remapperPreprocessor.preprocess(reader);
if (preProcessor != null) {
byte[] pre = preProcessor.process(reader);
if (pre != null) {
reader = new ClassReader(pre);
}
@ -251,6 +250,7 @@ public class JarRemapper extends CustomRemapper {
if (SpecialSource.identifier != null) {
wr.newUTF8(SpecialSource.identifier);
}
return wr.toByteArray();
return (postProcessor != null) ? postProcessor.process(wr.toByteArray()) : wr.toByteArray();
}
}

View File

@ -49,7 +49,7 @@ import java.util.List;
* - Remapping reflected field string constants
* - Remapping reflected class name string constants
*/
public class RemapperPreprocessor {
public class RemapperProcessor {
public boolean debug = false;
private InheritanceMap inheritanceMap;
@ -67,7 +67,7 @@ public class RemapperPreprocessor {
* @param accessMap Access transformer mappings, or null to not apply AT
* @throws IOException
*/
public RemapperPreprocessor(InheritanceMap inheritanceMap, JarMapping jarMapping, AccessMap accessMap) {
public RemapperProcessor(InheritanceMap inheritanceMap, JarMapping jarMapping, AccessMap accessMap) {
this.inheritanceMap = inheritanceMap;
this.jarMapping = jarMapping;
this.accessMap = accessMap;
@ -75,16 +75,16 @@ public class RemapperPreprocessor {
this.remapReflectClass = false;
}
public RemapperPreprocessor(InheritanceMap inheritanceMap, JarMapping jarMapping) {
public RemapperProcessor(InheritanceMap inheritanceMap, JarMapping jarMapping) {
this(inheritanceMap, jarMapping, null);
}
public byte[] preprocess(InputStream inputStream) throws IOException {
return preprocess(new ClassReader(inputStream));
public byte[] process(InputStream inputStream) throws IOException {
return process(new ClassReader(inputStream));
}
public byte[] preprocess(byte[] bytecode) throws IOException {
return preprocess(new ClassReader(bytecode));
public byte[] process(byte[] bytecode) {
return process(new ClassReader(bytecode));
}
/**
@ -104,7 +104,7 @@ public class RemapperPreprocessor {
}
@SuppressWarnings("unchecked")
public byte[] preprocess(ClassReader classReader) {
public byte[] process(ClassReader classReader) {
byte[] bytecode = null;
ClassNode classNode = new ClassNode();
int flags = 0;