|
@@ -1,6 +1,5 @@
|
|
package com.gradle.ares
|
|
package com.gradle.ares
|
|
|
|
|
|
-import org.gradle.api.logging.Logging
|
|
|
|
import org.objectweb.asm.ClassVisitor
|
|
import org.objectweb.asm.ClassVisitor
|
|
import org.objectweb.asm.FieldVisitor
|
|
import org.objectweb.asm.FieldVisitor
|
|
import org.objectweb.asm.Label
|
|
import org.objectweb.asm.Label
|
|
@@ -55,28 +54,28 @@ public class MethodLifeCycleVisitor extends MethodVisitor {
|
|
|
|
|
|
public final
|
|
public final
|
|
static void addMethods(Set<Agent> agentSet, String name, String superName, ClassVisitor cv) {
|
|
static void addMethods(Set<Agent> agentSet, String name, String superName, ClassVisitor cv) {
|
|
- addLifeCycleFieldMethod(cv)
|
|
|
|
|
|
+ addLifeCycleFieldMethod(name, cv)
|
|
for (Agent agent : Modify) {
|
|
for (Agent agent : Modify) {
|
|
if (!agentSet.contains(agent)) {
|
|
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
|
|
* @param cv
|
|
*/
|
|
*/
|
|
- private final static void addLifeCycleFieldMethod(ClassVisitor cv) {
|
|
|
|
|
|
+ private final static void addLifeCycleFieldMethod(String name, ClassVisitor cv) {
|
|
//desc
|
|
//desc
|
|
String fieldName = "\$lifeCycleAresDelegate"
|
|
String fieldName = "\$lifeCycleAresDelegate"
|
|
String fieldDesc = "L" + LifeClass + ";"
|
|
String fieldDesc = "L" + LifeClass + ";"
|
|
@@ -96,23 +95,23 @@ public class MethodLifeCycleVisitor extends MethodVisitor {
|
|
MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, GetLifeMethod, "()" + fieldDesc, null, null)
|
|
MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, GetLifeMethod, "()" + fieldDesc, null, null)
|
|
mv.visitCode()
|
|
mv.visitCode()
|
|
mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
- mv.visitFieldInsn(Opcodes.GETFIELD, LifeClass, fieldName, fieldDesc)
|
|
|
|
|
|
+ mv.visitFieldInsn(Opcodes.GETFIELD, name, fieldName, fieldDesc)
|
|
Label label = new Label()
|
|
Label label = new Label()
|
|
mv.visitJumpInsn(Opcodes.IFNONNULL, label)
|
|
mv.visitJumpInsn(Opcodes.IFNONNULL, label)
|
|
mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
mv.visitMethodInsn(Opcodes.INVOKESTATIC, LifeClass, "create", "(Ljava/lang/Object;)" + fieldDesc, false)
|
|
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.visitLabel(label)
|
|
mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
mv.visitVarInsn(Opcodes.ALOAD, 0)
|
|
- mv.visitFieldInsn(Opcodes.GETFIELD, LifeClass, fieldName, fieldDesc)
|
|
|
|
|
|
+ mv.visitFieldInsn(Opcodes.GETFIELD, name, fieldName, fieldDesc)
|
|
mv.visitInsn(Opcodes.ARETURN)
|
|
mv.visitInsn(Opcodes.ARETURN)
|
|
mv.visitMaxs(0, 0)
|
|
mv.visitMaxs(0, 0)
|
|
mv.visitEnd()
|
|
mv.visitEnd()
|
|
}
|
|
}
|
|
|
|
|
|
private int pCount;
|
|
private int pCount;
|
|
- private String name;
|
|
|
|
|
|
+ private String name;//class name
|
|
private Agent agent;
|
|
private Agent agent;
|
|
|
|
|
|
MethodLifeCycleVisitor(MethodVisitor mv, String name, Agent agent) {
|
|
MethodLifeCycleVisitor(MethodVisitor mv, String name, Agent agent) {
|