1. 去除Bytebuddy插件,改用Javassit插件增强
This commit is contained in:
parent
21abb21011
commit
7ac79a3eeb
|
|
@ -0,0 +1,7 @@
|
|||
package com.ai.cloud.skywalking.agent.transformer;
|
||||
|
||||
/**
|
||||
* Created by xin on 16/7/24.
|
||||
*/
|
||||
public class PluginsTransformer {
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package com.ai.cloud.skywalking.plugin.exception;
|
||||
|
||||
/**
|
||||
* Created by xin on 16/7/25.
|
||||
*/
|
||||
public class EnhanceClassEmptyException {
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package com.ai.cloud.skywalking.plugin.exception;
|
||||
|
||||
/**
|
||||
* Created by xin on 16/7/25.
|
||||
*/
|
||||
public class EnhanceClassNotFoundException {
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.ai.cloud.skywalking.plugin;
|
||||
package com.ai.cloud.skywalking.plugin.exception;
|
||||
|
||||
public class PluginException extends Exception {
|
||||
private static final long serialVersionUID = -6020188711867490724L;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package com.ai.cloud.skywalking.plugin.exception;
|
||||
|
||||
/**
|
||||
* Created by xin on 16/7/25.
|
||||
*/
|
||||
public class WitnessClassesCannotFound {
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor.enhance;
|
||||
|
||||
public interface FieldSetter {
|
||||
void setValue(Object value);
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor.enhance;
|
||||
|
||||
public interface FieldGetter {
|
||||
Object getValue();
|
||||
public interface OriginCall {
|
||||
|
||||
Object call();
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor.enhance;
|
||||
|
||||
/**
|
||||
* Created by xin on 16/7/26.
|
||||
*/
|
||||
public class OriginCallCodeGenerator {
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package com.ai.cloud.skywalking.plugin.interceptor.matcher;
|
||||
|
||||
import com.ai.cloud.skywalking.plugin.interceptor.MethodMatcher;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.nameMatches;
|
||||
|
||||
public class MethodRegexMatcher extends MethodMatcher {
|
||||
|
||||
public MethodRegexMatcher(String methodMatchDescribe) {
|
||||
super(methodMatchDescribe);
|
||||
}
|
||||
|
||||
public MethodRegexMatcher(String methodMatchDescribe, int argNum) {
|
||||
super(methodMatchDescribe, argNum);
|
||||
}
|
||||
|
||||
public MethodRegexMatcher(String methodMatchDescribe, Class<?>... argTypeArray) {
|
||||
super(methodMatchDescribe, argTypeArray);
|
||||
}
|
||||
|
||||
public MethodRegexMatcher(Modifier modifier, String methodMatchDescribe) {
|
||||
super(modifier, methodMatchDescribe);
|
||||
}
|
||||
|
||||
public MethodRegexMatcher(Modifier modifier, String methodMatchDescribe, int argNum) {
|
||||
super(modifier, methodMatchDescribe, argNum);
|
||||
}
|
||||
|
||||
public MethodRegexMatcher(Modifier modifier, String methodMatchDescribe, Class<?>... argTypeArray) {
|
||||
super(modifier, methodMatchDescribe, argTypeArray);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ElementMatcher.Junction<MethodDescription> buildMatcher() {
|
||||
ElementMatcher.Junction<MethodDescription> matcher = nameMatches(getMethodMatchDescribe());
|
||||
return mergeArgumentsIfNecessary(matcher);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
new Origin
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
package test.ai.cloud.bytebuddy;
|
||||
|
||||
import net.bytebuddy.implementation.bind.annotation.AllArguments;
|
||||
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
|
||||
import net.bytebuddy.implementation.bind.annotation.This;
|
||||
|
||||
public class ConstructorInterceptor {
|
||||
@RuntimeType
|
||||
public void intercept(@AllArguments Object[] allArguments) {
|
||||
System.out
|
||||
.println("ConstructorInterceptor size:" + allArguments.length);
|
||||
if(allArguments.length > 0){
|
||||
System.out.println("ConstructorInterceptor param[0]=" + allArguments[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
package test.ai.cloud.bytebuddy;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import net.bytebuddy.implementation.bind.annotation.AllArguments;
|
||||
import net.bytebuddy.implementation.bind.annotation.Origin;
|
||||
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
|
||||
import net.bytebuddy.implementation.bind.annotation.SuperCall;
|
||||
import net.bytebuddy.implementation.bind.annotation.This;
|
||||
|
||||
public class MethodInterceptor{
|
||||
@RuntimeType
|
||||
public Object intercept(@This Object obj, @AllArguments Object[] allArguments, @Origin Method method, @SuperCall Callable<?> zuper){
|
||||
try {
|
||||
return method.getName() + ":intercept_" + zuper.call();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
package test.ai.cloud.bytebuddy;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.dynamic.ClassFileLocator;
|
||||
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
|
||||
import net.bytebuddy.dynamic.scaffold.subclass.ConstructorStrategy;
|
||||
import net.bytebuddy.implementation.MethodDelegation;
|
||||
import net.bytebuddy.implementation.SuperMethodCall;
|
||||
import net.bytebuddy.pool.TypePool;
|
||||
|
||||
public class SimulateMain {
|
||||
public static void main(String[] args) throws NoSuchFieldException,
|
||||
SecurityException, InstantiationException, IllegalAccessException, ClassNotFoundException {
|
||||
TypePool typePool = TypePool.Default.ofClassPath();
|
||||
System.out.println(typePool.describe("test.ai.cloud.bytebuddy.TestClass").isResolved());
|
||||
|
||||
Class<?> newClazz = new ByteBuddy()
|
||||
.redefine(
|
||||
typePool.describe("test.ai.cloud.bytebuddy.TestClass")
|
||||
.resolve(),
|
||||
ClassFileLocator.ForClassLoader.ofClassPath())
|
||||
.name("test.ai.cloud.bytebuddy.TestClass$$Origin")
|
||||
.make()
|
||||
.load(ClassLoader.getSystemClassLoader(),
|
||||
ClassLoadingStrategy.Default.INJECTION).getLoaded();
|
||||
|
||||
TestClass t22 = (TestClass) (new ByteBuddy()
|
||||
.subclass(newClazz, ConstructorStrategy.Default.IMITATE_SUPER_CLASS)
|
||||
.method(isMethod())
|
||||
.intercept(MethodDelegation.to(new MethodInterceptor()))
|
||||
.constructor(isConstructor())
|
||||
.intercept(MethodDelegation.to(new ConstructorInterceptor()).andThen(SuperMethodCall.INSTANCE))
|
||||
.name("test.ai.cloud.bytebuddy.TestClass")
|
||||
.make()
|
||||
.load(ClassLoader.getSystemClassLoader(),
|
||||
ClassLoadingStrategy.Default.INJECTION).getLoaded()
|
||||
.newInstance());
|
||||
|
||||
// System.out.println(t22.testA("1"));
|
||||
TestClass t = new TestClass("abc");
|
||||
System.out.println(t.testA("1"));
|
||||
|
||||
t = new TestClass("abc");
|
||||
System.out.println(t.testA("1"));
|
||||
|
||||
// TestClass t2 = null;
|
||||
// try {
|
||||
// t2 = (TestClass) Class.forName("test.ai.cloud.bytebuddy.TestClass")
|
||||
// .newInstance();
|
||||
// } catch (ClassNotFoundException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// System.out.println(t2.testA("1"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
package test.ai.cloud.bytebuddy;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.dynamic.ClassFileLocator;
|
||||
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
|
||||
import net.bytebuddy.implementation.MethodDelegation;
|
||||
import net.bytebuddy.implementation.SuperMethodCall;
|
||||
import net.bytebuddy.pool.TypePool;
|
||||
|
||||
public class SimulateMain2 {
|
||||
public static void main(String[] args) throws InstantiationException,
|
||||
IllegalAccessException {
|
||||
TypePool typePool = TypePool.Default.ofClassPath();
|
||||
|
||||
new ByteBuddy()
|
||||
.rebase(typePool.describe("test.ai.cloud.bytebuddy.TestClass")
|
||||
.resolve(),
|
||||
ClassFileLocator.ForClassLoader.ofClassPath())
|
||||
.method(named("testA"))
|
||||
.intercept(MethodDelegation.to(new MethodInterceptor()))
|
||||
.method(named("testB"))
|
||||
.intercept(MethodDelegation.to(new MethodInterceptor()))
|
||||
.constructor(isConstructor())
|
||||
.intercept(
|
||||
MethodDelegation.to(new ConstructorInterceptor())
|
||||
.andThen(SuperMethodCall.INSTANCE))
|
||||
.make()
|
||||
.load(ClassLoader.getSystemClassLoader(),
|
||||
ClassLoadingStrategy.Default.INJECTION).getLoaded();
|
||||
|
||||
TestClass t = new TestClass("abc");
|
||||
System.out.println(t.testA("1"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
package test.ai.cloud.bytebuddy;
|
||||
|
||||
public class TestClass {
|
||||
public TestClass(){
|
||||
//System.out.println("init:" + this.getClass().getName());
|
||||
}
|
||||
|
||||
public TestClass(String tmp){
|
||||
//System.out.println("init:" + this.getClass().getName());
|
||||
}
|
||||
|
||||
|
||||
public String testA(String aa){
|
||||
// throw new RuntimeException("adfasdfas");
|
||||
return "TestClass.testA";
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1 @@
|
|||
com.ai.cloud.skywalking.plugin.tomcat8.define.Tomcat8PluginDefine
|
||||
com.ai.cloud.skywalking.plugin.tomcat78x.define.TomcatPluginDefine
|
||||
|
|
|
|||
Loading…
Reference in New Issue