use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class ClassInjectorUsingInstrumentationTest method testSystemInjection.
@Test
@AgentAttachmentRule.Enforce
public void testSystemInjection() throws Exception {
ClassInjector classInjector = ClassInjector.UsingInstrumentation.of(folder, ClassInjector.UsingInstrumentation.Target.SYSTEM, ByteBuddyAgent.install());
String name = BAR + RandomString.make();
DynamicType dynamicType = new ByteBuddy().subclass(Object.class).name(name).make();
Map<TypeDescription, Class<?>> types = classInjector.inject(Collections.singletonMap(dynamicType.getTypeDescription(), dynamicType.getBytes()));
assertThat(types.size(), is(1));
assertThat(types.get(dynamicType.getTypeDescription()).getName(), is(name));
assertThat(types.get(dynamicType.getTypeDescription()).getClassLoader(), is(ClassLoader.getSystemClassLoader()));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class ClassReloadingStrategyTest method testFromAgentClassReloadingStrategy.
@Test
@AgentAttachmentRule.Enforce(redefinesClasses = true)
public void testFromAgentClassReloadingStrategy() throws Exception {
assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
Foo foo = new Foo();
assertThat(foo.foo(), is(FOO));
ClassReloadingStrategy classReloadingStrategy = ClassReloadingStrategy.fromInstalledAgent();
new ByteBuddy().redefine(Foo.class).method(named(FOO)).intercept(FixedValue.value(BAR)).make().load(Foo.class.getClassLoader(), classReloadingStrategy);
try {
assertThat(foo.foo(), is(BAR));
} finally {
classReloadingStrategy.reset(Foo.class);
assertThat(foo.foo(), is(FOO));
}
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class ClassReloadingStrategyTest method testRetransformationReloadingStrategy.
@Test
@AgentAttachmentRule.Enforce(retransformsClasses = true)
public void testRetransformationReloadingStrategy() throws Exception {
assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
Foo foo = new Foo();
assertThat(foo.foo(), is(FOO));
ClassReloadingStrategy classReloadingStrategy = new ClassReloadingStrategy(ByteBuddyAgent.getInstrumentation(), ClassReloadingStrategy.Strategy.RETRANSFORMATION);
new ByteBuddy().redefine(Foo.class).method(named(FOO)).intercept(FixedValue.value(BAR)).make().load(Foo.class.getClassLoader(), classReloadingStrategy);
try {
assertThat(foo.foo(), is(BAR));
} finally {
classReloadingStrategy.reset(Foo.class);
assertThat(foo.foo(), is(FOO));
}
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AgentBuilderDefaultTest method testBuildPluginWithEntryPoint.
@Test
public void testBuildPluginWithEntryPoint() throws Exception {
Plugin plugin = mock(Plugin.class);
EntryPoint entryPoint = mock(EntryPoint.class);
ByteBuddy byteBuddy = mock(ByteBuddy.class);
when(entryPoint.getByteBuddy()).thenReturn(byteBuddy);
assertThat(AgentBuilder.Default.of(entryPoint, plugin), is((AgentBuilder) new AgentBuilder.Default(byteBuddy).with(new AgentBuilder.TypeStrategy.ForBuildEntryPoint(entryPoint)).type(plugin).transform(new AgentBuilder.Transformer.ForBuildPlugin(plugin))));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class MethodCallProxy method make.
@Override
public DynamicType make(String auxiliaryTypeName, ClassFileVersion classFileVersion, MethodAccessorFactory methodAccessorFactory) {
MethodDescription accessorMethod = methodAccessorFactory.registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT);
LinkedHashMap<String, TypeDescription> parameterFields = extractFields(accessorMethod);
DynamicType.Builder<?> builder = new ByteBuddy(classFileVersion).with(PrecomputedMethodGraph.INSTANCE).subclass(Object.class, ConstructorStrategy.Default.NO_CONSTRUCTORS).name(auxiliaryTypeName).modifiers(DEFAULT_TYPE_MODIFIER).implement(Runnable.class, Callable.class).intercept(new MethodCall(accessorMethod, assigner)).implement(serializableProxy ? new Class<?>[] { Serializable.class } : new Class<?>[0]).defineConstructor().withParameters(parameterFields.values()).intercept(ConstructorCall.INSTANCE);
for (Map.Entry<String, TypeDescription> field : parameterFields.entrySet()) {
builder = builder.defineField(field.getKey(), field.getValue(), Visibility.PRIVATE);
}
return builder.make();
}
Aggregations