mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
clean up the code a little bit by following Uncle Bob's clean code guide (#785)
This commit is contained in:
@@ -44,13 +44,8 @@ public class DownloadUtils {
|
||||
*/
|
||||
public static String readMavenReleaseVersion(String mavenMetaData) {
|
||||
try {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(mavenMetaData.getBytes("UTF-8"));
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
Document document = dBuilder.parse(inputStream);
|
||||
|
||||
Document document = transformMavenMetaData(mavenMetaData);
|
||||
NodeList nodeList = document.getDocumentElement().getElementsByTagName("release");
|
||||
|
||||
return nodeList.item(0).getTextContent();
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
@@ -67,11 +62,7 @@ public class DownloadUtils {
|
||||
public static List<String> readAllMavenVersion(String mavenMetaData) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
try {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(mavenMetaData.getBytes("UTF-8"));
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
Document document = dBuilder.parse(inputStream);
|
||||
|
||||
Document document = transformMavenMetaData(mavenMetaData);
|
||||
NodeList nodeList = document.getDocumentElement().getElementsByTagName("version");
|
||||
int length = nodeList.getLength();
|
||||
for (int i = 0; i < length; ++i) {
|
||||
@@ -187,6 +178,20 @@ public class DownloadUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* transform the maven meta data which is in the format of String into document object.
|
||||
*
|
||||
* @param mavenMetaData
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private static Document transformMavenMetaData(String mavenMetaData) throws Exception {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(mavenMetaData.getBytes("UTF-8"));
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
return dBuilder.parse(inputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* support redirect
|
||||
*
|
||||
|
||||
@@ -8,43 +8,43 @@ import java.util.Properties;
|
||||
*
|
||||
*/
|
||||
public class JavaVersionUtils {
|
||||
private static final String versionPropName = "java.specification.version";
|
||||
private static final String javaVersionStr = System.getProperty(versionPropName);
|
||||
private static final float javaVersion = Float.parseFloat(javaVersionStr);
|
||||
private static final String VERSION_PROP_NAME = "java.specification.version";
|
||||
private static final String JAVA_VERSION_STR = System.getProperty(VERSION_PROP_NAME);
|
||||
private static final float JAVA_VERSION = Float.parseFloat(JAVA_VERSION_STR);
|
||||
|
||||
public static String javaVersionStr() {
|
||||
return javaVersionStr;
|
||||
return JAVA_VERSION_STR;
|
||||
}
|
||||
|
||||
public static String javaVersionStr(Properties props) {
|
||||
return (null != props) ? props.getProperty(versionPropName): null;
|
||||
return (null != props) ? props.getProperty(VERSION_PROP_NAME): null;
|
||||
}
|
||||
|
||||
public static float javaVersion() {
|
||||
return javaVersion;
|
||||
return JAVA_VERSION;
|
||||
}
|
||||
|
||||
public static boolean isJava6() {
|
||||
return javaVersionStr.equals("1.6");
|
||||
return JAVA_VERSION_STR.equals("1.6");
|
||||
}
|
||||
|
||||
public static boolean isJava7() {
|
||||
return javaVersionStr.equals("1.7");
|
||||
return JAVA_VERSION_STR.equals("1.7");
|
||||
}
|
||||
|
||||
public static boolean isJava8() {
|
||||
return javaVersionStr.equals("1.8");
|
||||
return JAVA_VERSION_STR.equals("1.8");
|
||||
}
|
||||
|
||||
public static boolean isJava9() {
|
||||
return javaVersionStr.equals("9");
|
||||
return JAVA_VERSION_STR.equals("9");
|
||||
}
|
||||
|
||||
public static boolean isLessThanJava9() {
|
||||
return javaVersion < 9.0f;
|
||||
return JAVA_VERSION < 9.0f;
|
||||
}
|
||||
|
||||
public static boolean isGreaterThanJava8() {
|
||||
return javaVersion > 1.8f;
|
||||
return JAVA_VERSION > 1.8f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,9 +110,9 @@ public class ClassLoaderCommand extends AnnotatedCommand {
|
||||
} else if (hashCode != null && this.loadClass != null) {
|
||||
processLoadClass(process, inst);
|
||||
} else if (hashCode != null) {
|
||||
processClassloader(process, inst);
|
||||
processClassLoader(process, inst);
|
||||
} else if (listClassLoader || isTree){
|
||||
processClassloaders(process, inst);
|
||||
processClassLoaders(process, inst);
|
||||
} else {
|
||||
processClassLoaderStats(process, inst);
|
||||
}
|
||||
@@ -152,7 +152,7 @@ public class ClassLoaderCommand extends AnnotatedCommand {
|
||||
process.end();
|
||||
}
|
||||
|
||||
private void processClassloaders(CommandProcess process, Instrumentation inst) {
|
||||
private void processClassLoaders(CommandProcess process, Instrumentation inst) {
|
||||
RowAffect affect = new RowAffect();
|
||||
List<ClassLoaderInfo> classLoaderInfos = includeReflectionClassLoader ? getAllClassLoaderInfo(inst) :
|
||||
getAllClassLoaderInfo(inst, new SunReflectionClassLoaderFilter());
|
||||
@@ -165,10 +165,10 @@ public class ClassLoaderCommand extends AnnotatedCommand {
|
||||
}
|
||||
|
||||
// 根据 hashCode 来打印URLClassLoader的urls
|
||||
private void processClassloader(CommandProcess process, Instrumentation inst) {
|
||||
private void processClassLoader(CommandProcess process, Instrumentation inst) {
|
||||
RowAffect affect = new RowAffect();
|
||||
|
||||
Set<ClassLoader> allClassLoader = getAllClassLoader(inst);
|
||||
Set<ClassLoader> allClassLoader = getAllClassLoaders(inst);
|
||||
for (ClassLoader cl : allClassLoader) {
|
||||
if (Integer.toHexString(cl.hashCode()).equals(hashCode)) {
|
||||
process.write(RenderUtil.render(renderClassLoaderUrls(cl), process.width()));
|
||||
@@ -184,7 +184,7 @@ public class ClassLoaderCommand extends AnnotatedCommand {
|
||||
private void processResources(CommandProcess process, Instrumentation inst) {
|
||||
RowAffect affect = new RowAffect();
|
||||
int rowCount = 0;
|
||||
Set<ClassLoader> allClassLoader = getAllClassLoader(inst);
|
||||
Set<ClassLoader> allClassLoader = getAllClassLoaders(inst);
|
||||
for (ClassLoader cl : allClassLoader) {
|
||||
if (Integer.toHexString(cl.hashCode()).equals(hashCode)) {
|
||||
TableElement table = new TableElement().leftCellPadding(1).rightCellPadding(1);
|
||||
@@ -209,7 +209,7 @@ public class ClassLoaderCommand extends AnnotatedCommand {
|
||||
|
||||
// Use ClassLoader to loadClass
|
||||
private void processLoadClass(CommandProcess process, Instrumentation inst) {
|
||||
Set<ClassLoader> allClassLoader = getAllClassLoader(inst);
|
||||
Set<ClassLoader> allClassLoader = getAllClassLoaders(inst);
|
||||
for (ClassLoader cl : allClassLoader) {
|
||||
if (Integer.toHexString(cl.hashCode()).equals(hashCode)) {
|
||||
try {
|
||||
@@ -382,7 +382,7 @@ public class ClassLoaderCommand extends AnnotatedCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private static Set<ClassLoader> getAllClassLoader(Instrumentation inst, Filter... filters) {
|
||||
private static Set<ClassLoader> getAllClassLoaders(Instrumentation inst, Filter... filters) {
|
||||
Set<ClassLoader> classLoaderSet = new HashSet<ClassLoader>();
|
||||
|
||||
for (Class<?> clazz : inst.getAllLoadedClasses()) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.taobao.arthas.core.command.klass100;
|
||||
|
||||
import com.taobao.arthas.core.advisor.Enhancer;
|
||||
import com.taobao.arthas.core.command.Constants;
|
||||
import com.taobao.arthas.core.shell.cli.Completion;
|
||||
import com.taobao.arthas.core.shell.cli.CompletionUtils;
|
||||
@@ -26,13 +25,12 @@ import com.taobao.text.ui.LabelElement;
|
||||
import com.taobao.text.ui.TableElement;
|
||||
import com.taobao.text.util.RenderUtil;
|
||||
|
||||
import static java.lang.System.arraycopy;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.lang.instrument.UnmodifiableClassException;
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.taobao.text.ui.Element.label;
|
||||
|
||||
Reference in New Issue
Block a user