Skip to content

Commit

Permalink
(feature) add pmd plugin fix #63 (#69)
Browse files Browse the repository at this point in the history
add pmd plugin and fix
  • Loading branch information
xmtsui committed Jul 6, 2018
1 parent 1c0a005 commit d385b61
Show file tree
Hide file tree
Showing 41 changed files with 224 additions and 103 deletions.
40 changes: 40 additions & 0 deletions .middleware-common/pmd_rule_set.xml
@@ -0,0 +1,40 @@
<?xml version="1.0"?>

<ruleset name="PMD-Rules">
<description>
customize rule set priority
</description>
<rule ref="rulesets/java/empty.xml/EmptyCatchBlock">
<priority>1</priority>
</rule>
<rule ref="rulesets/java/empty.xml/EmptyIfStmt">
<priority>1</priority>
</rule>
<rule ref="rulesets/java/basic.xml/OverrideBothEqualsAndHashcode">
<priority>1</priority>
</rule>
<rule ref="rulesets/java/clone.xml/CloneMethodMustImplementCloneable">
<priority>1</priority>
</rule>
<rule ref="rulesets/java/imports.xml/DuplicateImports">
<priority>1</priority>
</rule>
<rule ref="rulesets/java/imports.xml/UnusedImports">
<priority>1</priority>
</rule>
<rule ref="rulesets/java/strings.xml/StringToString">
<priority>1</priority>
</rule>
<rule ref="rulesets/java/unusedcode.xml/UnusedLocalVariable">
<priority>1</priority>
</rule>
<rule ref="rulesets/java/unusedcode.xml/UnusedPrivateField">
<priority>1</priority>
</rule>
<rule ref="rulesets/java/unusedcode.xml/UnusedPrivateMethod">
<priority>1</priority>
</rule>
<rule ref="rulesets/java/unusedcode.xml/UnusedFormalParameter">
<priority>1</priority>
</rule>
</ruleset>
56 changes: 56 additions & 0 deletions pom.xml
Expand Up @@ -79,6 +79,7 @@
<maven.staging.plugin>1.6.7</maven.staging.plugin>
<maven.surefire.plugin>2.18.1</maven.surefire.plugin>
<netty.version>4.1.25.Final</netty.version>

<project.encoding>UTF-8</project.encoding>
<slf4j.version>1.7.21</slf4j.version>
<sofa.common.tools>1.0.12</sofa.common.tools>
Expand Down Expand Up @@ -389,5 +390,60 @@
<additionalparam>-Xdoclint:none</additionalparam>
</properties>
</profile>
<profile>
<id>jdk7+</id>
<activation>
<jdk>[1.7,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.alibaba.p3c</groupId>
<artifactId>p3c-pmd</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
<configuration>
<failOnViolation>true</failOnViolation>
<!-- only fail on block issues -->
<failurePriority>1</failurePriority>
<excludes>
<exclude>src/test/java/**</exclude>
</excludes>
<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>
<ruleset>rulesets/java/basic.xml</ruleset>
<ruleset>rulesets/java/empty.xml</ruleset>
<ruleset>rulesets/java/imports.xml</ruleset>
<ruleset>rulesets/java/unusedcode.xml</ruleset>
<ruleset>${project.basedir}/.middleware-common/pmd_rule_set.xml</ruleset>
</rulesets>
<printFailingErrors>true</printFailingErrors>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Expand Up @@ -100,6 +100,7 @@ public void process(RemotingContext ctx, T msg, ExecutorService defaultExecutor)
*
* @return property value of executor
*/
@Override
public ExecutorService getExecutor() {
return executor;
}
Expand All @@ -109,6 +110,7 @@ public ExecutorService getExecutor() {
*
* @param executor value to be assigned to property executor
*/
@Override
public void setExecutor(ExecutorService executor) {
this.executor = executor;
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/alipay/remoting/AbstractRemotingServer.java
Expand Up @@ -16,12 +16,13 @@
*/
package com.alipay.remoting;

import com.alipay.remoting.log.BoltLoggerFactory;
import org.slf4j.Logger;

import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicBoolean;

import org.slf4j.Logger;

import com.alipay.remoting.log.BoltLoggerFactory;

/**
* Server template for remoting.
*
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/alipay/remoting/CommonCommandCode.java
Expand Up @@ -32,6 +32,7 @@ private CommonCommandCode(short value) {
this.value = value;
}

@Override
public short value() {
return this.value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/alipay/remoting/Connection.java
Expand Up @@ -19,8 +19,8 @@
import java.net.InetSocketAddress;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/alipay/remoting/ConnectionEventHandler.java
Expand Up @@ -22,18 +22,18 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.alipay.remoting.util.GlobalSwitch;
import org.slf4j.Logger;

import com.alipay.remoting.log.BoltLoggerFactory;
import com.alipay.remoting.util.GlobalSwitch;
import com.alipay.remoting.util.RemotingUtil;
import com.alipay.remoting.util.StringUtils;

import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.util.Attribute;

/**
Expand Down
Expand Up @@ -224,6 +224,7 @@ public DefaultConnectionManager(ConnectionSelectStrategy connectionSelectStrateg
/**
* @see com.alipay.remoting.ConnectionManager#init()
*/
@Override
public void init() {
this.connectionEventHandler.setConnectionManager(this);
this.connectionEventHandler.setConnectionEventListener(connectionEventListener);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/alipay/remoting/NamedThreadFactory.java
Expand Up @@ -53,6 +53,7 @@ public NamedThreadFactory(String preffix, boolean daemon) {
*
* @see java.util.concurrent.ThreadFactory#newThread(java.lang.Runnable)
*/
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0);
t.setDaemon(isDaemon);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/alipay/remoting/ProtocolCode.java
Expand Up @@ -51,10 +51,12 @@ public int length() {

@Override
public boolean equals(Object o) {
if (this == o)
if (this == o) {
return true;
if (o == null || getClass() != o.getClass())
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ProtocolCode that = (ProtocolCode) o;
return Arrays.equals(version, that.version);
}
Expand Down
Expand Up @@ -20,10 +20,10 @@
import java.util.List;
import java.util.Random;

import com.alipay.remoting.util.GlobalSwitch;
import org.slf4j.Logger;

import com.alipay.remoting.log.BoltLoggerFactory;
import com.alipay.remoting.util.GlobalSwitch;
import com.alipay.remoting.util.StringUtils;

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/alipay/remoting/ReconnectManager.java
Expand Up @@ -115,6 +115,7 @@ public void stop() {
private final class HealConnectionRunner implements Runnable {
private long lastConnectTime = -1;

@Override
public void run() {
while (ReconnectManager.this.started) {
long start = -1;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/alipay/remoting/RemotingServer.java
Expand Up @@ -16,11 +16,10 @@
*/
package com.alipay.remoting;

import com.alipay.remoting.rpc.protocol.MultiInterestUserProcessor;
import com.alipay.remoting.rpc.protocol.UserProcessor;

import java.util.concurrent.ExecutorService;

import com.alipay.remoting.rpc.protocol.UserProcessor;

/**
* @author chengyi (mark.lx@antfin.com) 2018-06-16 06:55
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/alipay/remoting/ServerIdleHandler.java
Expand Up @@ -22,8 +22,8 @@
import com.alipay.remoting.util.RemotingUtil;

import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleStateEvent;

/**
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/alipay/remoting/SystemProperties.java
Expand Up @@ -16,8 +16,6 @@
*/
package com.alipay.remoting;

import io.netty.channel.epoll.EpollMode;

/**
* get configs from system properties
*
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/alipay/remoting/Url.java
Expand Up @@ -224,12 +224,15 @@ public Properties getProperties() {

@Override
public final boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
Url url = (Url) obj;
if (this.getOriginUrl().equals(url.getOriginUrl())) {
return true;
Expand Down
Expand Up @@ -16,6 +16,11 @@
*/
package com.alipay.remoting.connection;

import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;

import com.alipay.remoting.Connection;
import com.alipay.remoting.ConnectionEventHandler;
import com.alipay.remoting.ConnectionEventType;
Expand All @@ -28,6 +33,7 @@
import com.alipay.remoting.rpc.protocol.RpcProtocol;
import com.alipay.remoting.rpc.protocol.RpcProtocolV2;
import com.alipay.remoting.util.NettyEventLoopUtil;

import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.UnpooledByteBufAllocator;
Expand All @@ -39,14 +45,8 @@
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.WriteBufferWaterMark;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.timeout.IdleStateHandler;
import org.slf4j.Logger;

import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;

/**
* ConnectionFactory to create connection.
Expand Down Expand Up @@ -106,6 +106,7 @@ public void init(final ConnectionEventHandler connectionEventHandler) {

bootstrap.handler(new ChannelInitializer<SocketChannel>() {

@Override
protected void initChannel(SocketChannel channel) {
ChannelPipeline pipeline = channel.pipeline();
pipeline.addLast("decoder", codec.newDecoder());
Expand Down
Expand Up @@ -18,6 +18,7 @@

import com.alipay.remoting.NamedThreadFactory;
import com.alipay.remoting.codec.Codec;

import io.netty.channel.ChannelHandler;

/**
Expand Down
Expand Up @@ -248,7 +248,7 @@ public void tryAsyncExecuteInvokeCallbackAbnormally() {
CommandHandler commandHandler = protocol.getCommandHandler();
if (null != commandHandler) {
ExecutorService executor = commandHandler.getDefaultExecutor();
if (null != executor)
if (null != executor) {
executor.execute(new Runnable() {
@Override
public void run() {
Expand All @@ -269,6 +269,7 @@ public void run() {
}
}
});
}
} else {
logger.error("Executor null in commandHandler of protocolCode [{}].",
this.protocol);
Expand Down
Expand Up @@ -22,8 +22,8 @@
import com.alipay.remoting.ProtocolManager;

import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleStateEvent;

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/alipay/remoting/rpc/RpcAddressParser.java
Expand Up @@ -51,6 +51,7 @@ public class RpcAddressParser implements RemotingAddressParser {
/**
* @see com.alipay.remoting.RemotingAddressParser#parse(java.lang.String)
*/
@Override
public Url parse(String url) {
if (StringUtils.isBlank(url)) {
throw new IllegalArgumentException("Illegal format address string [" + url
Expand Down Expand Up @@ -155,6 +156,7 @@ public Url parse(String url) {
/**
* @see com.alipay.remoting.RemotingAddressParser#parseUniqueKey(java.lang.String)
*/
@Override
public String parseUniqueKey(String url) {
boolean illegal = false;
if (StringUtils.isBlank(url)) {
Expand Down Expand Up @@ -197,6 +199,7 @@ public String parseProperty(String addr, String propKey) {
/**
* @see com.alipay.remoting.RemotingAddressParser#initUrlArgs(Url)
*/
@Override
public void initUrlArgs(Url url) {
String connTimeoutStr = url.getProperty(RpcConfigs.CONNECT_TIMEOUT_KEY);
int connTimeout = Configs.DEFAULT_CONNECT_TIMEOUT;
Expand Down

0 comments on commit d385b61

Please sign in to comment.