diff --git a/src/main/java/net/md_5/specialsource/CompactSrgWriter.java b/src/main/java/net/md_5/specialsource/CompactSrgWriter.java new file mode 100644 index 0000000..7a52d5a --- /dev/null +++ b/src/main/java/net/md_5/specialsource/CompactSrgWriter.java @@ -0,0 +1,42 @@ +package net.md_5.specialsource; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class CompactSrgWriter implements ISrgWriter { + private PrintWriter out; + private List lines; + + public CompactSrgWriter(PrintWriter out) { + this.out = out; + this.lines = new ArrayList(); + } + + @Override + public void addClassMap(String oldClass, String newClass) { + lines.add(oldClass+" "+newClass); + } + + @Override + public void addFieldMap(Ownable oldField, Ownable newField) { + lines.add(oldField.owner+" "+oldField.name+" "+newField.name); + } + + @Override + public void addMethodMap(Ownable oldMethod, Ownable newMethod) { + lines.add(oldMethod.owner+" "+oldMethod.name+" "+oldMethod.descriptor+" "+newMethod.name); + } + + @Override + public void write() throws IOException { + Collections.sort(lines); + + for (String s : lines) { + out.println(s); + } + out.close(); + } +} diff --git a/src/main/java/net/md_5/specialsource/ISrgWriter.java b/src/main/java/net/md_5/specialsource/ISrgWriter.java new file mode 100644 index 0000000..1f42ba7 --- /dev/null +++ b/src/main/java/net/md_5/specialsource/ISrgWriter.java @@ -0,0 +1,14 @@ +package net.md_5.specialsource; + +import java.io.File; +import java.io.IOException; + +public interface ISrgWriter { + void addClassMap(String oldClass, String newClass); + + void addFieldMap(Ownable oldField, Ownable newField); + + void addMethodMap(Ownable oldMethod, Ownable newMethod); + + void write() throws IOException; +} diff --git a/src/main/java/net/md_5/specialsource/JarMapping.java b/src/main/java/net/md_5/specialsource/JarMapping.java index f05b008..d439678 100644 --- a/src/main/java/net/md_5/specialsource/JarMapping.java +++ b/src/main/java/net/md_5/specialsource/JarMapping.java @@ -42,10 +42,22 @@ public class JarMapping { public final Map methods = new HashMap(); - public JarMapping(JarComparer oldJar, JarComparer newJar, File logfile) throws IOException { + public JarMapping(JarComparer oldJar, JarComparer newJar, File logfile, boolean compact) throws IOException { SpecialSource.validate(oldJar, newJar); - SrgWriter srgWriter = new SrgWriter(); + PrintWriter out; + if (logfile == null) { + out = new PrintWriter(System.out); + } else { + out = new PrintWriter(logfile); + } + + ISrgWriter srgWriter; + if (compact) { + srgWriter = new CompactSrgWriter(out); + } else { + srgWriter = new SrgWriter(out, oldJar.jar.file.getName(), newJar.jar.file.getName()); + } for (int i = 0; i < oldJar.classes.size(); i++) { String oldClass = oldJar.classes.get(i); @@ -81,6 +93,6 @@ public class JarMapping { } } - srgWriter.write(logfile, oldJar.jar.file.getName(), newJar.jar.file.getName()); + srgWriter.write(); } } diff --git a/src/main/java/net/md_5/specialsource/SpecialSource.java b/src/main/java/net/md_5/specialsource/SpecialSource.java index 3133169..7ce14e7 100644 --- a/src/main/java/net/md_5/specialsource/SpecialSource.java +++ b/src/main/java/net/md_5/specialsource/SpecialSource.java @@ -54,7 +54,7 @@ public class SpecialSource { .withRequiredArg() .ofType(File.class); - acceptsAll(asList("s", "srg-out"), "Mapping srg output") + acceptsAll(asList("s", "srg-out"), "Mapping file output") .withRequiredArg() .ofType(File.class); @@ -67,6 +67,7 @@ public class SpecialSource { .ofType(File.class); acceptsAll(asList("q", "quiet"), "Quiet mode"); + acceptsAll(asList("c", "compact"), "Output mapping file in compact format"); } }; @@ -104,7 +105,7 @@ public class SpecialSource { JarComparer visitor2 = new JarComparer(jar2); visit(new Pair(jar1, jar2), new Pair(visitor1, visitor2), new Pair(jar1.main, jar2.main)); - JarMapping jarMapping = new JarMapping(visitor1, visitor2, (File)options.valueOf("srg-out")); + JarMapping jarMapping = new JarMapping(visitor1, visitor2, (File)options.valueOf("srg-out"), options.has("c")); if (options.has("in-jar")) { log("Remapping final jar"); diff --git a/src/main/java/net/md_5/specialsource/SrgWriter.java b/src/main/java/net/md_5/specialsource/SrgWriter.java index 487cc0d..c4102d5 100644 --- a/src/main/java/net/md_5/specialsource/SrgWriter.java +++ b/src/main/java/net/md_5/specialsource/SrgWriter.java @@ -9,7 +9,7 @@ import java.util.Collections; import java.util.Date; import java.util.List; -public class SrgWriter { +public class SrgWriter implements ISrgWriter { private static final String HEADER = "" + "# THESE ARE AUTOMATICALLY GENERATED MAPPINGS BETWEEN {0} and {1}\n" + "# THEY WERE GENERATED ON {2} USING Special Source (c) md_5 2012.\n" @@ -17,8 +17,16 @@ public class SrgWriter { private List lines; - public SrgWriter() { + private PrintWriter out; + private String oldJarName; + private String newJarName; + + public SrgWriter(PrintWriter out, String oldJarName, String newJarName) { this.lines = new ArrayList(); + + this.out = out; + this.oldJarName = oldJarName; + this.newJarName = newJarName; } public void addClassMap(String oldClass, String newClass) { @@ -33,14 +41,7 @@ public class SrgWriter { lines.add("MD: " + oldMethod.owner + "/" + oldMethod.name + " " + oldMethod.descriptor + " " + newMethod.owner + "/" + newMethod.name + " " + newMethod.descriptor); } - public void write(File logfile, String oldJarName, String newJarName) throws IOException { - PrintWriter out; - if (logfile == null) { - out = new PrintWriter(System.out); - } else { - out = new PrintWriter(logfile); - } - + public void write() throws IOException { Collections.sort(lines); // No try with resources for us! try {