Skip to content

命令行处理类名时,自动替换/为. #3017

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class JadCommand extends AnnotatedCommand {
@Argument(argName = "class-pattern", index = 0)
@Description("Class name pattern, use either '.' or '/' as separator")
public void setClassPattern(String classPattern) {
this.classPattern = classPattern;
this.classPattern = StringUtils.normalizeClassName(classPattern);
}

@Argument(argName = "method-name", index = 1, required = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class SearchClassCommand extends AnnotatedCommand {
@Argument(argName = "class-pattern", index = 0)
@Description("Class name pattern, use either '.' or '/' as separator")
public void setClassPattern(String classPattern) {
this.classPattern = classPattern;
this.classPattern = StringUtils.normalizeClassName(classPattern);
}

@Option(shortName = "d", longName = "details", flag = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.taobao.arthas.core.shell.command.CommandProcess;
import com.taobao.arthas.core.shell.handlers.Handler;
import com.taobao.arthas.core.util.SearchUtils;
import com.taobao.arthas.core.util.StringUtils;
import com.taobao.arthas.core.util.matcher.Matcher;
import com.taobao.middleware.cli.annotations.Argument;
import com.taobao.middleware.cli.annotations.Description;
Expand Down Expand Up @@ -40,7 +41,7 @@ public class MonitorCommand extends EnhancerCommand {
@Argument(argName = "class-pattern", index = 0)
@Description("Path and classname of Pattern Matching")
public void setClassPattern(String classPattern) {
this.classPattern = classPattern;
this.classPattern = StringUtils.normalizeClassName(classPattern);
}

@Argument(argName = "method-pattern", index = 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.taobao.arthas.core.command.Constants;
import com.taobao.arthas.core.shell.command.CommandProcess;
import com.taobao.arthas.core.util.SearchUtils;
import com.taobao.arthas.core.util.StringUtils;
import com.taobao.arthas.core.util.matcher.GroupMatcher;
import com.taobao.arthas.core.util.matcher.Matcher;
import com.taobao.arthas.core.util.matcher.RegexMatcher;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class TraceCommand extends EnhancerCommand {
@Argument(argName = "class-pattern", index = 0)
@Description("Class name pattern, use either '.' or '/' as separator")
public void setClassPattern(String classPattern) {
this.classPattern = classPattern;
this.classPattern = StringUtils.normalizeClassName(classPattern);
}

@Argument(argName = "method-pattern", index = 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.taobao.arthas.core.shell.cli.CompletionUtils;
import com.taobao.arthas.core.shell.command.CommandProcess;
import com.taobao.arthas.core.util.SearchUtils;
import com.taobao.arthas.core.util.StringUtils;
import com.taobao.arthas.core.util.matcher.Matcher;
import com.taobao.arthas.core.view.ObjectView;
import com.taobao.middleware.cli.annotations.Argument;
Expand Down Expand Up @@ -49,7 +50,7 @@ public class WatchCommand extends EnhancerCommand {
@Argument(index = 0, argName = "class-pattern")
@Description("The full qualified class name you want to watch")
public void setClassPattern(String classPattern) {
this.classPattern = classPattern;
this.classPattern = StringUtils.normalizeClassName(classPattern);
}

@Argument(index = 1, argName = "method-pattern")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,4 +412,21 @@ public void testWrap() {
public void testClassLoaderHash() {
Assert.assertEquals("null", StringUtils.classLoaderHash(null));
}

@Test
public void testNormalizeNull() {
Assert.assertNull(StringUtils.normalizeClassName(null));
}

@Test
public void testNormalizeNoSlash() {
String input = "com.example.Class";
Assert.assertEquals(input, StringUtils.normalizeClassName(input));
}

@Test
public void testNormalizeWithSlash() {
String input = "com/example/Class";
Assert.assertEquals("com.example.Class", StringUtils.normalizeClassName(input));
}
}