From b839f98de219f5b26fe677e8f8f0247371ce160c Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 23 Jan 2013 19:55:14 +1100 Subject: [PATCH] Formattng + a few nitpicks of previous patches. --- pom.xml | 2 + .../md_5/specialsource/CompactSrgReader.java | 32 +++++++++++-- .../md_5/specialsource/CompactSrgWriter.java | 35 ++++++++++++-- .../specialsource/IInheritanceProvider.java | 30 ++++++++++++ .../net/md_5/specialsource/ISrgWriter.java | 30 +++++++++++- .../specialsource/JarInheritanceProvider.java | 46 +++++++++++++++---- .../net/md_5/specialsource/JarMapping.java | 9 ++-- .../net/md_5/specialsource/JarRemapper.java | 4 +- .../MethodDescriptorTransformer.java | 44 ++++++++++++++---- .../RuntimeInheritanceProvider.java | 39 +++++++++++++--- .../ShadeRelocationSimulator.java | 40 ++++++++++++++-- .../net/md_5/specialsource/SpecialSource.java | 27 ++++------- .../net/md_5/specialsource/SrgWriter.java | 36 +++++++++++++-- 13 files changed, 314 insertions(+), 60 deletions(-) diff --git a/pom.xml b/pom.xml index b9dcb2e..61b9b07 100644 --- a/pom.xml +++ b/pom.xml @@ -53,6 +53,7 @@ org.ow2.asm asm-all 4.1 + compile org.projectlombok @@ -126,6 +127,7 @@ true + true diff --git a/src/main/java/net/md_5/specialsource/CompactSrgReader.java b/src/main/java/net/md_5/specialsource/CompactSrgReader.java index 1241ad4..8a5533e 100644 --- a/src/main/java/net/md_5/specialsource/CompactSrgReader.java +++ b/src/main/java/net/md_5/specialsource/CompactSrgReader.java @@ -1,12 +1,38 @@ +/** + * Copyright (c) 2012, md_5. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package net.md_5.specialsource; -import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; public class CompactSrgReader { - public CompactSrgReader(File file, JarMapping jarMapping) throws IOException { + public CompactSrgReader(File file, JarMapping jarMapping) throws IOException { } } diff --git a/src/main/java/net/md_5/specialsource/CompactSrgWriter.java b/src/main/java/net/md_5/specialsource/CompactSrgWriter.java index 7a52d5a..8dcec36 100644 --- a/src/main/java/net/md_5/specialsource/CompactSrgWriter.java +++ b/src/main/java/net/md_5/specialsource/CompactSrgWriter.java @@ -1,3 +1,31 @@ +/** + * Copyright (c) 2012, md_5. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package net.md_5.specialsource; import java.io.IOException; @@ -7,6 +35,7 @@ import java.util.Collections; import java.util.List; public class CompactSrgWriter implements ISrgWriter { + private PrintWriter out; private List lines; @@ -17,17 +46,17 @@ public class CompactSrgWriter implements ISrgWriter { @Override public void addClassMap(String oldClass, String newClass) { - lines.add(oldClass+" "+newClass); + lines.add(oldClass + " " + newClass); } @Override public void addFieldMap(Ownable oldField, Ownable newField) { - lines.add(oldField.owner+" "+oldField.name+" "+newField.name); + 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); + lines.add(oldMethod.owner + " " + oldMethod.name + " " + oldMethod.descriptor + " " + newMethod.name); } @Override diff --git a/src/main/java/net/md_5/specialsource/IInheritanceProvider.java b/src/main/java/net/md_5/specialsource/IInheritanceProvider.java index 6b11065..f3fcdd3 100644 --- a/src/main/java/net/md_5/specialsource/IInheritanceProvider.java +++ b/src/main/java/net/md_5/specialsource/IInheritanceProvider.java @@ -1,10 +1,40 @@ +/** + * Copyright (c) 2012, md_5. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package net.md_5.specialsource; import java.util.List; public interface IInheritanceProvider { + /** * Get the superclass and implemented interfaces of a class + * * @param className * @return */ diff --git a/src/main/java/net/md_5/specialsource/ISrgWriter.java b/src/main/java/net/md_5/specialsource/ISrgWriter.java index 1f42ba7..4db2836 100644 --- a/src/main/java/net/md_5/specialsource/ISrgWriter.java +++ b/src/main/java/net/md_5/specialsource/ISrgWriter.java @@ -1,9 +1,37 @@ +/** + * Copyright (c) 2012, md_5. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ 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); diff --git a/src/main/java/net/md_5/specialsource/JarInheritanceProvider.java b/src/main/java/net/md_5/specialsource/JarInheritanceProvider.java index d249d28..32ec4d6 100644 --- a/src/main/java/net/md_5/specialsource/JarInheritanceProvider.java +++ b/src/main/java/net/md_5/specialsource/JarInheritanceProvider.java @@ -1,39 +1,67 @@ +/** + * Copyright (c) 2012, md_5. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package net.md_5.specialsource; import org.objectweb.asm.tree.ClassNode; import java.util.ArrayList; import java.util.List; +import lombok.ToString; /** - * Lookup inheritance from a class given a jar + * Lookup inheritance from a class given a jar. */ +@ToString public class JarInheritanceProvider implements IInheritanceProvider { + private final Jar self; public JarInheritanceProvider(Jar self) { this.self = self; } + @Override @SuppressWarnings("unchecked") // Saddens me to see ASM strip vital info like that public List getParents(String owner) { - System.out.println("jar: owner "+owner); + System.out.println("jar: owner " + owner); List parents = new ArrayList(); ClassNode node = self.getNode(owner); if (node != null) { for (String iface : (List) node.interfaces) { - System.out.println("jar: add iface="+iface); + System.out.println("jar: add iface=" + iface); parents.add(iface); } - System.out.println("jar: add super="+node.superName); + System.out.println("jar: add super=" + node.superName); parents.add(node.superName); } else { - System.out.println("jar: nothing for "+owner); + System.out.println("jar: nothing for " + owner); } return parents; } - - public String toString() { - return getClass().getSimpleName()+"("+self.file.getName()+")"; - } } diff --git a/src/main/java/net/md_5/specialsource/JarMapping.java b/src/main/java/net/md_5/specialsource/JarMapping.java index 30dbf43..5e2c7a8 100644 --- a/src/main/java/net/md_5/specialsource/JarMapping.java +++ b/src/main/java/net/md_5/specialsource/JarMapping.java @@ -32,7 +32,7 @@ import java.io.*; import java.util.*; public class JarMapping { - // Mappings from old to new name + public final Map packages = new HashMap(); public final Map classes = new HashMap(); public final Map fields = new HashMap(); @@ -44,8 +44,10 @@ public class JarMapping { /** * Load a mapping given a .csrg file + * * @param file Mapping file - * @param shader Relocation to apply to old class names, or null for no relocation + * @param shader Relocation to apply to old class names, or null for no + * relocation * @throws IOException */ public JarMapping(File file, ShadeRelocationSimulator shader) throws IOException { @@ -56,7 +58,7 @@ public class JarMapping { } String line; - while((line = reader.readLine()) != null) { + while ((line = reader.readLine()) != null) { String[] tokens = line.split(" "); // Read .csrg file @@ -88,6 +90,7 @@ public class JarMapping { /** * Generate a mapping given an original jar and renamed jar + * * @param oldJar Original jar * @param newJar Renamed jar * @param logfile Optional .srg file to output mappings to diff --git a/src/main/java/net/md_5/specialsource/JarRemapper.java b/src/main/java/net/md_5/specialsource/JarRemapper.java index ab48cd4..ecbc38d 100644 --- a/src/main/java/net/md_5/specialsource/JarRemapper.java +++ b/src/main/java/net/md_5/specialsource/JarRemapper.java @@ -43,7 +43,6 @@ import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.commons.Remapper; import org.objectweb.asm.commons.RemappingClassAdapter; -import org.objectweb.asm.tree.ClassNode; public class JarRemapper extends Remapper { @@ -70,7 +69,8 @@ public class JarRemapper extends Remapper { } /** - * Helper method to map a class name by package (prefix) or class (exact) map + * Helper method to map a class name by package (prefix) or class (exact) + * map */ private static String mapClassName(String className, Map packageMap, Map classMap) { if (packageMap != null) { diff --git a/src/main/java/net/md_5/specialsource/MethodDescriptorTransformer.java b/src/main/java/net/md_5/specialsource/MethodDescriptorTransformer.java index 0ea2f43..0b95fa0 100644 --- a/src/main/java/net/md_5/specialsource/MethodDescriptorTransformer.java +++ b/src/main/java/net/md_5/specialsource/MethodDescriptorTransformer.java @@ -1,8 +1,37 @@ +/** + * Copyright (c) 2012, md_5. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package net.md_5.specialsource; import java.util.Map; public class MethodDescriptorTransformer { + private Map packageMap; private Map classMap; @@ -15,11 +44,10 @@ public class MethodDescriptorTransformer { StringBuilder output = new StringBuilder(); int i = 0; - while(i < input.length()) { + while (i < input.length()) { char c = input.charAt(i); - switch(c) - { + switch (c) { // class case 'L': String rest = input.substring(i); @@ -32,7 +60,7 @@ public class MethodDescriptorTransformer { String newClassName = JarRemapper.mapTypeName(className, packageMap, classMap); - output.append("L" + newClassName + ";"); + output.append("L").append(newClassName).append(";"); break; // primitive type @@ -56,17 +84,17 @@ public class MethodDescriptorTransformer { break; case 'T': - throw new IllegalArgumentException("Method descriptors with type variables unsupported: "+c); + throw new IllegalArgumentException("Method descriptors with type variables unsupported: " + c); case '<': - throw new IllegalArgumentException("Method descriptors with optional arguments unsupported: "+c); + throw new IllegalArgumentException("Method descriptors with optional arguments unsupported: " + c); case '*': case '+': case '-': - throw new IllegalArgumentException("Method descriptors with wildcards unsupported: "+c); + throw new IllegalArgumentException("Method descriptors with wildcards unsupported: " + c); case '!': case '|': case 'Q': - throw new IllegalArgumentException("Method descriptors with advanced types unsupported: "+c); + throw new IllegalArgumentException("Method descriptors with advanced types unsupported: " + c); default: throw new IllegalArgumentException("Unrecognized type in method descriptor: " + c); } diff --git a/src/main/java/net/md_5/specialsource/RuntimeInheritanceProvider.java b/src/main/java/net/md_5/specialsource/RuntimeInheritanceProvider.java index 521cad7..6bfa5b8 100644 --- a/src/main/java/net/md_5/specialsource/RuntimeInheritanceProvider.java +++ b/src/main/java/net/md_5/specialsource/RuntimeInheritanceProvider.java @@ -1,14 +1,43 @@ +/** + * Copyright (c) 2012, md_5. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package net.md_5.specialsource; import java.util.List; import java.util.ArrayList; /** - * Lookup class inheritance from classes loaded at runtime + * Lookup class inheritance from classes loaded at runtime. */ public class RuntimeInheritanceProvider implements IInheritanceProvider { - // TODO: option to transform through a jarRemapper at runtime + // TODO: option to transform through a jarRemapper at runtime + @Override public List getParents(String internalClassName) { List parents = new ArrayList(); String sourceClassName = toSourceName(internalClassName); @@ -17,7 +46,7 @@ public class RuntimeInheritanceProvider implements IInheritanceProvider { clazz = ClassLoader.getSystemClassLoader().loadClass(sourceClassName); // load class without initializing //clazz = Class.forName(toSourceName(sourceClassName)); // runs static initializers - avoid! } catch (Throwable t) { - System.out.println("RuntimeInheritanceProvider failed: "+t); + System.out.println("RuntimeInheritanceProvider failed: " + t); return parents; } @@ -42,8 +71,4 @@ public class RuntimeInheritanceProvider implements IInheritanceProvider { public String toInternalName(String className) { return className.replace('.', '/'); } - - public String toString() { - return this.getClass().getSimpleName(); - } } diff --git a/src/main/java/net/md_5/specialsource/ShadeRelocationSimulator.java b/src/main/java/net/md_5/specialsource/ShadeRelocationSimulator.java index 68fbee1..b30536f 100644 --- a/src/main/java/net/md_5/specialsource/ShadeRelocationSimulator.java +++ b/src/main/java/net/md_5/specialsource/ShadeRelocationSimulator.java @@ -1,3 +1,31 @@ +/** + * Copyright (c) 2012, md_5. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package net.md_5.specialsource; import java.util.HashMap; @@ -5,11 +33,12 @@ import java.util.List; import java.util.Map; /** - * Simulate a small subset of the maven-shade-plugin class relocation functionality + * Simulate a small subset of the maven-shade-plugin class relocation + * functionality */ public class ShadeRelocationSimulator { - public Map relocations = new HashMap(); + public Map relocations = new HashMap(); // No relocations public static final ShadeRelocationSimulator IDENTITY = new ShadeRelocationSimulator(); @@ -18,6 +47,7 @@ public class ShadeRelocationSimulator { /** * Load relocations from map of pattern to shadedPattern + * * @param relocations */ public ShadeRelocationSimulator(Map relocations) { @@ -27,14 +57,16 @@ public class ShadeRelocationSimulator { } /** - * Load relocations from list of equals-separated patterns (pattern=shadedPattern) + * Load relocations from list of equals-separated patterns + * (pattern=shadedPattern) + * * @param list */ public ShadeRelocationSimulator(List list) { for (String pair : list) { int index = pair.indexOf("="); if (index == -1) { - throw new IllegalArgumentException("ShadeRelocationSimulator invalid relocation string, missing =: "+pair); + throw new IllegalArgumentException("ShadeRelocationSimulator invalid relocation string, missing =: " + pair); } String pattern = pair.substring(0, index); String shadedPattern = pair.substring(index + 1); diff --git a/src/main/java/net/md_5/specialsource/SpecialSource.java b/src/main/java/net/md_5/specialsource/SpecialSource.java index 0edc33a..f12a449 100644 --- a/src/main/java/net/md_5/specialsource/SpecialSource.java +++ b/src/main/java/net/md_5/specialsource/SpecialSource.java @@ -41,6 +41,7 @@ import org.objectweb.asm.ClassReader; import static java.util.Arrays.asList; public class SpecialSource { + private static OptionSet options; public static void main(String[] args) throws Exception { @@ -100,48 +101,40 @@ public class SpecialSource { } } - /* TODO: move to help - if (args.length != 2 && args.length != 3) { - System.err.println("SpecialSource takes 2 or 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 []"); - System.err.println("It is currently tuned to only accept a Minecraft v1.4.5 server jar as the 2 jars to compare"); - return; - }*/ - JarMapping jarMapping; if (options.has("first-jar") && options.has("second-jar")) { // Generate mappings from two otherwise-identical jars log("Reading jars"); - Jar jar1 = Jar.init((File)options.valueOf("first-jar")); - Jar jar2 = Jar.init((File)options.valueOf("second-jar")); + Jar jar1 = Jar.init((File) options.valueOf("first-jar")); + Jar jar2 = Jar.init((File) options.valueOf("second-jar")); log("Creating jar compare"); JarComparer visitor1 = new JarComparer(jar1); JarComparer visitor2 = new JarComparer(jar2); visit(new Pair(jar1, jar2), new Pair(visitor1, visitor2), new Pair(jar1.main, jar2.main)); - jarMapping = new JarMapping(visitor1, visitor2, (File)options.valueOf("srg-out"), options.has("compact")); + jarMapping = new JarMapping(visitor1, visitor2, (File) options.valueOf("srg-out"), options.has("compact")); } else if (options.has("srg-in")) { // Load mappings, possibly shaded ShadeRelocationSimulator shadeRelocationSimulator = null; if (options.has("shade-relocation")) { - List relocations = (List)options.valuesOf("shade-relocation"); + List relocations = (List) options.valuesOf("shade-relocation"); shadeRelocationSimulator = new ShadeRelocationSimulator(relocations); for (Map.Entry entry : shadeRelocationSimulator.relocations.entrySet()) { - log("Relocation: " + entry.getKey() + " -> " +entry.getValue()); + log("Relocation: " + entry.getKey() + " -> " + entry.getValue()); } } log("Loading mappings"); - jarMapping = new JarMapping((File)options.valueOf("srg-in"), shadeRelocationSimulator); + jarMapping = new JarMapping((File) options.valueOf("srg-in"), shadeRelocationSimulator); } else { System.err.println("No mappings given, first-jar/second-jar or srg-in required"); parser.printHelpOn(System.err); return; } - log(jarMapping.classes.size()+" classes, "+jarMapping.fields.size()+" fields, "+jarMapping.methods.size()+" methods"); + log(jarMapping.classes.size() + " classes, " + jarMapping.fields.size() + " fields, " + jarMapping.methods.size() + " methods"); if (options.has("in-jar")) { if (!options.has("out-jar")) { @@ -151,8 +144,8 @@ public class SpecialSource { } log("Remapping final jar"); - Jar jar3 = Jar.init((File)options.valueOf("in-jar")); - JarRemapper.renameJar(jar3, (File)options.valueOf("out-jar"), jarMapping, options.has("live")); + Jar jar3 = Jar.init((File) options.valueOf("in-jar")); + JarRemapper.renameJar(jar3, (File) options.valueOf("out-jar"), jarMapping, options.has("live")); } } diff --git a/src/main/java/net/md_5/specialsource/SrgWriter.java b/src/main/java/net/md_5/specialsource/SrgWriter.java index c4102d5..9d7316d 100644 --- a/src/main/java/net/md_5/specialsource/SrgWriter.java +++ b/src/main/java/net/md_5/specialsource/SrgWriter.java @@ -1,6 +1,33 @@ +/** + * Copyright (c) 2012, md_5. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ package net.md_5.specialsource; -import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.text.MessageFormat; @@ -10,13 +37,12 @@ import java.util.Date; import java.util.List; 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" + "# PLEASE DO NOT REMOVE THIS HEADER!\n"; - private List lines; - private PrintWriter out; private String oldJarName; private String newJarName; @@ -29,18 +55,22 @@ public class SrgWriter implements ISrgWriter { this.newJarName = newJarName; } + @Override public void addClassMap(String oldClass, String newClass) { lines.add("CL: " + oldClass + " " + newClass); } + @Override public void addFieldMap(Ownable oldField, Ownable newField) { lines.add("FD: " + oldField.owner + "/" + oldField.name + " " + newField.owner + "/" + newField.name); } + @Override public void addMethodMap(Ownable oldMethod, Ownable newMethod) { lines.add("MD: " + oldMethod.owner + "/" + oldMethod.name + " " + oldMethod.descriptor + " " + newMethod.owner + "/" + newMethod.name + " " + newMethod.descriptor); } + @Override public void write() throws IOException { Collections.sort(lines); // No try with resources for us!