Java 6 support.
This commit is contained in:
parent
ac9cccdf8e
commit
03ae5d07c9
4
pom.xml
4
pom.xml
@ -88,8 +88,8 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.0</version>
|
<version>3.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.7</source>
|
<source>1.6</source>
|
||||||
<target>1.7</target>
|
<target>1.6</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -56,8 +56,8 @@ public class Jar {
|
|||||||
|
|
||||||
public final JarFile file;
|
public final JarFile file;
|
||||||
public final String main;
|
public final String main;
|
||||||
private final Set<String> contains = new HashSet<>();
|
private final Set<String> contains = new HashSet<String>();
|
||||||
private final Map<String, ClassNode> classes = new HashMap<>();
|
private final Map<String, ClassNode> classes = new HashMap<String, ClassNode>();
|
||||||
|
|
||||||
public boolean containsClass(String clazz) {
|
public boolean containsClass(String clazz) {
|
||||||
return contains.contains(clazz) ? true : getClass(clazz) != null;
|
return contains.contains(clazz) ? true : getClass(clazz) != null;
|
||||||
|
@ -40,9 +40,9 @@ public class JarComparer extends ClassVisitor {
|
|||||||
public final Jar jar;
|
public final Jar jar;
|
||||||
private String myName;
|
private String myName;
|
||||||
public int iterDepth;
|
public int iterDepth;
|
||||||
public NoDupeList<String> classes = new NoDupeList<>();
|
public NoDupeList<String> classes = new NoDupeList<String>();
|
||||||
public NoDupeList<Ownable> fields = new NoDupeList<>();
|
public NoDupeList<Ownable> fields = new NoDupeList<Ownable>();
|
||||||
public NoDupeList<Ownable> methods = new NoDupeList<>();
|
public NoDupeList<Ownable> methods = new NoDupeList<Ownable>();
|
||||||
|
|
||||||
private void visitType(Type type) {
|
private void visitType(Type type) {
|
||||||
// FIXME: Scan arrays too!
|
// FIXME: Scan arrays too!
|
||||||
|
@ -57,13 +57,13 @@ public class JarRemapper extends Remapper {
|
|||||||
private static final String HEADER = ""
|
private static final String HEADER = ""
|
||||||
+ "# THESE ARE AUTOMATICALLY GENERATED MAPPINGS BETWEEN {0} and {1}\n"
|
+ "# THESE ARE AUTOMATICALLY GENERATED MAPPINGS BETWEEN {0} and {1}\n"
|
||||||
+ "# THEY WERE GENERATED ON {2} USING Special Source (c) md_5 2012.\n"
|
+ "# THEY WERE GENERATED ON {2} USING Special Source (c) md_5 2012.\n"
|
||||||
+ "# PLEASE DO NOT REMOVE THIS HEADER OR DISTRIBUTE THIS FILE WITHOUT PERMISSION!\n";
|
+ "# PLEASE DO NOT REMOVE THIS HEADER!\n";
|
||||||
private final JarComparer oldJar;
|
private final JarComparer oldJar;
|
||||||
private final JarComparer newJar;
|
private final JarComparer newJar;
|
||||||
private final Jar self;
|
private final Jar self;
|
||||||
private final Map<String, String> classes = new HashMap<>();
|
private final Map<String, String> classes = new HashMap<String, String>();
|
||||||
private final Map<String, String> fields = new HashMap<>();
|
private final Map<String, String> fields = new HashMap<String, String>();
|
||||||
private final Map<String, String> methods = new HashMap<>();
|
private final Map<String, String> methods = new HashMap<String, String>();
|
||||||
|
|
||||||
private JarRemapper(JarComparer oldJar, JarComparer newJar, Jar self, File logfile) throws IOException {
|
private JarRemapper(JarComparer oldJar, JarComparer newJar, Jar self, File logfile) throws IOException {
|
||||||
SpecialSource.validate(oldJar, newJar);
|
SpecialSource.validate(oldJar, newJar);
|
||||||
@ -71,7 +71,7 @@ public class JarRemapper extends Remapper {
|
|||||||
this.newJar = newJar;
|
this.newJar = newJar;
|
||||||
this.self = self;
|
this.self = self;
|
||||||
|
|
||||||
List<String> searge = new ArrayList<>();
|
List<String> searge = new ArrayList<String>();
|
||||||
|
|
||||||
for (int i = 0; i < oldJar.classes.size(); i++) {
|
for (int i = 0; i < oldJar.classes.size(); i++) {
|
||||||
String oldClass = oldJar.classes.get(i);
|
String oldClass = oldJar.classes.get(i);
|
||||||
@ -99,11 +99,15 @@ public class JarRemapper extends Remapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(searge);
|
Collections.sort(searge);
|
||||||
try (PrintWriter out = new PrintWriter(logfile)) {
|
// No try with resources for us!
|
||||||
|
PrintWriter out = new PrintWriter(logfile);
|
||||||
|
try {
|
||||||
out.println(MessageFormat.format(HEADER, oldJar.jar.file.getName(), newJar.jar.file.getName(), new Date()));
|
out.println(MessageFormat.format(HEADER, oldJar.jar.file.getName(), newJar.jar.file.getName(), new Date()));
|
||||||
for (String s : searge) {
|
for (String s : searge) {
|
||||||
out.println(s);
|
out.println(s);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
out.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,11 +152,14 @@ public class JarRemapper extends Remapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void renameJar(Jar jar, File target, JarComparer oldNames, JarComparer newNames) throws IOException {
|
public static void renameJar(Jar jar, File target, JarComparer oldNames, JarComparer newNames) throws IOException {
|
||||||
try (JarOutputStream out = new JarOutputStream(new FileOutputStream(target))) {
|
JarOutputStream out = new JarOutputStream(new FileOutputStream(target));
|
||||||
|
try {
|
||||||
JarRemapper self = new JarRemapper(oldNames, newNames, jar, new File(target.getPath() + ".srg"));
|
JarRemapper self = new JarRemapper(oldNames, newNames, jar, new File(target.getPath() + ".srg"));
|
||||||
for (Enumeration<JarEntry> entr = jar.file.entries(); entr.hasMoreElements();) {
|
for (Enumeration<JarEntry> entr = jar.file.entries(); entr.hasMoreElements();) {
|
||||||
JarEntry entry = entr.nextElement();
|
JarEntry entry = entr.nextElement();
|
||||||
try (InputStream is = jar.file.getInputStream(entry)) {
|
|
||||||
|
InputStream is = jar.file.getInputStream(entry);
|
||||||
|
try {
|
||||||
String name = entry.getName();
|
String name = entry.getName();
|
||||||
byte[] data;
|
byte[] data;
|
||||||
if (name.endsWith(".class")) {
|
if (name.endsWith(".class")) {
|
||||||
@ -170,7 +177,7 @@ public class JarRemapper extends Remapper {
|
|||||||
} else {
|
} else {
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
int n;
|
int n;
|
||||||
byte[] b = new byte[1 << 15]; // Max class file size, arbritrary number
|
byte[] b = new byte[1 << 15]; // Max class file size
|
||||||
while ((n = is.read(b, 0, b.length)) != -1) {
|
while ((n = is.read(b, 0, b.length)) != -1) {
|
||||||
buffer.write(b, 0, n);
|
buffer.write(b, 0, n);
|
||||||
}
|
}
|
||||||
@ -180,8 +187,12 @@ public class JarRemapper extends Remapper {
|
|||||||
entry.setTime(0);
|
entry.setTime(0);
|
||||||
out.putNextEntry(entry);
|
out.putNextEntry(entry);
|
||||||
out.write(data);
|
out.write(data);
|
||||||
|
} finally {
|
||||||
|
is.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
out.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public class NoDupeList<E> implements Iterable<E> {
|
public class NoDupeList<E> implements Iterable<E> {
|
||||||
|
|
||||||
private final Set<E> set = new HashSet<>();
|
private final Set<E> set = new HashSet<E>();
|
||||||
private final List<E> backing = new ArrayList<>();
|
private final List<E> backing = new ArrayList<E>();
|
||||||
|
|
||||||
public boolean add(E e) {
|
public boolean add(E e) {
|
||||||
if (set.contains(e)) {
|
if (set.contains(e)) {
|
||||||
|
@ -35,14 +35,13 @@ import lombok.ToString;
|
|||||||
/**
|
/**
|
||||||
* A class representing a set of 2 objects as defined by the type parameters.
|
* A class representing a set of 2 objects as defined by the type parameters.
|
||||||
*
|
*
|
||||||
* @param <T1> First type
|
* @param <E> type of element
|
||||||
* @param <T2> Second type
|
|
||||||
*/
|
*/
|
||||||
@ToString
|
@ToString
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class Pair<T1, T2> {
|
public class Pair<E> {
|
||||||
|
|
||||||
public final T1 first;
|
public final E first;
|
||||||
public final T2 second;
|
public final E second;
|
||||||
}
|
}
|
||||||
|
@ -30,16 +30,15 @@ package net.md_5.specialsource;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.jar.JarFile;
|
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
|
|
||||||
public class SpecialSource {
|
public class SpecialSource {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
args = new String[]{"jars/1.4.5/bukkit.jar", "jars/1.4.5/vanilla.jar", "jars/1.4.5/craftbukkit-1.4.5-R0.3-SNAPSHOT.jar"};
|
|
||||||
if (args.length != 3) {
|
if (args.length != 3) {
|
||||||
System.err.println("SpecialSource takes 3 arguments. It will take 2 jars to generate a difference between, and a 3rd jar based on the first jar to rename to the second jar.");
|
System.err.println("SpecialSource takes 3 arguments. It will take 2 jars to generate a difference between, and a 3rd jar based on the first jar to rename to the second jar.");
|
||||||
System.err.println("Usage: java -jar SpecialSource.jar <first jar> <second jar> <jar of first names>");
|
System.err.println("Usage: java -jar SpecialSource.jar <first jar> <second jar> <jar of first names>");
|
||||||
|
System.err.println("It is currently tuned to only accept a Minecraft v1.4.5 server jar as the 2 jars to compare");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +49,7 @@ public class SpecialSource {
|
|||||||
System.out.println("Creating jar compare");
|
System.out.println("Creating jar compare");
|
||||||
JarComparer visitor1 = new JarComparer(jar1);
|
JarComparer visitor1 = new JarComparer(jar1);
|
||||||
JarComparer visitor2 = new JarComparer(jar2);
|
JarComparer visitor2 = new JarComparer(jar2);
|
||||||
visit(new Pair<>(jar1, jar2), new Pair<>(visitor1, visitor2), new Pair<>(jar1.main, jar2.main));
|
visit(new Pair<Jar>(jar1, jar2), new Pair<JarComparer>(visitor1, visitor2), new Pair<String>(jar1.main, jar2.main));
|
||||||
|
|
||||||
System.out.println("Checking vailidity");
|
System.out.println("Checking vailidity");
|
||||||
if (visitor1.classes.size() != 1004 || visitor2.classes.size() != 1004) {
|
if (visitor1.classes.size() != 1004 || visitor2.classes.size() != 1004) {
|
||||||
@ -67,7 +66,7 @@ public class SpecialSource {
|
|||||||
JarRemapper.renameJar(Jar.init(args[2]), new File("out.jar"), visitor1, visitor2);
|
JarRemapper.renameJar(Jar.init(args[2]), new File("out.jar"), visitor1, visitor2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void visit(Pair<Jar, Jar> jars, Pair<JarComparer, JarComparer> visitors, Pair<String, String> classes) throws IOException {
|
private static void visit(Pair<Jar> jars, Pair<JarComparer> visitors, Pair<String> classes) throws IOException {
|
||||||
JarComparer visitor1 = visitors.first;
|
JarComparer visitor1 = visitors.first;
|
||||||
JarComparer visitor2 = visitors.second;
|
JarComparer visitor2 = visitors.second;
|
||||||
|
|
||||||
@ -81,7 +80,7 @@ public class SpecialSource {
|
|||||||
while (visitor1.iterDepth < visitor1.classes.size()) {
|
while (visitor1.iterDepth < visitor1.classes.size()) {
|
||||||
String className1 = visitor1.classes.get(visitor1.iterDepth);
|
String className1 = visitor1.classes.get(visitor1.iterDepth);
|
||||||
String className2 = visitor2.classes.get(visitor1.iterDepth);
|
String className2 = visitor2.classes.get(visitor1.iterDepth);
|
||||||
Pair<String, String> pair = new Pair<>(className1, className2);
|
Pair<String> pair = new Pair<String>(className1, className2);
|
||||||
visitor1.iterDepth++;
|
visitor1.iterDepth++;
|
||||||
visit(jars, visitors, pair);
|
visit(jars, visitors, pair);
|
||||||
}
|
}
|
||||||
@ -97,6 +96,5 @@ public class SpecialSource {
|
|||||||
if (visitor1.methods.size() != visitor2.methods.size()) {
|
if (visitor1.methods.size() != visitor2.methods.size()) {
|
||||||
throw new IllegalStateException("methods");
|
throw new IllegalStateException("methods");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user