Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add ant-style path pattern. #2173

Merged
merged 1 commit into from
Oct 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent/src/main/resources-local/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ profiler.spring.beans=true
# ANT Style pattern rules:
# ? - matches on character
# * - matches zero or more characters
# ** - matches zero or more 'directories' in a path

# Examples
# profiler.spring.beans.1.name.scope=component-scan
Expand Down
1 change: 1 addition & 0 deletions agent/src/main/resources-release/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ profiler.spring.beans=true
# ANT Style pattern rules:
# ? - matches on character
# * - matches zero or more characters
# ** - matches zero or more 'directories' in a path

# Examples
# profiler.spring.beans.1.name.scope=component-scan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ profiler.spring.beans=true
# ANT Style pattern rules:
# ? - matches on character
# * - matches zero or more characters
# ** - matches zero or more 'directories' in a path

# Examples
# profiler.spring.beans.1.name.scope=component-scan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ profiler.spring.beans=true
# ANT Style pattern rules:
# ? - matches on character
# * - matches zero or more characters
# ** - matches zero or more 'directories' in a path

# Examples
# profiler.spring.beans.1.name.scope=component-scan
Expand Down
1 change: 1 addition & 0 deletions agent/src/test/resources/pinpoint-spring-bean-test.config
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ profiler.spring.beans=true
# ANT Style pattern rules:
# ? - matches on character
# * - matches zero or more characters
# ** - matches zero or more 'directories' in a path

# Examples:
# profiler.spring.beans.1.name.scope=component-scan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ public List<String> getBasePackages() {
}

public void setNamePatterns(final String namePatternRegex) {
this.namePatterns = compilePattern(split(namePatternRegex));
this.namePatterns = compilePattern(split(namePatternRegex), "/");
}

public List<PathMatcher> getNamePatterns() {
return namePatterns;
}

public void setClassPatterns(final String classPatternRegex) {
this.classPatterns = compilePattern(split(classPatternRegex));
this.classPatterns = compilePattern(split(classPatternRegex), ".");
}

public List<PathMatcher> getClassPatterns() {
Expand Down Expand Up @@ -114,7 +114,7 @@ List<String> split(final String values) {
return result;
}

List<PathMatcher> compilePattern(List<String> patternStrings) {
List<PathMatcher> compilePattern(List<String> patternStrings, final String separator) {
if (patternStrings == null || patternStrings.isEmpty()) {
return null;
}
Expand All @@ -127,7 +127,7 @@ List<PathMatcher> compilePattern(List<String> patternStrings) {
if (prefix.equals(ANT_STYLE_PATTERN_PREFIX)) {
final String trimmed = patternString.substring(prefixEnd + 1).trim();
if (!trimmed.isEmpty()) {
pathMatchers.add(new AntPathMatcher(trimmed));
pathMatchers.add(new AntPathMatcher(trimmed, separator));
}
continue;
} else if (prefix.equals(REGEX_PATTERN_PREFIX)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public void split() {
@Test
public void compilePattern() {
SpringBeansTarget target = new SpringBeansTarget();
List<PathMatcher> list = target.compilePattern(Arrays.asList("1", "regex:2", "antstyle:3"));
List<PathMatcher> list = target.compilePattern(Arrays.asList("1", "regex:2", "antstyle:3"), ".");
assertEquals(3, list.size());
list = target.compilePattern(Arrays.asList("1", "regex: 2", "antstyle: 3"));
list = target.compilePattern(Arrays.asList("1", "regex: 2", "antstyle: 3"), ".");
assertEquals(3, list.size());
list = target.compilePattern(Arrays.asList("1", "regex:", "antstyle:"));
list = target.compilePattern(Arrays.asList("1", "regex:", "antstyle:"), ".");
assertEquals(1, list.size());
list = target.compilePattern(Arrays.asList("1", "regex: 1", "antstyle: 2"));
list = target.compilePattern(Arrays.asList("1", "regex: 1", "antstyle: 2"), ".");
assertEquals(3, list.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,29 @@ public void beansNamePattern() {

@Test
public void classNamePattern() {
assertClassNamePattern("antstyle:**");
assertClassNamePattern("antstyle:java.*.String");
assertClassNamePattern("antstyle:java.**.String");
assertClassNamePattern("antstyle:java.*.*");
assertClassNamePattern("antstyle:java.**");
assertClassNamePattern("antstyle:**.String");
assertClassNamePattern("antstyle:java.lang.S*");
assertClassNamePattern("antstyle:java.lang.*");
assertClassNamePattern("antstyle:java.lang.Strin?");
assertClassNamePattern("java.*");
assertClassNamePattern("regex:java.*");
assertClassNamePattern("regex:java.*.String");
}

private void assertClassNamePattern(final String pattern) {
Properties properties = new Properties();
properties.put(SpringBeansConfig.SPRING_BEANS_PREFIX + 1 + SpringBeansConfig.SPRING_BEANS_CLASS_PATTERN_POSTFIX, "antstyle:*");
properties.put(SpringBeansConfig.SPRING_BEANS_PREFIX + 1 + SpringBeansConfig.SPRING_BEANS_CLASS_PATTERN_POSTFIX, pattern);
ProfilerConfig config = new DefaultProfilerConfig(properties);
TargetBeanFilter filter = TargetBeanFilter.of(config);
filter.clear();

BeanDefinition beanDefinition = new RootBeanDefinition(String.class);
assertTrue(filter.isTarget(SpringBeansTargetScope.COMPONENT_SCAN, "Target0", beanDefinition));

filter.addTransformed(String.class.getName());

assertFalse(filter.isTarget(SpringBeansTargetScope.COMPONENT_SCAN, "Target0", beanDefinition));
assertFalse(filter.isTarget(SpringBeansTargetScope.COMPONENT_SCAN, "Target1", beanDefinition));
}

@Test
Expand Down
1 change: 1 addition & 0 deletions quickstart/agent/src/main/resources/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ profiler.spring.beans=true
# ANT Style pattern rules:
# ? - matches on character
# * - matches zero or more characters
# ** - matches zero or more 'directories' in a path

# Examples
# profiler.spring.beans.1.name.scope=component-scan
Expand Down
1 change: 1 addition & 0 deletions quickstart/conf/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ profiler.spring.beans=true
# ANT Style pattern rules:
# ? - matches on character
# * - matches zero or more characters
# ** - matches zero or more 'directories' in a path

# Examples
# profiler.spring.beans.1.name.scope=component-scan
Expand Down