Search in sources :

Example 46 with ClassFileTransformer

use of java.lang.instrument.ClassFileTransformer in project byte-buddy by raphw.

the class AgentBuilderDefaultTest method testIgnoredTypeMatcherOnlyAppliedOnceWithMultipleTransformations.

@Test
public void testIgnoredTypeMatcherOnlyAppliedOnceWithMultipleTransformations() throws Exception {
    AgentBuilder.RawMatcher ignored = mock(AgentBuilder.RawMatcher.class);
    ClassFileTransformer classFileTransformer = new AgentBuilder.Default(byteBuddy).with(initializationStrategy).with(poolStrategy).with(typeStrategy).with(installationListener).with(listener).disableNativeMethodPrefix().ignore(ignored).type(typeMatcher).transform(transformer).type(typeMatcher).transform(transformer).installOn(instrumentation);
    assertThat(transform(classFileTransformer, JavaModule.ofType(REDEFINED), REDEFINED.getClassLoader(), REDEFINED.getName(), REDEFINED, REDEFINED.getProtectionDomain(), QUX), nullValue(byte[].class));
    verify(listener).onIgnored(new TypeDescription.ForLoadedType(REDEFINED), REDEFINED.getClassLoader(), JavaModule.ofType(REDEFINED), true);
    verify(listener).onComplete(REDEFINED.getName(), REDEFINED.getClassLoader(), JavaModule.ofType(REDEFINED), true);
    verifyNoMoreInteractions(listener);
    verify(ignored).matches(new TypeDescription.ForLoadedType(REDEFINED), REDEFINED.getClassLoader(), JavaModule.ofType(REDEFINED), REDEFINED, REDEFINED.getProtectionDomain());
    verifyNoMoreInteractions(ignored);
}
Also used : ClassFileTransformer(java.lang.instrument.ClassFileTransformer) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 47 with ClassFileTransformer

use of java.lang.instrument.ClassFileTransformer in project byte-buddy by raphw.

the class AgentBuilderLambdaInstrumentationStrategyTest method testDisabledStrategyIsNoOp.

@Test
public void testDisabledStrategyIsNoOp() throws Exception {
    ByteBuddy byteBuddy = mock(ByteBuddy.class);
    Instrumentation instrumentation = mock(Instrumentation.class);
    ClassFileTransformer classFileTransformer = mock(ClassFileTransformer.class);
    AgentBuilder.Default.LambdaInstrumentationStrategy.DISABLED.apply(byteBuddy, instrumentation, classFileTransformer);
    verifyZeroInteractions(byteBuddy);
    verifyZeroInteractions(instrumentation);
    verifyZeroInteractions(classFileTransformer);
}
Also used : ClassFileTransformer(java.lang.instrument.ClassFileTransformer) ByteBuddy(net.bytebuddy.ByteBuddy) Instrumentation(java.lang.instrument.Instrumentation) Test(org.junit.Test)

Example 48 with ClassFileTransformer

use of java.lang.instrument.ClassFileTransformer in project pinpoint by naver.

the class MockPluginContextLoadResult method getClassFileTransformer.

@Override
public List<ClassFileTransformer> getClassFileTransformer() {
    List<ClassFileTransformer> classFileTransformerList = new ArrayList<ClassFileTransformer>();
    for (SetupResult pluginContext : getProfilerPluginContextList()) {
        List<ClassFileTransformer> classFileTransformer = pluginContext.getClassTransformerList();
        classFileTransformerList.addAll(classFileTransformer);
    }
    return classFileTransformerList;
}
Also used : ClassFileTransformer(java.lang.instrument.ClassFileTransformer) SetupResult(com.navercorp.pinpoint.profiler.plugin.SetupResult) ArrayList(java.util.ArrayList)

Example 49 with ClassFileTransformer

use of java.lang.instrument.ClassFileTransformer in project pinpoint by naver.

the class DefaultClassFileTransformerDispatcher method createTransformerRegistry.

private TransformerRegistry createTransformerRegistry(PluginContextLoadResult pluginContexts) {
    DefaultTransformerRegistry registry = new DefaultTransformerRegistry();
    for (ClassFileTransformer transformer : pluginContexts.getClassFileTransformer()) {
        if (transformer instanceof MatchableClassFileTransformer) {
            MatchableClassFileTransformer t = (MatchableClassFileTransformer) transformer;
            logger.info("Registering class file transformer {} for {} ", t, t.getMatcher());
            registry.addTransformer(t.getMatcher(), t);
        } else {
            logger.warn("Ignore class file transformer {}", transformer);
        }
    }
    return registry;
}
Also used : MatchableClassFileTransformer(com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer) ClassFileTransformer(java.lang.instrument.ClassFileTransformer) MatchableClassFileTransformer(com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer) DefaultTransformerRegistry(com.navercorp.pinpoint.profiler.instrument.transformer.DefaultTransformerRegistry)

Example 50 with ClassFileTransformer

use of java.lang.instrument.ClassFileTransformer in project pinpoint by naver.

the class DefaultTransformerRegistry method addModifier0.

private void addModifier0(ClassFileTransformer transformer, String className) {
    final String classInternalName = JavaAssistUtils.javaNameToJvmName(className);
    ClassFileTransformer old = registry.put(classInternalName, transformer);
    if (old != null) {
        throw new IllegalStateException("Transformer already exist. className:" + classInternalName + " new:" + transformer.getClass() + " old:" + old.getClass());
    }
}
Also used : ClassFileTransformer(java.lang.instrument.ClassFileTransformer)

Aggregations

ClassFileTransformer (java.lang.instrument.ClassFileTransformer)54 Test (org.junit.Test)38 Instrumentation (java.lang.instrument.Instrumentation)35 ByteArrayClassLoader (net.bytebuddy.dynamic.loading.ByteArrayClassLoader)9 IllegalClassFormatException (java.lang.instrument.IllegalClassFormatException)7 Callable (java.util.concurrent.Callable)7 SimpleType (net.bytebuddy.test.packaging.SimpleType)6 ProtectionDomain (java.security.ProtectionDomain)5 ByteBuddy (net.bytebuddy.ByteBuddy)5 URLClassLoader (java.net.URLClassLoader)3 MatchableClassFileTransformer (com.navercorp.pinpoint.profiler.plugin.MatchableClassFileTransformer)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 PersistenceProvider (javax.persistence.spi.PersistenceProvider)2 TypeDescription (net.bytebuddy.description.type.TypeDescription)2 SimpleOptionalType (net.bytebuddy.test.packaging.SimpleOptionalType)2 TempClassLoader (org.apache.openejb.core.TempClassLoader)2 PersistenceClassLoaderHandler (org.apache.openejb.persistence.PersistenceClassLoaderHandler)2 PersistenceUnitInfoImpl (org.apache.openejb.persistence.PersistenceUnitInfoImpl)2