|
@@ -0,0 +1,57 @@
|
|
|
+package com.gradle.ares
|
|
|
+
|
|
|
+import org.gradle.api.Project
|
|
|
+import org.gradle.api.logging.Logger
|
|
|
+import org.gradle.api.logging.Logging
|
|
|
+import org.objectweb.asm.ClassVisitor
|
|
|
+import org.objectweb.asm.MethodVisitor
|
|
|
+import org.objectweb.asm.Opcodes
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by Glen on 2017/2/8.
|
|
|
+ */
|
|
|
+
|
|
|
+public class ClassAdapter extends ClassVisitor {
|
|
|
+ private Project project;
|
|
|
+ private Logger logger;
|
|
|
+
|
|
|
+ private boolean modify;
|
|
|
+ private int access;
|
|
|
+ private String superName;
|
|
|
+ private String[] interfaces;
|
|
|
+
|
|
|
+ public ClassAdapter(ClassVisitor cv, Project project) {
|
|
|
+ super(Opcodes.ASM5, cv)
|
|
|
+ this.project = project
|
|
|
+ this.logger = Logging.getLogger(ClassAdapter.class)
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
|
|
+ super.visit(version, access, name, signature, superName, interfaces)
|
|
|
+ this.access = access
|
|
|
+ this.superName = superName
|
|
|
+ this.interfaces = interfaces
|
|
|
+ debug("class:" + name + "_" + superName + "_" + interfaces)
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
|
|
|
+ MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions)
|
|
|
+ def agent = MethodAgentVisitor.getAgent(access, name, desc)
|
|
|
+ if (agent != null) {
|
|
|
+ modify = true
|
|
|
+ debug("method:" + access + "_" + name + "_" + desc)
|
|
|
+ return new MethodAgentVisitor(mv, agent)
|
|
|
+ }
|
|
|
+ return mv
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean getModify() {
|
|
|
+ return modify
|
|
|
+ }
|
|
|
+
|
|
|
+ private void debug(def msg) {
|
|
|
+ this.logger.lifecycle(":" + this.project.name + ":" + msg)
|
|
|
+ }
|
|
|
+}
|