Search in sources :

Example 1 with PathMatcher

use of com.navercorp.pinpoint.bootstrap.util.PathMatcher in project pinpoint by naver.

the class SpringBeansTarget method compilePattern.

List<PathMatcher> compilePattern(List<String> patternStrings, final String separator) {
    if (CollectionUtils.isEmpty(patternStrings)) {
        return null;
    }
    final List<PathMatcher> pathMatchers = new ArrayList<>(patternStrings.size());
    for (String patternString : patternStrings) {
        final int prefixEnd = patternString.indexOf(":");
        if (prefixEnd != -1) {
            final String prefix = patternString.substring(0, prefixEnd).trim();
            if (prefix.equals(ANT_STYLE_PATTERN_PREFIX)) {
                final String trimmed = patternString.substring(prefixEnd + 1).trim();
                if (!trimmed.isEmpty()) {
                    pathMatchers.add(new AntPathMatcher(trimmed, separator));
                }
                continue;
            } else if (prefix.equals(REGEX_PATTERN_PREFIX)) {
                final String trimmed = patternString.substring(prefixEnd + 1).trim();
                if (!trimmed.isEmpty()) {
                    final Pattern pattern = Pattern.compile(trimmed);
                    pathMatchers.add(new RegexPathMatcher(pattern));
                }
                continue;
            }
        }
        final Pattern pattern = Pattern.compile(patternString);
        pathMatchers.add(new RegexPathMatcher(pattern));
    }
    return pathMatchers;
}
Also used : Pattern(java.util.regex.Pattern) PathMatcher(com.navercorp.pinpoint.bootstrap.util.PathMatcher) RegexPathMatcher(com.navercorp.pinpoint.bootstrap.util.RegexPathMatcher) AntPathMatcher(com.navercorp.pinpoint.bootstrap.util.AntPathMatcher) ArrayList(java.util.ArrayList) RegexPathMatcher(com.navercorp.pinpoint.bootstrap.util.RegexPathMatcher) AntPathMatcher(com.navercorp.pinpoint.bootstrap.util.AntPathMatcher)

Example 2 with PathMatcher

use of com.navercorp.pinpoint.bootstrap.util.PathMatcher in project pinpoint by naver.

the class TargetBeanFilter method isTarget.

public boolean isTarget(final SpringBeansTargetScope scope, final String beanName, final Class<?> clazz) {
    if (scope == null || beanName == null || clazz == null) {
        return false;
    }
    final String className = clazz.getName();
    if (className == null) {
        return false;
    }
    if (cache.contains(className)) {
        return false;
    }
    for (SpringBeansTarget target : targets) {
        // check scope.
        if (target.getScope() != scope) {
            continue;
        }
        boolean condition = false;
        // check base packages.
        final List<String> basePackages = target.getBasePackages();
        if (CollectionUtils.hasLength(basePackages)) {
            if (!isBasePackage(target, className)) {
                continue;
            }
            condition = true;
        }
        // check bean name pattern.
        final List<PathMatcher> namePatterns = target.getNamePatterns();
        if (CollectionUtils.hasLength(namePatterns)) {
            if (!isBeanNameTarget(target, beanName)) {
                continue;
            }
            condition = true;
        }
        // check class name pattern.
        final List<PathMatcher> classPatterns = target.getClassPatterns();
        if (CollectionUtils.hasLength(classPatterns)) {
            if (!isClassNameTarget(target, className)) {
                continue;
            }
            condition = true;
        }
        // check class annotation.
        final List<String> annotations = target.getAnnotations();
        if (CollectionUtils.hasLength(annotations)) {
            if (!isAnnotationTarget(target, clazz)) {
                continue;
            }
            condition = true;
        }
        if (condition) {
            // AND condition.
            return true;
        }
    }
    return false;
}
Also used : SpringBeansTarget(com.navercorp.pinpoint.plugin.spring.beans.SpringBeansTarget) PathMatcher(com.navercorp.pinpoint.bootstrap.util.PathMatcher)

Example 3 with PathMatcher

use of com.navercorp.pinpoint.bootstrap.util.PathMatcher in project pinpoint by naver.

the class TargetBeanFilter method isTarget.

public boolean isTarget(final SpringBeansTargetScope scope, final String beanName, final BeanDefinition beanDefinition) {
    if (scope == null || beanName == null || beanDefinition == null) {
        return false;
    }
    final String className = beanDefinition.getBeanClassName();
    if (className == null) {
        return false;
    }
    if (cache.contains(className)) {
        return false;
    }
    for (SpringBeansTarget target : targets) {
        // check scope.
        if (target.getScope() != scope) {
            continue;
        }
        boolean condition = false;
        // check base packages.
        final List<String> basePackages = target.getBasePackages();
        if (CollectionUtils.hasLength(basePackages)) {
            if (!isBasePackage(target, className)) {
                continue;
            }
            condition = true;
        }
        // check bean name pattern.
        final List<PathMatcher> namePatterns = target.getNamePatterns();
        if (CollectionUtils.hasLength(namePatterns)) {
            if (!isBeanNameTarget(target, beanName)) {
                continue;
            }
            condition = true;
        }
        // check class name pattern.
        final List<PathMatcher> classPatterns = target.getClassPatterns();
        if (CollectionUtils.hasLength(classPatterns)) {
            if (!isClassNameTarget(target, className)) {
                continue;
            }
            condition = true;
        }
        // check class annotation.
        final List<String> annotations = target.getAnnotations();
        if (CollectionUtils.hasLength(annotations)) {
            if (!(beanDefinition instanceof AnnotatedBeanDefinition) || !isAnnotationTarget(target, (AnnotatedBeanDefinition) beanDefinition)) {
                continue;
            }
            condition = true;
        }
        if (condition) {
            // AND condition.
            return true;
        }
    }
    return false;
}
Also used : SpringBeansTarget(com.navercorp.pinpoint.plugin.spring.beans.SpringBeansTarget) PathMatcher(com.navercorp.pinpoint.bootstrap.util.PathMatcher) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)

Aggregations

PathMatcher (com.navercorp.pinpoint.bootstrap.util.PathMatcher)3 SpringBeansTarget (com.navercorp.pinpoint.plugin.spring.beans.SpringBeansTarget)2 AntPathMatcher (com.navercorp.pinpoint.bootstrap.util.AntPathMatcher)1 RegexPathMatcher (com.navercorp.pinpoint.bootstrap.util.RegexPathMatcher)1 ArrayList (java.util.ArrayList)1 Pattern (java.util.regex.Pattern)1 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)1