mirror of
https://github.com/alibaba/arthas.git
synced 2026-11-30 15:33:59 +00:00
Apply pmd plugin and fix/ignore broken styles
This commit applies [p3c-pmd](https://github.com/alibaba/p3c) plugin/rules, and fixes/ignores all violations of piority 1 (mandatory).
This commit is contained in:
1 parent
17c42f3e9a
commit
ae67e7ed2c
13 files changed
+74
-15
No files matched your search
+1
-1
@@ -18,7 +18,7 @@ cache:
|
|||||||
- "$HOME/.m2/repository"
|
- "$HOME/.m2/repository"
|
||||||
- "$HOME/.m2/wrapper"
|
- "$HOME/.m2/wrapper"
|
||||||
script:
|
script:
|
||||||
- ./mvnw clean cobertura:cobertura package -P full -Dsphinx.binUrl=https://github.com/hengyunabc/sphinx-binary/releases/download/v0.4.0.1/sphinx.linux-x86_64
|
- ./mvnw clean cobertura:cobertura package -P full -Dsphinx.binUrl=https://github.com/hengyunabc/sphinx-binary/releases/download/v0.4.0.1/sphinx.linux-x86_64 -DminimumPriority=1
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
- bash <(curl -s https://codecov.io/bash)
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import java.util.TimerTask;
|
|||||||
" dashboard -n 10\n" +
|
" dashboard -n 10\n" +
|
||||||
" dashboard -i 2000\n" +
|
" dashboard -i 2000\n" +
|
||||||
Constants.WIKI + Constants.WIKI_HOME + "dashboard")
|
Constants.WIKI + Constants.WIKI_HOME + "dashboard")
|
||||||
|
@SuppressWarnings("PMD.AvoidUseTimerRule")
|
||||||
public class DashboardCommand extends AnnotatedCommand {
|
public class DashboardCommand extends AnnotatedCommand {
|
||||||
|
|
||||||
private static final Logger logger = LogUtil.getArthasLogger();
|
private static final Logger logger = LogUtil.getArthasLogger();
|
||||||
|
|||||||
+1
@@ -8,6 +8,7 @@ import java.util.Timer;
|
|||||||
/**
|
/**
|
||||||
* @author ralf0131 2017-01-09 13:37.
|
* @author ralf0131 2017-01-09 13:37.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("PMD.AvoidUseTimerRule")
|
||||||
public class DashboardInterruptHandler extends CommandInterruptHandler {
|
public class DashboardInterruptHandler extends CommandInterruptHandler {
|
||||||
|
|
||||||
private volatile Timer timer;
|
private volatile Timer timer;
|
||||||
|
|||||||
+1
@@ -66,6 +66,7 @@ import static com.taobao.text.ui.Element.label;
|
|||||||
*
|
*
|
||||||
* @author beiwei30 on 28/11/2016.
|
* @author beiwei30 on 28/11/2016.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("PMD.AvoidUseTimerRule")
|
||||||
class MonitorAdviceListener extends ReflectAdviceListenerAdapter {
|
class MonitorAdviceListener extends ReflectAdviceListenerAdapter {
|
||||||
// 输出定时任务
|
// 输出定时任务
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ public class ArthasBootstrap {
|
|||||||
private ShellServer shellServer;
|
private ShellServer shellServer;
|
||||||
private ExecutorService executorService;
|
private ExecutorService executorService;
|
||||||
|
|
||||||
|
@SuppressWarnings("PMD.ThreadPoolCreationRule")
|
||||||
private ArthasBootstrap(int pid, Instrumentation instrumentation) {
|
private ArthasBootstrap(int pid, Instrumentation instrumentation) {
|
||||||
this.pid = pid;
|
this.pid = pid;
|
||||||
this.instrumentation = instrumentation;
|
this.instrumentation = instrumentation;
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ public class ShellServerImpl extends ShellServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("PMD.ThreadPoolCreationRule")
|
||||||
public synchronized void setTimer() {
|
public synchronized void setTimer() {
|
||||||
if (!closed && reaperInterval > 0) {
|
if (!closed && reaperInterval > 0) {
|
||||||
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
|
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ import com.taobao.middleware.logger.Logger;
|
|||||||
* @author gehui 2017年7月31日 上午11:55:41
|
* @author gehui 2017年7月31日 上午11:55:41
|
||||||
*/
|
*/
|
||||||
public class GlobalJobControllerImpl extends JobControllerImpl {
|
public class GlobalJobControllerImpl extends JobControllerImpl {
|
||||||
|
@SuppressWarnings("PMD.AvoidUseTimerRule")
|
||||||
private Timer timer = new Timer("job-timeout", true);
|
private Timer timer = new Timer("job-timeout", true);
|
||||||
private Map<Integer, TimerTask> jobTimeoutTaskMap = new HashMap<Integer, TimerTask>();
|
private Map<Integer, TimerTask> jobTimeoutTaskMap = new HashMap<Integer, TimerTask>();
|
||||||
private static final Logger logger = LogUtil.getArthasLogger();
|
private static final Logger logger = LogUtil.getArthasLogger();
|
||||||
|
|||||||
@@ -85,14 +85,16 @@ public class Decompiler {
|
|||||||
path = classFileSource.adjustInputPath(path);
|
path = classFileSource.adjustInputPath(path);
|
||||||
|
|
||||||
AnalysisType type = (AnalysisType) options.getOption(OptionsImpl.ANALYSE_AS);
|
AnalysisType type = (AnalysisType) options.getOption(OptionsImpl.ANALYSE_AS);
|
||||||
if (type == null)
|
if (type == null) {
|
||||||
type = dcCommonState.detectClsJar(path);
|
type = dcCommonState.detectClsJar(path);
|
||||||
|
}
|
||||||
|
|
||||||
if (type == AnalysisType.JAR) {
|
if (type == AnalysisType.JAR) {
|
||||||
// doJar(dcCommonState, path, dumperFactory);
|
// doJar(dcCommonState, path, dumperFactory);
|
||||||
}
|
}
|
||||||
if (type == AnalysisType.CLASS)
|
if (type == AnalysisType.CLASS) {
|
||||||
result.append(doClass(dcCommonState, path, skipInnerClass, dumperFactory));
|
result.append(doClass(dcCommonState, path, skipInnerClass, dumperFactory));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
@@ -105,8 +107,9 @@ public class Decompiler {
|
|||||||
Dumper d = new ToStringDumper();
|
Dumper d = new ToStringDumper();
|
||||||
try {
|
try {
|
||||||
ClassFile c = dcCommonState.getClassFileMaybePath(path);
|
ClassFile c = dcCommonState.getClassFileMaybePath(path);
|
||||||
if ((skipInnerClass) && (c.isInnerClass()))
|
if ((skipInnerClass) && (c.isInnerClass())) {
|
||||||
return "";
|
return "";
|
||||||
|
}
|
||||||
dcCommonState.configureWith(c);
|
dcCommonState.configureWith(c);
|
||||||
dumperFactory.getProgressDumper().analysingType(c.getClassType());
|
dumperFactory.getProgressDumper().analysingType(c.getClassType());
|
||||||
try {
|
try {
|
||||||
@@ -132,12 +135,14 @@ public class Decompiler {
|
|||||||
// collectingDumper.getTypeUsageInformation(), illegalIdentifierDump);
|
// collectingDumper.getTypeUsageInformation(), illegalIdentifierDump);
|
||||||
|
|
||||||
String methname = (String) options.getOption(OptionsImpl.METHODNAME);
|
String methname = (String) options.getOption(OptionsImpl.METHODNAME);
|
||||||
if (methname == null)
|
if (methname == null) {
|
||||||
c.dump(d);
|
c.dump(d);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
for (Method method : c.getMethodByName(methname))
|
for (Method method : c.getMethodByName(methname)) {
|
||||||
method.dump(d, true);
|
method.dump(d, true);
|
||||||
|
}
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
throw new IllegalArgumentException("No such method '" + methname + "'.");
|
throw new IllegalArgumentException("No such method '" + methname + "'.");
|
||||||
}
|
}
|
||||||
@@ -146,18 +151,21 @@ public class Decompiler {
|
|||||||
result.append(d.toString());
|
result.append(d.toString());
|
||||||
} catch (ConfusedCFRException e) {
|
} catch (ConfusedCFRException e) {
|
||||||
result.append(e.toString()).append("\n");
|
result.append(e.toString()).append("\n");
|
||||||
for (Object x : e.getStackTrace())
|
for (Object x : e.getStackTrace()) {
|
||||||
result.append(x).append("\n");
|
result.append(x).append("\n");
|
||||||
|
}
|
||||||
} catch (CannotLoadClassException e) {
|
} catch (CannotLoadClassException e) {
|
||||||
result.append("Can't load the class specified:").append("\n");
|
result.append("Can't load the class specified:").append("\n");
|
||||||
result.append(e.toString()).append("\n");
|
result.append(e.toString()).append("\n");
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
result.append(e.toString()).append("\n");
|
result.append(e.toString()).append("\n");
|
||||||
for (Object x : e.getStackTrace())
|
for (Object x : e.getStackTrace()) {
|
||||||
result.append(x).append("\n");
|
result.append(x).append("\n");
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (d != null)
|
if (d != null) {
|
||||||
d.close();
|
d.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,12 +191,13 @@ public class NetUtils {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
if (s != null)
|
if (s != null) {
|
||||||
try {
|
try {
|
||||||
s.close();
|
s.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -871,7 +871,9 @@ public abstract class StringUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String classLoaderHash(Class<?> clazz) {
|
public static String classLoaderHash(Class<?> clazz) {
|
||||||
if (clazz == null || clazz.getClassLoader() == null) return "null";
|
if (clazz == null || clazz.getClassLoader() == null) {
|
||||||
|
return "null";
|
||||||
|
}
|
||||||
return Integer.toHexString(clazz.getClassLoader().hashCode());
|
return Integer.toHexString(clazz.getClassLoader().hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -881,7 +883,9 @@ public abstract class StringUtils {
|
|||||||
* @return human readable format
|
* @return human readable format
|
||||||
*/
|
*/
|
||||||
public static String humanReadableByteCount(long bytes) {
|
public static String humanReadableByteCount(long bytes) {
|
||||||
if (bytes < UNIT) return bytes + " B";
|
if (bytes < UNIT) {
|
||||||
|
return bytes + " B";
|
||||||
|
}
|
||||||
int exp = (int) (Math.log(bytes) / Math.log(UNIT));
|
int exp = (int) (Math.log(bytes) / Math.log(UNIT));
|
||||||
String pre = STRING_UNITS.charAt(exp-1) + "i";
|
String pre = STRING_UNITS.charAt(exp-1) + "i";
|
||||||
return String.format("%.2f %sB", bytes / Math.pow(UNIT, exp), pre);
|
return String.format("%.2f %sB", bytes / Math.pow(UNIT, exp), pre);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import java.util.concurrent.Executors;
|
|||||||
* Created by zhuyong on 15/11/12.
|
* Created by zhuyong on 15/11/12.
|
||||||
*/
|
*/
|
||||||
public class UserStatUtil {
|
public class UserStatUtil {
|
||||||
|
@SuppressWarnings("PMD.ThreadPoolCreationRule")
|
||||||
private static final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
private static final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||||
private static final String ip = IPUtils.getLocalIP();
|
private static final String ip = IPUtils.getLocalIP();
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,9 @@ public class Ansi {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public static void setDetector(final Callable<Boolean> detector) {
|
public static void setDetector(final Callable<Boolean> detector) {
|
||||||
if (detector == null) throw new IllegalArgumentException();
|
if (detector == null) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
Ansi.detector = detector;
|
Ansi.detector = detector;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -698,8 +700,9 @@ public class Ansi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void flushAttributes() {
|
private void flushAttributes() {
|
||||||
if (attributeOptions.isEmpty())
|
if (attributeOptions.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
if (attributeOptions.size() == 1 && attributeOptions.get(0) == 0) {
|
if (attributeOptions.size() == 1 && attributeOptions.get(0) == 0) {
|
||||||
builder.append(FIRST_ESC_CHAR);
|
builder.append(FIRST_ESC_CHAR);
|
||||||
builder.append(SECOND_ESC_CHAR);
|
builder.append(SECOND_ESC_CHAR);
|
||||||
|
|||||||
@@ -195,6 +195,43 @@
|
|||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-pmd-plugin</artifactId>
|
||||||
|
<version>3.8</version>
|
||||||
|
<configuration>
|
||||||
|
<sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
|
||||||
|
<targetJdk>1.8</targetJdk>
|
||||||
|
<printFailingErrors>true</printFailingErrors>
|
||||||
|
<rulesets>
|
||||||
|
<ruleset>rulesets/java/ali-comment.xml</ruleset>
|
||||||
|
<ruleset>rulesets/java/ali-concurrent.xml</ruleset>
|
||||||
|
<ruleset>rulesets/java/ali-constant.xml</ruleset>
|
||||||
|
<ruleset>rulesets/java/ali-exception.xml</ruleset>
|
||||||
|
<ruleset>rulesets/java/ali-flowcontrol.xml</ruleset>
|
||||||
|
<ruleset>rulesets/java/ali-naming.xml</ruleset>
|
||||||
|
<ruleset>rulesets/java/ali-oop.xml</ruleset>
|
||||||
|
<ruleset>rulesets/java/ali-orm.xml</ruleset>
|
||||||
|
<ruleset>rulesets/java/ali-other.xml</ruleset>
|
||||||
|
<ruleset>rulesets/java/ali-set.xml</ruleset>
|
||||||
|
</rulesets>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.p3c</groupId>
|
||||||
|
<artifactId>p3c-pmd</artifactId>
|
||||||
|
<version>1.3.6</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
|||||||
Reference in new issue
Block a user