Skip to content
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

sort sc command ouput #234

Merged
merged 1 commit into from
Oct 17, 2018
Merged
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
@@ -1,5 +1,15 @@
package com.taobao.arthas.core.command.klass100;

import static com.taobao.text.ui.Element.label;

import java.lang.instrument.Instrumentation;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;

import com.taobao.arthas.core.command.Constants;
import com.taobao.arthas.core.shell.command.AnnotatedCommand;
import com.taobao.arthas.core.shell.command.CommandProcess;
Expand All @@ -17,12 +27,6 @@
import com.taobao.text.ui.TableElement;
import com.taobao.text.util.RenderUtil;

import java.lang.instrument.Instrumentation;
import java.security.CodeSource;
import java.util.Set;

import static com.taobao.text.ui.Element.label;

/**
* 展示类信息
*
Expand All @@ -43,6 +47,14 @@ public class SearchClassCommand extends AnnotatedCommand {
private boolean isRegEx = false;
private Integer expand;

public static String getCodeSource(final CodeSource cs) {
if (null == cs || null == cs.getLocation() || null == cs.getLocation().getFile()) {
return com.taobao.arthas.core.util.Constants.EMPTY_STRING;
}

return cs.getLocation().getFile();
}

@Argument(argName = "class-pattern", index = 0)
@Description("Class name pattern, use either '.' or '/' as separator")
public void setClassPattern(String classPattern) {
Expand Down Expand Up @@ -78,7 +90,13 @@ public void process(CommandProcess process) {
// TODO: null check
RowAffect affect = new RowAffect();
Instrumentation inst = process.session().getInstrumentation();
Set<Class<?>> matchedClasses = SearchUtils.searchClass(inst, classPattern, isRegEx);
List<Class<?>> matchedClasses = new ArrayList(SearchUtils.searchClass(inst, classPattern, isRegEx));
Collections.sort(matchedClasses, new Comparator() {
@Override
public int compare(Object o1, Object o2) {
return StringUtils.classname((Class) o1).compareTo(StringUtils.classname((Class) o2));
}
});

for (Class<?> clazz : matchedClasses) {
processClass(process, clazz);
Expand Down Expand Up @@ -127,12 +145,4 @@ private Element renderClassInfo(Class<?> clazz, boolean isPrintField) {
return table;
}

public static String getCodeSource(final CodeSource cs) {
if (null == cs || null == cs.getLocation() || null == cs.getLocation().getFile()) {
return com.taobao.arthas.core.util.Constants.EMPTY_STRING;
}

return cs.getLocation().getFile();
}

}