checkstyle - mixin processor

This commit is contained in:
Lucas
2019-05-17 03:04:15 +02:00
parent 0d8dbfee38
commit 7740b7a85e
18 changed files with 51 additions and 78 deletions

View File

@@ -33,10 +33,6 @@ import io.sigpipe.jbsdiff.Patch;
import javassist.ClassPool; import javassist.ClassPool;
import javassist.CtClass; import javassist.CtClass;
import javassist.LoaderClassPath; import javassist.LoaderClassPath;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import us.runelitepl.mixinprocessor.generators.AnnotationProcessor; import us.runelitepl.mixinprocessor.generators.AnnotationProcessor;
import us.runelitepl.mixinprocessor.generators.PatchGenerator; import us.runelitepl.mixinprocessor.generators.PatchGenerator;
@@ -50,14 +46,11 @@ import us.runelitepl.mixinprocessor.util.JavassistUtils;
import us.runelitepl.mixinprocessor.util.RefUtils; import us.runelitepl.mixinprocessor.util.RefUtils;
import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
@@ -111,9 +104,9 @@ public class MixinProcessorMojo
public static HashMap<String, MethodGarbageValue> methodGarbageValues = new HashMap<>(); public static HashMap<String, MethodGarbageValue> methodGarbageValues = new HashMap<>();
public static HashMap<String, byte[]> gamepack = new HashMap<>(); private static HashMap<String, byte[]> gamepack = new HashMap<>();
public static final int BUFFER_SIZE = 1024 * 1024 * 4; private static final int BUFFER_SIZE = 1024 * 1024 * 4;
public void execute() public void execute()
throws MojoExecutionException throws MojoExecutionException
@@ -257,7 +250,7 @@ public class MixinProcessorMojo
} }
public void stderr(String s, Object... format) private void stderr(String s, Object... format)
{ {
getLog().info(String.format(s, format)); getLog().info(String.format(s, format));
} }
@@ -267,7 +260,7 @@ public class MixinProcessorMojo
INST.stderr(s, format); INST.stderr(s, format);
} }
static void deleteDir(File file) throws IOException private static void deleteDir(File file) throws IOException
{ {
if (!file.exists()) if (!file.exists())
{ {

View File

@@ -31,5 +31,5 @@ public enum InjectionType
APPEND, APPEND,
OVERWRITE, OVERWRITE,
PREPEND, PREPEND,
PROVIDED; PROVIDED
} }

View File

@@ -26,8 +26,6 @@
package us.runelitepl.mixinprocessor.generators; package us.runelitepl.mixinprocessor.generators;
import us.runelitepl.mixinprocessor.transformers.AnnotationRemoverTransformer; import us.runelitepl.mixinprocessor.transformers.AnnotationRemoverTransformer;
import us.runelitepl.mixinprocessor.transformers.AsmMethodGarbageTransformer;
import us.runelitepl.mixinprocessor.transformers.AsmMethodSignatureTransformer;
import us.runelitepl.mixinprocessor.transformers.AsmNameTransformer; import us.runelitepl.mixinprocessor.transformers.AsmNameTransformer;
import us.runelitepl.mixinprocessor.transformers.AsmStaticUsageTransformer; import us.runelitepl.mixinprocessor.transformers.AsmStaticUsageTransformer;
import us.runelitepl.mixinprocessor.transformers.DoNothingTransformer; import us.runelitepl.mixinprocessor.transformers.DoNothingTransformer;

View File

@@ -25,18 +25,12 @@
package us.runelitepl.mixinprocessor.generators; package us.runelitepl.mixinprocessor.generators;
import javassist.CannotCompileException;
import javassist.CtClass;
import javassist.NotFoundException;
import us.runelitepl.mixinprocessor.MixinProcessorMojo; import us.runelitepl.mixinprocessor.MixinProcessorMojo;
import us.runelitepl.mixinprocessor.util.JavassistUtils;
import us.runelitepl.mixinprocessor.util.RefUtils; import us.runelitepl.mixinprocessor.util.RefUtils;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode; import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.MethodNode;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@@ -45,11 +39,11 @@ import java.util.Set;
public class StaticGenerator public class StaticGenerator
{ {
public static HashMap<String, ArrayList<MethodNode>> staticMethods = new HashMap<>(); static HashMap<String, ArrayList<MethodNode>> staticMethods = new HashMap<>();
public static HashMap<String, ArrayList<FieldNode>> staticFields = new HashMap<>(); static HashMap<String, ArrayList<FieldNode>> staticFields = new HashMap<>();
public static Set<String> modifiedClasses = new HashSet<>(); static Set<String> modifiedClasses = new HashSet<>();
public void run(byte[] bytecode) throws NotFoundException, IOException, CannotCompileException public void run(byte[] bytecode)
{ {
ClassReader cr = new ClassReader(bytecode); ClassReader cr = new ClassReader(bytecode);

View File

@@ -36,7 +36,6 @@ import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.FieldNode; import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TypeAnnotationNode; import org.objectweb.asm.tree.TypeAnnotationNode;
import us.runelitepl.mixinprocessor.MixinProcessorMojo;
import us.runelitepl.mixinprocessor.parsers.MethodReflector; import us.runelitepl.mixinprocessor.parsers.MethodReflector;
import java.util.HashMap; import java.util.HashMap;

View File

@@ -56,7 +56,7 @@ public class GamepackDownloader
continue; continue;
} }
String key = entry.getName().replace(".class", ""); String key = entry.getName().replace(".class", "");
int len = 0; int len;
while ((len = zipInputStream.read(buffer)) > 0) while ((len = zipInputStream.read(buffer)) > 0)
{ {
fileContent.write(buffer, 0, len); fileContent.write(buffer, 0, len);
@@ -83,7 +83,7 @@ public class GamepackDownloader
} }
} }
public static String getGamepackUrl() private static String getGamepackUrl()
{ {
return codebase + initial_jar; return codebase + initial_jar;
} }

View File

@@ -96,7 +96,7 @@ public class AnnotationRemoverTransformer extends AsmBaseTransformer
return cw.toByteArray(); return cw.toByteArray();
} }
public static String makeAnnotationDescriptor(String s) static String makeAnnotationDescriptor(String s)
{ {
return "Lus/runelitepl/mixinprocessor/annotations/" + s + ";"; return "Lus/runelitepl/mixinprocessor/annotations/" + s + ";";
} }

View File

@@ -35,9 +35,10 @@ public abstract class AsmBaseTransformer implements Opcodes
protected final ArrayList<String> validMethods = new ArrayList<>(); protected final ArrayList<String> validMethods = new ArrayList<>();
protected final ArrayList<String> validFields = new ArrayList<>(); protected final ArrayList<String> validFields = new ArrayList<>();
// CHECKSTYLE:OFF
protected void buildMethodList(){} protected void buildMethodList(){}
protected void buildFieldList(){} protected void buildFieldList(){}
// CHECKSTYLE:ON
public abstract byte[] transform(); public abstract byte[] transform();

View File

@@ -32,8 +32,6 @@ import org.objectweb.asm.MethodVisitor;
import us.runelitepl.mixinprocessor.MethodGarbageValue; import us.runelitepl.mixinprocessor.MethodGarbageValue;
import us.runelitepl.mixinprocessor.MixinProcessorMojo; import us.runelitepl.mixinprocessor.MixinProcessorMojo;
import us.runelitepl.mixinprocessor.util.RefUtils; import us.runelitepl.mixinprocessor.util.RefUtils;
import java.sql.Ref;
import java.util.HashMap; import java.util.HashMap;
public class AsmMethodGarbageTransformer extends AsmBaseTransformer public class AsmMethodGarbageTransformer extends AsmBaseTransformer

View File

@@ -32,11 +32,6 @@ import org.objectweb.asm.MethodVisitor;
import us.runelitepl.mixinprocessor.MixinProcessorMojo; import us.runelitepl.mixinprocessor.MixinProcessorMojo;
import us.runelitepl.mixinprocessor.util.RefUtils; import us.runelitepl.mixinprocessor.util.RefUtils;
import static org.objectweb.asm.Opcodes.ASM6;
import static org.objectweb.asm.Opcodes.GETSTATIC;
import static org.objectweb.asm.Opcodes.INVOKESTATIC;
import static org.objectweb.asm.Opcodes.PUTSTATIC;
public class AsmStaticUsageTransformer extends AsmBaseTransformer public class AsmStaticUsageTransformer extends AsmBaseTransformer
{ {

View File

@@ -47,10 +47,10 @@ public class DoNothingTransformer extends AsmBaseTransformer
ClassReader cr = new ClassReader(bytecode); ClassReader cr = new ClassReader(bytecode);
ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES); ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES);
// CHECKSTYLE:OFF
cr.accept(new ClassVisitor(ASM6, cw) cr.accept(new ClassVisitor(ASM6, cw)
{}, 0); {}, 0);
//CHECKSTYLE:ON
return cw.toByteArray(); return cw.toByteArray();
} }
} }

View File

@@ -169,11 +169,7 @@ public class RefUtils
i++; i++;
} }
} }
if (i == 1) return i == 1;
{
return true;
}
return false;
} }
@Deprecated @Deprecated
@@ -187,11 +183,7 @@ public class RefUtils
i++; i++;
} }
} }
if (i == 1) return i == 1;
{
return true;
}
return false;
} }
public static boolean shouldReobField(String owner, String deob, String desc) public static boolean shouldReobField(String owner, String deob, String desc)
@@ -275,7 +267,7 @@ public class RefUtils
{ {
obbedName = className; obbedName = className;
} }
deobbed.append("L" + obbedName + ";"); deobbed.append("L").append(obbedName ).append(";");
strIndex += sigPart.length(); strIndex += sigPart.length();
} }
catch (StringIndexOutOfBoundsException ex) catch (StringIndexOutOfBoundsException ex)

View File

@@ -50,14 +50,17 @@ public class WebUtils
return pageText; return pageText;
} }
public static byte[] downloadFile(String urlText) throws IOException { public static byte[] downloadFile(String urlText) throws IOException
{
URL url = new URL(urlText); URL url = new URL(urlText);
ByteArrayOutputStream output = new ByteArrayOutputStream(); ByteArrayOutputStream output = new ByteArrayOutputStream();
try (InputStream inputStream = url.openStream()) { try (InputStream inputStream = url.openStream())
int n = 0; {
int n;
byte [] buffer = new byte[ 1024 ]; byte [] buffer = new byte[ 1024 ];
while (-1 != (n = inputStream.read(buffer))) { while (-1 != (n = inputStream.read(buffer)))
{
output.write(buffer, 0, n); output.write(buffer, 0, n);
} }
} }