private boolean filterCoreJavaClasses(ClassLoader classLoader, TypeDescription typeDescription) { if (transformsCoreJavaClasses()) { return true; } else { final boolean isCoreJavaClass = isBootstrapClassLoader().matches(classLoader) || nameStartsWith("java") .or(nameStartsWith("com.sun.")) .or(nameStartsWith("sun.")) .or(nameStartsWith("jdk.")).matches(typeDescription); return !isCoreJavaClass; } }
/** * Matches any Java bean setter method. * * @param <T> The type of the matched object. * @return A matcher that matches any setter method. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter() { return nameStartsWith("set").and(takesArguments(1)).and(returns(TypeDescription.VOID)); }
/** * Matches any Java bean getter method. * * @param <T> The type of the matched object. * @return A matcher that matches any getter method. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isGetter() { return takesArguments(0).and(not(returns(TypeDescription.VOID))).and(nameStartsWith("get").or(nameStartsWith("is").and(returnsGeneric(anyOf(boolean.class, Boolean.class))))); }
private ProxyDefinitionHelpers() { this.groovyGetMetaClassFilter = isSynthetic().and( named( "getMetaClass" ) .and( returns( td -> "groovy.lang.MetaClass".equals( td.getName() ) ) ) ); this.virtualNotFinalizerFilter = isVirtual().and( not( isFinalizer() ) ); this.hibernateGeneratedMethodFilter = nameStartsWith( "$$_hibernate_" ).and( isVirtual() ); PrivilegedAction<MethodDelegation> delegateToInterceptorDispatcherMethodDelegationPrivilegedAction = new PrivilegedAction<MethodDelegation>() { @Override public MethodDelegation run() { return MethodDelegation.to( ProxyConfiguration.InterceptorDispatcher.class ); } }; this.delegateToInterceptorDispatcherMethodDelegation = System.getSecurityManager() != null ? AccessController.doPrivileged( delegateToInterceptorDispatcherMethodDelegationPrivilegedAction ) : delegateToInterceptorDispatcherMethodDelegationPrivilegedAction.run(); PrivilegedAction<FieldAccessor.PropertyConfigurable> interceptorFieldAccessorPrivilegedAction = new PrivilegedAction<FieldAccessor.PropertyConfigurable>() { @Override public FieldAccessor.PropertyConfigurable run() { return FieldAccessor.ofField( ProxyConfiguration.INTERCEPTOR_FIELD_NAME ) .withAssigner( Assigner.DEFAULT, Assigner.Typing.DYNAMIC ); } }; this.interceptorFieldAccessor = System.getSecurityManager() != null ? AccessController.doPrivileged( interceptorFieldAccessorPrivilegedAction ) : interceptorFieldAccessorPrivilegedAction.run(); }
private static AgentBuilder createAgentBuilder(AutoEvictingCachingBinaryLocator binaryLocator) { final ByteBuddy byteBuddy = new ByteBuddy() .with(TypeValidation.of(corePlugin.isDebugInstrumentation())) .with(MethodGraph.Compiler.ForDeclaredMethods.INSTANCE); return new AgentBuilder.Default(byteBuddy) .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION) .with(getListener()) .with(binaryLocator) .ignore(any(), timed("classloader", "reflection", isReflectionClassLoader())) .or(any(), timed("classloader", "groovy-call-site", classLoaderWithName("org.codehaus.groovy.runtime.callsite.CallSiteClassLoader"))) .or(any(), new IsIgnoredClassLoaderElementMatcher()) .or(timed("type", "global-exclude", nameStartsWith("org.aspectj.") .or(nameStartsWith("org.groovy.")) .or(nameStartsWith("com.p6spy.")) .or(nameStartsWith("net.bytebuddy.")) .or(nameStartsWith("org.slf4j.").and(not(nameStartsWith("org.slf4j.impl.")))) .or(nameContains("javassist")) .or(nameContains(".asm.")) .or(nameStartsWith("org.stagemonitor") .and(not(nameContains("Test") .or(nameContains("benchmark")) .or(nameStartsWith("org.stagemonitor.demo"))))) )) .disableClassFormatChanges(); }
new RawMatcher.Disjunction( new RawMatcher.ForElementMatchers(any(), isBootstrapClassLoader().or(isExtensionClassLoader())), new RawMatcher.ForElementMatchers(nameStartsWith("net.bytebuddy.").or(nameStartsWith("sun.reflect.")).<TypeDescription>or(isSynthetic()))), Transformation.Ignored.INSTANCE);
.method(isVirtual() .and(not(isBridge().or(isHashCode()).or(isEquals()).or(isDefaultFinalizer()))) .and(not(isDeclaredBy(nameStartsWith("java.")).<MethodDescription>and(isPackagePrivate()))), Advice.withCustomMapping() .bind(MockMethodAdvice.Identifier.class, identifier)
AnnotationAppender.ForTypeAnnotations.VARIABLE_ON_INVOKEABLE, methodDescription.getTypeVariables()); for (AnnotationDescription annotation : methodDescription.getDeclaredAnnotations().filter(not(annotationType(nameStartsWith("jdk.internal."))))) { annotationAppender = annotationAppender.append(annotation, annotationValueFilter);
public static ElementMatcher.Junction<NamedElement> isInAnyPackage(Collection<String> includedPackages, ElementMatcher.Junction<NamedElement> defaultIfEmpty) { if (includedPackages.isEmpty()) { return defaultIfEmpty; } ElementMatcher.Junction<NamedElement> matcher = none(); for (String applicationPackage : includedPackages) { matcher = matcher.or(nameStartsWith(applicationPackage)); } return matcher; }
private static Junction<MethodDescription> isPackagePrivateJavaMethods() { return isDeclaredBy(nameStartsWith("java.")).and(isPackagePrivate()); }
for(int i = 0; i < arr.length; i++) { if(includeMatcher == null){ includeMatcher = ElementMatchers.nameStartsWith(arr[i]); continue; includeMatcher = includeMatcher.or(ElementMatchers.nameStartsWith(arr[i])); String[] arr = nameStartsWithVal.split(","); for(int i = 0; i < arr.length; i++) { matcher = matcher.and(ElementMatchers.not(ElementMatchers.<MethodDescription>nameStartsWith(arr[i])));
private ProxyDefinitionHelpers() { this.groovyGetMetaClassFilter = isSynthetic().and( named( "getMetaClass" ) .and( returns( td -> "groovy.lang.MetaClass".equals( td.getName() ) ) ) ); this.virtualNotFinalizerFilter = isVirtual().and( not( isFinalizer() ) ); this.hibernateGeneratedMethodFilter = nameStartsWith( "$$_hibernate_" ).and( isVirtual() ); PrivilegedAction<MethodDelegation> delegateToInterceptorDispatcherMethodDelegationPrivilegedAction = new PrivilegedAction<MethodDelegation>() { @Override public MethodDelegation run() { return MethodDelegation.to( ProxyConfiguration.InterceptorDispatcher.class ); } }; this.delegateToInterceptorDispatcherMethodDelegation = System.getSecurityManager() != null ? AccessController.doPrivileged( delegateToInterceptorDispatcherMethodDelegationPrivilegedAction ) : delegateToInterceptorDispatcherMethodDelegationPrivilegedAction.run(); PrivilegedAction<FieldAccessor.PropertyConfigurable> interceptorFieldAccessorPrivilegedAction = new PrivilegedAction<FieldAccessor.PropertyConfigurable>() { @Override public FieldAccessor.PropertyConfigurable run() { return FieldAccessor.ofField( ProxyConfiguration.INTERCEPTOR_FIELD_NAME ) .withAssigner( Assigner.DEFAULT, Assigner.Typing.DYNAMIC ); } }; this.interceptorFieldAccessor = System.getSecurityManager() != null ? AccessController.doPrivileged( interceptorFieldAccessorPrivilegedAction ) : interceptorFieldAccessorPrivilegedAction.run(); }
public static ElementMatcher.Junction<TypeDescription> buildTypesMatcher(Map<String,String> includeMap,Map<String,String> excludeMap){ ElementMatcher.Junction<TypeDescription> matcher = ElementMatchers.not(ElementMatchers.<TypeDescription>nameStartsWith("net.beeapm.agent.")); if(includeMap != null && !includeMap.isEmpty()){ String namedVal = includeMap.get("named"); for(int i = 0; i < arr.length; i++){ if(includeMatcher == null){ includeMatcher = ElementMatchers.nameStartsWith(arr[i]); continue; includeMatcher = includeMatcher.or(ElementMatchers.nameStartsWith(arr[i])); String[] arr = nameStartsWithVal.split(","); for(int i = 0; i < arr.length; i++) { matcher = matcher.and(ElementMatchers.not(ElementMatchers.<TypeDescription>nameStartsWith(arr[i])));
.ignore(any(), isReflectionClassLoader()) .or(any(), classLoaderWithName("org.codehaus.groovy.runtime.callsite.CallSiteClassLoader")) .or(nameStartsWith("java.") .and( not( nameEndsWith("URLConnection") .or(nameStartsWith("java.util.concurrent.")) .or(nameStartsWith("com.sun.") .and( not( nameStartsWith("com.sun.faces.") .or(nameEndsWith("URLConnection")) .or(nameStartsWith("sun") .and( not(nameEndsWith("URLConnection")) .or(nameStartsWith("org.aspectj.")) .or(nameStartsWith("org.groovy.")) .or(nameStartsWith("com.p6spy.")) .or(nameStartsWith("net.bytebuddy.")) .or(nameStartsWith("org.stagemonitor.")) .or(nameContains("javassist")) .or(nameContains(".asm."))
static Object create(final Object bean, DecoratorExecutor executor) { try { Object proxy = new ByteBuddy() .subclass(bean.getClass()) .implement(EnhancedProxy.class) .defineField("bean", bean.getClass(), Modifier.PRIVATE) .defineField("executor", DecoratorExecutor.class, Modifier.PRIVATE) .method(isEquals()) .intercept(to(EqualsInterceptor.class)) .method(isAnnotatedWith(nameStartsWith("cucumber.api"))) .intercept(to(CucumberInterceptor.class)) .method(not(isEquals().or(isClone()).or(isAnnotatedWith(nameStartsWith("cucumber.api"))))) .intercept(toField("bean")) .make() .load(bean.getClass().getClassLoader(), ClassLoadingStrategy.Default.INJECTION) .getLoaded() .newInstance(); ReflectionUtils.injectValue(proxy, "bean", bean); ReflectionUtils.injectValue(proxy, "executor", executor); return proxy; } catch (Exception e) { throw new JpaUnitException("Failed to create proxy for " + bean, e); } } }