Move .srg writing into SrgWriter
This commit is contained in:
parent
b20840a65e
commit
a11c2c4698
@ -41,22 +41,18 @@ public class JarMapping {
|
|||||||
public final Map<String, String> fields = new HashMap<String, String>();
|
public final Map<String, String> fields = new HashMap<String, String>();
|
||||||
public final Map<String, String> methods = new HashMap<String, String>();
|
public final Map<String, String> methods = new HashMap<String, String>();
|
||||||
|
|
||||||
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"
|
|
||||||
+ "# PLEASE DO NOT REMOVE THIS HEADER!\n";
|
|
||||||
|
|
||||||
public JarMapping(JarComparer oldJar, JarComparer newJar, File logfile) throws IOException {
|
public JarMapping(JarComparer oldJar, JarComparer newJar, File logfile) throws IOException {
|
||||||
SpecialSource.validate(oldJar, newJar);
|
SpecialSource.validate(oldJar, newJar);
|
||||||
|
|
||||||
List<String> searge = new ArrayList<String>(); // TODO: refactor
|
SrgWriter srgWriter = new SrgWriter();
|
||||||
|
|
||||||
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);
|
||||||
String newClass = newJar.classes.get(i);
|
String newClass = newJar.classes.get(i);
|
||||||
classes.put(oldClass, newClass);
|
classes.put(oldClass, newClass);
|
||||||
if (!Objects.equals(oldClass, newClass)) {
|
if (!Objects.equals(oldClass, newClass)) {
|
||||||
searge.add("CL: " + oldClass + " " + newClass);
|
srgWriter.addClassMap(oldClass, newClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < oldJar.fields.size(); i++) {
|
for (int i = 0; i < oldJar.fields.size(); i++) {
|
||||||
@ -66,7 +62,7 @@ public class JarMapping {
|
|||||||
fields.put(key, newField.name);
|
fields.put(key, newField.name);
|
||||||
|
|
||||||
if (!Objects.equals(oldField.name, newField.name)) {
|
if (!Objects.equals(oldField.name, newField.name)) {
|
||||||
searge.add("FD: " + oldField.owner + "/" + oldField.name + " " + newField.owner + "/" + newField.name);
|
srgWriter.addFieldMap(oldField, newField);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < oldJar.methods.size(); i++) {
|
for (int i = 0; i < oldJar.methods.size(); i++) {
|
||||||
@ -81,27 +77,10 @@ public class JarMapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!Objects.equals(oldMethod.name + " " + oldDescriptor, newMethod.name + " " + newMethod.descriptor)) {
|
if (!Objects.equals(oldMethod.name + " " + oldDescriptor, newMethod.name + " " + newMethod.descriptor)) {
|
||||||
searge.add("MD: " + oldMethod.owner + "/" + oldMethod.name + " " + oldMethod.descriptor + " " + newMethod.owner + "/" + newMethod.name + " " + newMethod.descriptor);
|
srgWriter.addMethodMap(oldMethod, newMethod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintWriter out;
|
srgWriter.write(logfile, oldJar.jar.file.getName(), newJar.jar.file.getName());
|
||||||
|
|
||||||
if (logfile == null) {
|
|
||||||
out = new PrintWriter(System.out);
|
|
||||||
} else {
|
|
||||||
out = new PrintWriter(logfile);
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(searge);
|
|
||||||
// No try with resources for us!
|
|
||||||
try {
|
|
||||||
out.println(MessageFormat.format(HEADER, oldJar.jar.file.getName(), newJar.jar.file.getName(), new Date()));
|
|
||||||
for (String s : searge) {
|
|
||||||
out.println(s);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
55
src/main/java/net/md_5/specialsource/SrgWriter.java
Normal file
55
src/main/java/net/md_5/specialsource/SrgWriter.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package net.md_5.specialsource;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SrgWriter {
|
||||||
|
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"
|
||||||
|
+ "# PLEASE DO NOT REMOVE THIS HEADER!\n";
|
||||||
|
|
||||||
|
private List<String> lines;
|
||||||
|
|
||||||
|
public SrgWriter() {
|
||||||
|
this.lines = new ArrayList<String>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addClassMap(String oldClass, String newClass) {
|
||||||
|
lines.add("CL: " + oldClass + " " + newClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFieldMap(Ownable oldField, Ownable newField) {
|
||||||
|
lines.add("FD: " + oldField.owner + "/" + oldField.name + " " + newField.owner + "/" + newField.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMethodMap(Ownable oldMethod, Ownable newMethod) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(lines);
|
||||||
|
// No try with resources for us!
|
||||||
|
try {
|
||||||
|
out.println(MessageFormat.format(HEADER, oldJarName, newJarName, new Date()));
|
||||||
|
for (String s : lines) {
|
||||||
|
out.println(s);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user