提交 a7068a88 编写于 作者: A ascrutae

Revert "1. 去除Bytebuddy插件,改用Javassit插件增强"

This reverts commit 7ac79a3e.
上级 64c65892
package com.ai.cloud.skywalking.agent.transformer;
/**
* Created by xin on 16/7/24.
*/
public class PluginsTransformer {
}
package com.ai.cloud.skywalking.plugin.exception;
package com.ai.cloud.skywalking.plugin;
public class PluginException extends Exception {
private static final long serialVersionUID = -6020188711867490724L;
......
package com.ai.cloud.skywalking.plugin.exception;
/**
* Created by xin on 16/7/25.
*/
public class EnhanceClassEmptyException {
}
package com.ai.cloud.skywalking.plugin.exception;
/**
* Created by xin on 16/7/25.
*/
public class EnhanceClassNotFoundException {
}
package com.ai.cloud.skywalking.plugin.exception;
/**
* Created by xin on 16/7/25.
*/
public class WitnessClassesCannotFound {
}
package com.ai.cloud.skywalking.plugin.interceptor.enhance;
/**
* Created by xin on 16/7/26.
*/
public class OriginCallCodeGenerator {
public interface FieldSetter {
void setValue(Object value);
}
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);
}
}
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]);
}
}
}
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;
}
}
}
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"));
}
}
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"));
}
}
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";
}
}
com.ai.cloud.skywalking.plugin.tomcat78x.define.TomcatPluginDefine
com.ai.cloud.skywalking.plugin.tomcat8.define.Tomcat8PluginDefine
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册