From a3369378ad07499805e9f9e93349ac56ce0772b7 Mon Sep 17 00:00:00 2001 From: Bo Zhang Date: Fri, 15 Mar 2019 09:24:39 +0800 Subject: [PATCH] Apply Alibaba p3c pmd plugin/rules and fix/ignore all violations of priority 1 (#574) --- .travis.yml | 4 ++ pom.xml | 40 +++++++++++++++++++ .../cluster/client/NettyTransportClient.java | 1 + .../server/connection/ConnectionPool.java | 1 + .../slots/block/degrade/DegradeRule.java | 1 + .../slots/block/flow/FlowRuleManager.java | 1 + .../slots/system/SystemRuleManager.java | 1 + .../dashboard/metric/MetricFetcher.java | 2 + .../dubbo/demo2/FooConsumerBootstrap.java | 1 + .../demo/rocketmq/PullConsumerDemo.java | 1 + .../spring/webflux/service/FooService.java | 1 + .../datasource/AutoRefreshDataSource.java | 1 + .../init/HeartbeatSenderInitFunc.java | 1 + .../command/NettyHttpCommandCenter.java | 1 + .../command/SimpleHttpCommandCenter.java | 1 + 15 files changed, 58 insertions(+) diff --git a/.travis.yml b/.travis.yml index 5c3f8970..0f940c4d 100755 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,10 @@ matrix: allow_failures: - env: BUILD_JDK=ORACLE_JDK_11 +# https://docs.travis-ci.com/user/languages/java/#maven-dependency-management +install: + - mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -DminimumPriority=1 + after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/pom.xml b/pom.xml index 7f321428..d6193397 100755 --- a/pom.xml +++ b/pom.xml @@ -186,6 +186,46 @@ + + org.apache.maven.plugins + maven-pmd-plugin + 3.8 + + ${project.build.sourceEncoding} + 1.8 + + **/*_jmhTest.java + + true + + rulesets/java/ali-comment.xml + rulesets/java/ali-concurrent.xml + rulesets/java/ali-constant.xml + rulesets/java/ali-exception.xml + rulesets/java/ali-flowcontrol.xml + rulesets/java/ali-naming.xml + rulesets/java/ali-oop.xml + rulesets/java/ali-orm.xml + rulesets/java/ali-other.xml + rulesets/java/ali-set.xml + + + + + verify + + check + + + + + + com.alibaba.p3c + p3c-pmd + 1.3.6 + + + org.apache.maven.plugins maven-compiler-plugin diff --git a/sentinel-cluster/sentinel-cluster-client-default/src/main/java/com/alibaba/csp/sentinel/cluster/client/NettyTransportClient.java b/sentinel-cluster/sentinel-cluster-client-default/src/main/java/com/alibaba/csp/sentinel/cluster/client/NettyTransportClient.java index 2492bfea..e2038b50 100644 --- a/sentinel-cluster/sentinel-cluster-client-default/src/main/java/com/alibaba/csp/sentinel/cluster/client/NettyTransportClient.java +++ b/sentinel-cluster/sentinel-cluster-client-default/src/main/java/com/alibaba/csp/sentinel/cluster/client/NettyTransportClient.java @@ -60,6 +60,7 @@ import io.netty.util.concurrent.GenericFutureListener; */ public class NettyTransportClient implements ClusterTransportClient { + @SuppressWarnings("PMD.ThreadPoolCreationRule") private static final ScheduledExecutorService SCHEDULER = Executors.newScheduledThreadPool(1, new NamedThreadFactory("sentinel-cluster-transport-client-scheduler")); diff --git a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionPool.java b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionPool.java index e1e320ce..ef01486f 100644 --- a/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionPool.java +++ b/sentinel-cluster/sentinel-cluster-server-default/src/main/java/com/alibaba/csp/sentinel/cluster/server/connection/ConnectionPool.java @@ -38,6 +38,7 @@ import io.netty.channel.Channel; */ public class ConnectionPool { + @SuppressWarnings("PMD.ThreadPoolCreationRule") private static final ScheduledExecutorService TIMER = Executors.newScheduledThreadPool(2); /** diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java index 1401281c..f29c42d1 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/DegradeRule.java @@ -57,6 +57,7 @@ public class DegradeRule extends AbstractRule { private static final int RT_MAX_EXCEED_N = 5; + @SuppressWarnings("PMD.ThreadPoolCreationRule") private static ScheduledExecutorService pool = Executors.newScheduledThreadPool( Runtime.getRuntime().availableProcessors(), new NamedThreadFactory("sentinel-degrade-reset-task", true)); diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java index 18885812..40d2f92a 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/flow/FlowRuleManager.java @@ -51,6 +51,7 @@ public class FlowRuleManager { private static final FlowPropertyListener LISTENER = new FlowPropertyListener(); private static SentinelProperty> currentProperty = new DynamicSentinelProperty>(); + @SuppressWarnings("PMD.ThreadPoolCreationRule") private static final ScheduledExecutorService SCHEDULER = Executors.newScheduledThreadPool(1, new NamedThreadFactory("sentinel-metrics-record-task", true)); diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java index 2e2fe635..99b93a93 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/system/SystemRuleManager.java @@ -88,6 +88,7 @@ public class SystemRuleManager { private final static SystemPropertyListener listener = new SystemPropertyListener(); private static SentinelProperty> currentProperty = new DynamicSentinelProperty>(); + @SuppressWarnings("PMD.ThreadPoolCreationRule") private final static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("sentinel-system-status-record-task", true)); diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/metric/MetricFetcher.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/metric/MetricFetcher.java index 2cce06e2..43fe4113 100755 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/metric/MetricFetcher.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/metric/MetricFetcher.java @@ -84,6 +84,8 @@ public class MetricFetcher { private AppManagement appManagement; private CloseableHttpAsyncClient httpclient; + + @SuppressWarnings("PMD.ThreadPoolCreationRule") private ScheduledExecutorService fetchScheduleService = Executors.newScheduledThreadPool(1, new NamedThreadFactory("sentinel-dashboard-metrics-fetch-task")); private ExecutorService fetchService; diff --git a/sentinel-demo/sentinel-demo-dubbo/src/main/java/com/alibaba/csp/sentinel/demo/dubbo/demo2/FooConsumerBootstrap.java b/sentinel-demo/sentinel-demo-dubbo/src/main/java/com/alibaba/csp/sentinel/demo/dubbo/demo2/FooConsumerBootstrap.java index 2eb717d5..19938513 100644 --- a/sentinel-demo/sentinel-demo-dubbo/src/main/java/com/alibaba/csp/sentinel/demo/dubbo/demo2/FooConsumerBootstrap.java +++ b/sentinel-demo/sentinel-demo-dubbo/src/main/java/com/alibaba/csp/sentinel/demo/dubbo/demo2/FooConsumerBootstrap.java @@ -48,6 +48,7 @@ public class FooConsumerBootstrap { private static final String RES_KEY = "com.alibaba.csp.sentinel.demo.dubbo.FooService:sayHello(java.lang.String)"; private static final String INTERFACE_RES_KEY = "com.alibaba.csp.sentinel.demo.dubbo.FooService"; + @SuppressWarnings("PMD.ThreadPoolCreationRule") private static final ExecutorService pool = Executors.newFixedThreadPool(10, new NamedThreadFactory("dubbo-consumer-pool")); diff --git a/sentinel-demo/sentinel-demo-rocketmq/src/main/java/com/alibaba/csp/sentinel/demo/rocketmq/PullConsumerDemo.java b/sentinel-demo/sentinel-demo-rocketmq/src/main/java/com/alibaba/csp/sentinel/demo/rocketmq/PullConsumerDemo.java index fd1d0d1d..6435aca5 100755 --- a/sentinel-demo/sentinel-demo-rocketmq/src/main/java/com/alibaba/csp/sentinel/demo/rocketmq/PullConsumerDemo.java +++ b/sentinel-demo/sentinel-demo-rocketmq/src/main/java/com/alibaba/csp/sentinel/demo/rocketmq/PullConsumerDemo.java @@ -44,6 +44,7 @@ public class PullConsumerDemo { private static final Map OFFSET_TABLE = new HashMap(); + @SuppressWarnings("PMD.ThreadPoolCreationRule") private static final ExecutorService pool = Executors.newFixedThreadPool(32); private static final AtomicLong SUCCESS_COUNT = new AtomicLong(0); diff --git a/sentinel-demo/sentinel-demo-spring-webflux/src/main/java/com/alibaba/csp/sentinel/demo/spring/webflux/service/FooService.java b/sentinel-demo/sentinel-demo-spring-webflux/src/main/java/com/alibaba/csp/sentinel/demo/spring/webflux/service/FooService.java index 699d2c2e..6b3dafe1 100644 --- a/sentinel-demo/sentinel-demo-spring-webflux/src/main/java/com/alibaba/csp/sentinel/demo/spring/webflux/service/FooService.java +++ b/sentinel-demo/sentinel-demo-spring-webflux/src/main/java/com/alibaba/csp/sentinel/demo/spring/webflux/service/FooService.java @@ -31,6 +31,7 @@ import reactor.core.scheduler.Schedulers; @Service public class FooService { + @SuppressWarnings("PMD.ThreadPoolCreationRule") private final ExecutorService pool = Executors.newFixedThreadPool(8); private final Scheduler scheduler = Schedulers.fromExecutor(pool); diff --git a/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/AutoRefreshDataSource.java b/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/AutoRefreshDataSource.java index f2a8ab3e..5a917a5e 100755 --- a/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/AutoRefreshDataSource.java +++ b/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/AutoRefreshDataSource.java @@ -48,6 +48,7 @@ public abstract class AutoRefreshDataSource extends AbstractDataSource handlerMap = new ConcurrentHashMap(); + @SuppressWarnings("PMD.ThreadPoolCreationRule") private ExecutorService executor = Executors.newSingleThreadExecutor( new NamedThreadFactory("sentinel-command-center-executor")); private ExecutorService bizExecutor;