From d10478f95fad42c6325dfd1956b54cee36b3f8da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=91=E6=88=9F?= Date: Sat, 17 Apr 2021 17:46:35 +0800 Subject: [PATCH] package prefix should auto append dot --- docs/zh-cn/doc/javaagent-args.md | 4 ++-- .../com/alibaba/testable/agent/config/ArgumentParser.java | 2 +- .../com/alibaba/testable/agent/config/PropertiesParser.java | 2 +- .../agent/transformer/TestableClassTransformer.java | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/zh-cn/doc/javaagent-args.md b/docs/zh-cn/doc/javaagent-args.md index 6596271..ef41fe7 100644 --- a/docs/zh-cn/doc/javaagent-args.md +++ b/docs/zh-cn/doc/javaagent-args.md @@ -32,7 +32,7 @@ ```xml - -javaagent:${settings.localRepository}/com/alibaba/testable/testable-agent/${testable.version}/testable-agent-${testable.version}.jar=mockScope=associated&pkgPrefix=com.demo. + -javaagent:${settings.localRepository}/com/alibaba/testable/testable-agent/${testable.version}/testable-agent-${testable.version}.jar=mockScope=associated&pkgPrefix=com.demo ``` @@ -42,5 +42,5 @@ ```groovy - jvmArgs "-javaagent:${classpath.find { it.name.contains("testable-agent") }.absolutePath}=mockScope=associated&pkgPrefix=com.demo." + jvmArgs "-javaagent:${classpath.find { it.name.contains("testable-agent") }.absolutePath}=mockScope=associated&pkgPrefix=com.demo" ``` diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/config/ArgumentParser.java b/testable-agent/src/main/java/com/alibaba/testable/agent/config/ArgumentParser.java index 08a070c..a25a0ed 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/config/ArgumentParser.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/config/ArgumentParser.java @@ -33,7 +33,7 @@ public class ArgumentParser { } else if (k.equals(DUMP_PATH)) { GlobalConfig.setDumpPath(v); } else if (k.equals(PKG_PREFIX)) { - GlobalConfig.setPkgPrefix(v); + GlobalConfig.setPkgPrefixes(v); } else if (k.equals(MOCK_SCOPE)) { GlobalConfig.setDefaultMockScope(MockScope.of(v)); } else if (k.equals(CONFIG_FILE)) { diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/config/PropertiesParser.java b/testable-agent/src/main/java/com/alibaba/testable/agent/config/PropertiesParser.java index 3ecdd5e..f6b5131 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/config/PropertiesParser.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/config/PropertiesParser.java @@ -57,7 +57,7 @@ public class PropertiesParser { } else if (k.equals(DUMP_PATH)) { GlobalConfig.setDumpPath(v); } else if (k.equals(PKG_PREFIX_WHITELIST)) { - GlobalConfig.setPkgPrefix(v); + GlobalConfig.setPkgPrefixes(v); } else if (k.equals(DEFAULT_MOCK_SCOPE)) { GlobalConfig.setDefaultMockScope(MockScope.of(v)); } else if (k.equals(ENABLE_THREAD_POOL)) { diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/TestableClassTransformer.java b/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/TestableClassTransformer.java index 84585cd..0aefdef 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/TestableClassTransformer.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/TestableClassTransformer.java @@ -141,9 +141,9 @@ public class TestableClassTransformer implements ClassFileTransformer { if (null == className || className.contains(CGLIB_CLASS_PATTERN)) { return true; } - String whitePrefix = GlobalConfig.getPkgPrefix(); - if (whitePrefix != null) { - for (String prefix : whitePrefix.split(COMMA)) { + List whitePrefixes = GlobalConfig.getPkgPrefixes(); + if (!whitePrefixes.isEmpty()) { + for (String prefix : whitePrefixes) { if (className.startsWith(prefix)) { // Only consider package in provided list as non-system class return false;