Formattng + a few nitpicks of previous patches.
This commit is contained in:
parent
297b9f5a33
commit
b839f98de2
2
pom.xml
2
pom.xml
@ -53,6 +53,7 @@
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm-all</artifactId>
|
||||
<version>4.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
@ -126,6 +127,7 @@
|
||||
</executions>
|
||||
<configuration>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
@ -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 {
|
||||
}
|
||||
}
|
||||
|
@ -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<String> 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
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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);
|
||||
|
@ -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<String> getParents(String owner) {
|
||||
System.out.println("jar: owner "+owner);
|
||||
System.out.println("jar: owner " + owner);
|
||||
List<String> parents = new ArrayList<String>();
|
||||
ClassNode node = self.getNode(owner);
|
||||
if (node != null) {
|
||||
for (String iface : (List<String>) 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()+")";
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class JarMapping {
|
||||
// Mappings from old to new name
|
||||
|
||||
public final Map<String, String> packages = new HashMap<String, String>();
|
||||
public final Map<String, String> classes = new HashMap<String, String>();
|
||||
public final Map<String, String> fields = new HashMap<String, String>();
|
||||
@ -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
|
||||
|
@ -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<String, String> packageMap, Map<String, String> classMap) {
|
||||
if (packageMap != null) {
|
||||
|
@ -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<String, String> packageMap;
|
||||
private Map<String, String> 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);
|
||||
}
|
||||
|
@ -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<String> getParents(String internalClassName) {
|
||||
List<String> parents = new ArrayList<String>();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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<String, String> relocations = new HashMap<String, String>();
|
||||
|
||||
public Map<String, String> relocations = new HashMap<String, String>();
|
||||
// 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<String, String> 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<String> 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);
|
||||
|
@ -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 <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;
|
||||
}*/
|
||||
|
||||
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<Jar>(jar1, jar2), new Pair<JarComparer>(visitor1, visitor2), new Pair<String>(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<String> relocations = (List<String>)options.valuesOf("shade-relocation");
|
||||
List<String> relocations = (List<String>) options.valuesOf("shade-relocation");
|
||||
shadeRelocationSimulator = new ShadeRelocationSimulator(relocations);
|
||||
|
||||
for (Map.Entry<String, String> 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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<String> 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!
|
||||
|
Loading…
Reference in New Issue
Block a user