|
@@ -1,6 +1,5 @@
|
|
|
package com.gradle.ares
|
|
|
|
|
|
-import org.gradle.api.logging.Logging
|
|
|
import org.objectweb.asm.ClassVisitor
|
|
|
import org.objectweb.asm.FieldVisitor
|
|
|
import org.objectweb.asm.Label
|
|
@@ -55,28 +54,28 @@ public class MethodLifeCycleVisitor extends MethodVisitor {
|
|
|
|
|
|
public final
|
|
|
static void addMethods(Set<Agent> agentSet, String name, String superName, ClassVisitor cv) {
|
|
|
- addLifeCycleFieldMethod(cv)
|
|
|
+ addLifeCycleFieldMethod(name, cv)
|
|
|
for (Agent agent : Modify) {
|
|
|
if (!agentSet.contains(agent)) {
|
|
|
-// //method
|
|
|
-// int count = 0;
|
|
|
-// for (def item : agent.desc.substring(1, agent.desc.indexOf(")")).split(";")) {
|
|
|
-// if (!item.equals("")) count++
|
|
|
-// }
|
|
|
-//
|
|
|
-// MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, agent.name, agent.desc, null, null)
|
|
|
-// mv.visitCode()
|
|
|
-// mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
|
-// mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, name, GetLifeMethod, "()L" + LifeClass + ";", false)
|
|
|
-// for (int i = 1; i <= count; i++) mv.visitVarInsn(Opcodes.ALOAD, i)
|
|
|
-// mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, LifeClass, agent.name, agent.desc, false)
|
|
|
-//
|
|
|
-// mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
|
-// for (int i = 1; i <= count; i++) mv.visitVarInsn(Opcodes.ALOAD, i)
|
|
|
-// mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, agent.name, agent.desc, false)
|
|
|
-// mv.visitInsn(Opcodes.RETURN)
|
|
|
-// mv.visitMaxs(0, 0)
|
|
|
-// mv.visitEnd()
|
|
|
+ //method
|
|
|
+ int count = 0;
|
|
|
+ for (def item : agent.desc.substring(1, agent.desc.indexOf(")")).split(";")) {
|
|
|
+ if (!item.equals("")) count++
|
|
|
+ }
|
|
|
+
|
|
|
+ MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, agent.name, agent.desc, null, null)
|
|
|
+ mv.visitCode()
|
|
|
+ mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
|
+ mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, name, GetLifeMethod, "()L" + LifeClass + ";", false)
|
|
|
+ for (int i = 1; i <= count; i++) mv.visitVarInsn(Opcodes.ALOAD, i)
|
|
|
+ mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, LifeClass, agent.name, agent.desc, false)
|
|
|
+
|
|
|
+ mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
|
+ for (int i = 1; i <= count; i++) mv.visitVarInsn(Opcodes.ALOAD, i)
|
|
|
+ mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, agent.name, agent.desc, false)
|
|
|
+ mv.visitInsn(Opcodes.RETURN)
|
|
|
+ mv.visitMaxs(0, 0)
|
|
|
+ mv.visitEnd()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -85,7 +84,7 @@ public class MethodLifeCycleVisitor extends MethodVisitor {
|
|
|
* 注入代理字段及初始化方法
|
|
|
* @param cv
|
|
|
*/
|
|
|
- private final static void addLifeCycleFieldMethod(ClassVisitor cv) {
|
|
|
+ private final static void addLifeCycleFieldMethod(String name, ClassVisitor cv) {
|
|
|
//desc
|
|
|
String fieldName = "\$lifeCycleAresDelegate"
|
|
|
String fieldDesc = "L" + LifeClass + ";"
|
|
@@ -96,23 +95,23 @@ public class MethodLifeCycleVisitor extends MethodVisitor {
|
|
|
MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, GetLifeMethod, "()" + fieldDesc, null, null)
|
|
|
mv.visitCode()
|
|
|
mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
|
- mv.visitFieldInsn(Opcodes.GETFIELD, LifeClass, fieldName, fieldDesc)
|
|
|
+ mv.visitFieldInsn(Opcodes.GETFIELD, name, fieldName, fieldDesc)
|
|
|
Label label = new Label()
|
|
|
mv.visitJumpInsn(Opcodes.IFNONNULL, label)
|
|
|
mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
|
mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
|
mv.visitMethodInsn(Opcodes.INVOKESTATIC, LifeClass, "create", "(Ljava/lang/Object;)" + fieldDesc, false)
|
|
|
- mv.visitFieldInsn(Opcodes.PUTFIELD, LifeClass, fieldName, fieldDesc)
|
|
|
+ mv.visitFieldInsn(Opcodes.PUTFIELD, name, fieldName, fieldDesc)
|
|
|
mv.visitLabel(label)
|
|
|
mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
|
- mv.visitFieldInsn(Opcodes.GETFIELD, LifeClass, fieldName, fieldDesc)
|
|
|
+ mv.visitFieldInsn(Opcodes.GETFIELD, name, fieldName, fieldDesc)
|
|
|
mv.visitInsn(Opcodes.ARETURN)
|
|
|
mv.visitMaxs(0, 0)
|
|
|
mv.visitEnd()
|
|
|
}
|
|
|
|
|
|
private int pCount;
|
|
|
- private String name;
|
|
|
+ private String name;//class name
|
|
|
private Agent agent;
|
|
|
|
|
|
MethodLifeCycleVisitor(MethodVisitor mv, String name, Agent agent) {
|