本文整理汇总了Java中net.bytebuddy.agent.ByteBuddyAgent.install方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuddyAgent.install方法的具体用法?Java ByteBuddyAgent.install怎么用?Java ByteBuddyAgent.install使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.bytebuddy.agent.ByteBuddyAgent
的用法示例。
在下文中一共展示了ByteBuddyAgent.install方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: install
import net.bytebuddy.agent.ByteBuddyAgent; //导入方法依赖的package包/类
public static void install() {
ByteBuddyAgent.install();
ClassLoader targetClassLoader = File.class.getClassLoader();
// interceptor class must be injected to the same classloader as the target class that is intercepted
new ByteBuddy().redefine(CountFileSystemOperations.class)
.make()
.load(targetClassLoader,
ClassReloadingStrategy.fromInstalledAgent());
new ByteBuddy().redefine(DirectoryFileTree.class)
.visit(new AsmVisitorWrapper.ForDeclaredMethods().writerFlags(ClassWriter.COMPUTE_FRAMES)
.method(ElementMatchers.named("length"), Advice.to(CountFileSystemOperations.LengthMethod.class))
.method(ElementMatchers.named("isFile"), Advice.to(CountFileSystemOperations.IsFileMethod.class))
.method(ElementMatchers.named("isDirectory"), Advice.to(CountFileSystemOperations.IsDirectoryMethod.class))
.method(ElementMatchers.named("lastModified"), Advice.to(CountFileSystemOperations.LastModifiedMethod.class))
.method(ElementMatchers.named("exists"), Advice.to(CountFileSystemOperations.ExistsMethod.class))
)
.make()
.load(targetClassLoader,
ClassReloadingStrategy.fromInstalledAgent());
}
示例2: install
import net.bytebuddy.agent.ByteBuddyAgent; //导入方法依赖的package包/类
public static void install() {
ByteBuddyAgent.install();
ClassLoader targetClassLoader = DirectoryFileTree.class.getClassLoader();
// interceptor class must be injected to the same classloader as the target class that is intercepted
new ByteBuddy().redefine(CountDirectoryScans.class)
.make()
.load(targetClassLoader,
ClassReloadingStrategy.fromInstalledAgent());
new ByteBuddy().redefine(DirectoryFileTree.class)
.visit(new AsmVisitorWrapper.ForDeclaredMethods().writerFlags(ClassWriter.COMPUTE_FRAMES).method(ElementMatchers.named("visitFrom"), Advice.to(CountDirectoryScans.class)))
.make()
.load(targetClassLoader,
ClassReloadingStrategy.fromInstalledAgent());
}
示例3: testTutorialGettingStartedClassReloading
import net.bytebuddy.agent.ByteBuddyAgent; //导入方法依赖的package包/类
@Test
@AgentAttachmentRule.Enforce(redefinesClasses = true)
public void testTutorialGettingStartedClassReloading() throws Exception {
ByteBuddyAgent.install();
FooReloading foo = new FooReloading();
try {
new ByteBuddy()
.redefine(BarReloading.class)
.name(FooReloading.class.getName())
.make()
.load(FooReloading.class.getClassLoader(), ClassReloadingStrategy.fromInstalledAgent());
assertThat(foo.m(), is("bar"));
} finally {
ClassReloadingStrategy.fromInstalledAgent().reset(FooReloading.class); // Assure repeatability.
}
assertThat(foo.m(), is("foo"));
}
示例4: apply
import net.bytebuddy.agent.ByteBuddyAgent; //导入方法依赖的package包/类
@Override
public Statement apply(Statement base, FrameworkMethod method, Object target) {
Enforce enforce = method.getAnnotation(Enforce.class);
if (enforce != null) {
if (!available) {
return new NoOpStatement("The executing JVM does not support runtime attachment");
}
Instrumentation instrumentation = ByteBuddyAgent.install(ByteBuddyAgent.AttachmentProvider.DEFAULT);
if (enforce.redefinesClasses() && !instrumentation.isRedefineClassesSupported()) {
return new NoOpStatement("The executing JVM does not support class redefinition");
} else if (enforce.retransformsClasses() && !instrumentation.isRetransformClassesSupported()) {
return new NoOpStatement("The executing JVM does not support class retransformation");
} else if (enforce.nativeMethodPrefix() && !instrumentation.isNativeMethodPrefixSupported()) {
return new NoOpStatement("The executing JVM does not support class native method prefixes");
}
}
return base;
}
示例5: testAnonymousType
import net.bytebuddy.agent.ByteBuddyAgent; //导入方法依赖的package包/类
@Test
@JavaVersionRule.Enforce(value = 8, atMost = 8)
@AgentAttachmentRule.Enforce(retransformsClasses = true)
public void testAnonymousType() throws Exception {
ClassLoader classLoader = new ByteArrayClassLoader(ClassLoadingStrategy.BOOTSTRAP_LOADER,
ClassFileExtraction.of(Class.forName(LAMBDA_SAMPLE_FACTORY)),
ByteArrayClassLoader.PersistenceHandler.MANIFEST);
Instrumentation instrumentation = ByteBuddyAgent.install();
Class<?> factory = classLoader.loadClass(LAMBDA_SAMPLE_FACTORY);
@SuppressWarnings("unchecked")
Callable<String> instance = (Callable<String>) factory.getDeclaredMethod("nonCapturing").invoke(factory.getDeclaredConstructor().newInstance());
// Anonymous types can only be reset to their original format, if a retransformation is applied.
ClassReloadingStrategy classReloadingStrategy = new ClassReloadingStrategy(instrumentation,
ClassReloadingStrategy.Strategy.RETRANSFORMATION).preregistered(instance.getClass());
ClassFileLocator classFileLocator = ClassFileLocator.AgentBased.of(instrumentation, instance.getClass());
try {
assertThat(instance.call(), is(FOO));
new ByteBuddy()
.redefine(instance.getClass(), classFileLocator)
.method(named("call"))
.intercept(FixedValue.value(BAR))
.make()
.load(instance.getClass().getClassLoader(), classReloadingStrategy);
assertThat(instance.call(), is(BAR));
} finally {
classReloadingStrategy.reset(classFileLocator, instance.getClass());
assertThat(instance.call(), is(FOO));
}
}
示例6: testBootstrapInjection
import net.bytebuddy.agent.ByteBuddyAgent; //导入方法依赖的package包/类
@Test
@AgentAttachmentRule.Enforce
public void testBootstrapInjection() throws Exception {
ClassLoadingStrategy<ClassLoader> bootstrapStrategy = new ClassLoadingStrategy.ForBootstrapInjection(ByteBuddyAgent.install(), file);
String name = FOO + RandomString.make();
DynamicType dynamicType = new ByteBuddy().subclass(Object.class).name(name).make();
Map<TypeDescription, Class<?>> loaded = bootstrapStrategy.load(ClassLoadingStrategy.BOOTSTRAP_LOADER, Collections.singletonMap(dynamicType.getTypeDescription(), dynamicType.getBytes()));
assertThat(loaded.size(), is(1));
assertThat(loaded.get(dynamicType.getTypeDescription()).getName(), is(name));
assertThat(loaded.get(dynamicType.getTypeDescription()).getClassLoader(), nullValue(ClassLoader.class));
}
示例7: testClassLoaderInjection
import net.bytebuddy.agent.ByteBuddyAgent; //导入方法依赖的package包/类
@Test
@AgentAttachmentRule.Enforce
public void testClassLoaderInjection() throws Exception {
ClassLoadingStrategy<ClassLoader> bootstrapStrategy = new ClassLoadingStrategy.ForBootstrapInjection(ByteBuddyAgent.install(), file);
String name = BAR + RandomString.make();
ClassLoader classLoader = new URLClassLoader(new URL[0], null);
DynamicType dynamicType = new ByteBuddy().subclass(Object.class).name(name).make();
Map<TypeDescription, Class<?>> loaded = bootstrapStrategy.load(classLoader, Collections.singletonMap(dynamicType.getTypeDescription(), dynamicType.getBytes()));
assertThat(loaded.size(), is(1));
assertThat(loaded.get(dynamicType.getTypeDescription()).getName(), is(name));
assertThat(loaded.get(dynamicType.getTypeDescription()).getClassLoader(), is(classLoader));
}
示例8: getInstrumentation
import net.bytebuddy.agent.ByteBuddyAgent; //导入方法依赖的package包/类
private static Instrumentation getInstrumentation() {
try {
return ByteBuddyAgent.getInstrumentation();
} catch (IllegalStateException e) {
return ByteBuddyAgent.install(
new ByteBuddyAgent.AttachmentProvider.Compound(
new EhCacheAttachmentProvider(),
ByteBuddyAgent.AttachmentProvider.DEFAULT));
}
}
示例9: install
import net.bytebuddy.agent.ByteBuddyAgent; //导入方法依赖的package包/类
private static FakeIOTransformer install() {
Instrumentation inst = ByteBuddyAgent.install();
installBridge(inst);
return (FakeIOTransformer) new FakeIOTransformer().attach(inst);
}