Skip to content

Commit b3edce5

Browse files
committed
[v3.0]add check style and fix check style error
1 parent decac3e commit b3edce5

File tree

15 files changed

+529
-29
lines changed

15 files changed

+529
-29
lines changed

config/checkstyle.xml

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
4+
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
5+
<module name="Checker">
6+
7+
<module name="NewlineAtEndOfFile">
8+
<property name="lineSeparator" value="lf"/>
9+
</module>
10+
11+
<module name="RegexpSingleline">
12+
<!-- Checks that FIXME is not used in comments. TODO is preferred.
13+
-->
14+
<property name="format" value="((//.*)|(\*.*))FIXME"/>
15+
<property name="message"
16+
value='TODO is preferred to FIXME. e.g. "TODO(johndoe): Refactor when v2 is released."'/>
17+
</module>
18+
19+
<module name="RegexpSingleline">
20+
<!-- Checks that TODOs are named. (Actually, just that they are followed
21+
by an open paren.)
22+
-->
23+
<property name="format" value="((//.*)|(\*.*))TODO[^(]"/>
24+
<property name="message"
25+
value='All TODOs should be named. e.g. "TODO(johndoe): Refactor when v2 is released."'/>
26+
</module>
27+
28+
<module name="TreeWalker">
29+
<module name="LineLength">
30+
<!-- Checks if a line is too long. -->
31+
<property name="max" value="150" default="100"/>
32+
<property name="severity" value="error"/>
33+
</module>
34+
<module name="RedundantImport">
35+
<!-- Checks for redundant import statements. -->
36+
<property name="severity" value="error"/>
37+
</module>
38+
<!-- Item 38 - Adhere to generally accepted naming conventions -->
39+
40+
<module name="PackageName">
41+
<!-- Validates identifiers for package names against the
42+
supplied expression. -->
43+
<!-- Here the default checkstyle rule restricts package name parts to
44+
seven characters, this is not in line with common practice at Google.
45+
-->
46+
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]{1,})*$"/>
47+
<property name="severity" value="warning"/>
48+
</module>
49+
50+
<module name="TypeNameCheck">
51+
<!-- Validates static, final fields against the
52+
expression "^[A-Z][a-zA-Z0-9]*$". -->
53+
<metadata name="altname" value="TypeName"/>
54+
<property name="severity" value="warning"/>
55+
</module>
56+
57+
<module name="ConstantNameCheck">
58+
<!-- Validates non-private, static, final fields against the supplied
59+
public/package final fields "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$". -->
60+
<metadata name="altname" value="ConstantName"/>
61+
<property name="applyToPublic" value="true"/>
62+
<property name="applyToProtected" value="true"/>
63+
<property name="applyToPackage" value="true"/>
64+
<property name="applyToPrivate" value="false"/>
65+
<property name="format" value="^([A-Z][A-Z0-9]*(_[A-Z0-9]+)*|FLAG_.*)$"/>
66+
<message key="name.invalidPattern"
67+
value="Variable ''{0}'' should be in ALL_CAPS (if it is a constant) or be private (otherwise)."/>
68+
<property name="severity" value="warning"/>
69+
</module>
70+
71+
<module name="StaticVariableNameCheck">
72+
<!-- Validates static, non-final fields against the supplied
73+
expression "^[a-z][a-zA-Z0-9]*_?$". -->
74+
<metadata name="altname" value="StaticVariableName"/>
75+
<property name="applyToPublic" value="true"/>
76+
<property name="applyToProtected" value="true"/>
77+
<property name="applyToPackage" value="true"/>
78+
<property name="applyToPrivate" value="true"/>
79+
<property name="format" value="^[a-z][a-zA-Z0-9]*_?$"/>
80+
<property name="severity" value="warning"/>
81+
</module>
82+
83+
<module name="MemberNameCheck">
84+
<!-- Validates non-static members against the supplied expression. -->
85+
<metadata name="altname" value="MemberName"/>
86+
<property name="applyToPublic" value="true"/>
87+
<property name="applyToProtected" value="true"/>
88+
<property name="applyToPackage" value="true"/>
89+
<property name="applyToPrivate" value="true"/>
90+
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
91+
<property name="severity" value="warning"/>
92+
</module>
93+
94+
<module name="MethodNameCheck">
95+
<!-- Validates identifiers for method names. -->
96+
<metadata name="altname" value="MethodName"/>
97+
<property name="format" value="^[a-z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*$"/>
98+
<property name="severity" value="warning"/>
99+
</module>
100+
101+
<module name="ParameterName">
102+
<!-- Validates identifiers for method parameters against the
103+
expression "^[a-z][a-zA-Z0-9]*$". -->
104+
<property name="severity" value="warning"/>
105+
</module>
106+
107+
<module name="LocalFinalVariableName">
108+
<!-- Validates identifiers for local final variables against the
109+
expression "^[a-z][a-zA-Z0-9]*$". -->
110+
<property name="severity" value="warning"/>
111+
</module>
112+
113+
<module name="LocalVariableName">
114+
<!-- Validates identifiers for local variables against the
115+
expression "^[a-z][a-zA-Z0-9]*$". -->
116+
<property name="severity" value="warning"/>
117+
</module>
118+
119+
120+
<!--
121+
122+
LENGTH and CODING CHECKS
123+
124+
-->
125+
<module name="LeftCurly">
126+
<!-- Checks for placement of the left curly brace ('{'). -->
127+
<property name="severity" value="warning"/>
128+
</module>
129+
130+
<module name="RightCurly">
131+
<property name="option" value="same"/>
132+
<property name="severity" value="warning"/>
133+
</module>
134+
135+
<!-- Checks for braces around if and else blocks -->
136+
<module name="NeedBraces">
137+
<property name="severity" value="warning"/>
138+
<property name="tokens" value="LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO"/>
139+
</module>
140+
141+
<module name="UpperEll">
142+
<!-- Checks that long constants are defined with an upper ell.-->
143+
<property name="severity" value="error"/>
144+
</module>
145+
146+
<module name="FallThrough">
147+
<!-- Warn about falling through to the next case statement. Similar to
148+
javac -Xlint:fallthrough, but the check is suppressed if a single-line comment
149+
on the last non-blank line preceding the fallen-into case contains 'fall through' (or
150+
some other variants which we don't publicized to promote consistency).
151+
-->
152+
<property name="reliefPattern"
153+
value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
154+
<property name="severity" value="error"/>
155+
</module>
156+
157+
158+
<!--
159+
160+
MODIFIERS CHECKS
161+
162+
-->
163+
164+
<!-- <module name="ModifierOrder">-->
165+
<!-- &lt;!&ndash; Warn if modifier order is inconsistent with JLS3 8.1.1, 8.3.1, and-->
166+
<!-- 8.4.3. The prescribed order is:-->
167+
<!-- public, protected, private, abstract, static, final, transient, volatile,-->
168+
<!-- synchronized, native, strictfp-->
169+
<!-- &ndash;&gt;-->
170+
<!-- </module>-->
171+
172+
173+
<!--
174+
175+
WHITESPACE CHECKS
176+
177+
-->
178+
179+
<module name="WhitespaceAround">
180+
<!-- Checks that various tokens are surrounded by whitespace.
181+
This includes most binary operators and keywords followed
182+
by regular or curly braces.
183+
-->
184+
<property name="tokens" value="ASSIGN, BAND, BAND_ASSIGN, BOR,
185+
BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN,
186+
EQUAL, GE, GT, LAND, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
187+
LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
188+
LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS,
189+
MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION,
190+
SL, SL_ASSIGN, SR_ASSIGN, STAR, STAR_ASSIGN"/>
191+
<property name="severity" value="error"/>
192+
</module>
193+
194+
<module name="WhitespaceAfter">
195+
<!-- Checks that commas, semicolons and typecasts are followed by
196+
whitespace.
197+
-->
198+
<property name="tokens" value="COMMA, SEMI, TYPECAST"/>
199+
</module>
200+
201+
<module name="NoWhitespaceAfter">
202+
<!-- Checks that there is no whitespace after various unary operators.
203+
Linebreaks are allowed.
204+
-->
205+
<property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS,
206+
UNARY_PLUS"/>
207+
<property name="allowLineBreaks" value="true"/>
208+
<property name="severity" value="error"/>
209+
</module>
210+
211+
<module name="NoWhitespaceBefore">
212+
<!-- Checks that there is no whitespace before various unary operators.
213+
Linebreaks are allowed.
214+
-->
215+
<property name="tokens" value="SEMI, DOT, POST_DEC, POST_INC"/>
216+
<property name="allowLineBreaks" value="true"/>
217+
<property name="severity" value="error"/>
218+
</module>
219+
220+
<module name="ParenPad">
221+
<!-- Checks that there is no whitespace before close parens or after
222+
open parens.
223+
-->
224+
<property name="severity" value="warning"/>
225+
</module>
226+
227+
</module>
228+
</module>

config/git-hooks/pre-commit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
#set -x
3+
4+
echo "begin to execute hook"
5+
mvn checkstyle:check
6+
7+
RESULT=$?
8+
9+
exit $RESULT

example-client/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
<dependency>
1515
<groupId>github.javaguide</groupId>
1616
<artifactId>rpc-framework-simple</artifactId>
17-
<version>1.0-SNAPSHOT</version>
17+
<version>${project.version}</version>
1818
<scope>compile</scope>
1919
</dependency>
2020
<dependency>
2121
<groupId>github.javaguide</groupId>
2222
<artifactId>hello-service-api</artifactId>
23-
<version>1.0-SNAPSHOT</version>
23+
<version>${project.version}</version>
2424
<scope>compile</scope>
2525
</dependency>
2626
</dependencies>

example-server/pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111

1212
<artifactId>example-server</artifactId>
1313
<dependencies>
14-
<dependency>
15-
<artifactId>guide-rpc-framework</artifactId>
16-
<groupId>github.javaguide</groupId>
17-
<version>${project.version}</version>
18-
</dependency>
1914
<dependency>
2015
<groupId>github.javaguide</groupId>
2116
<artifactId>hello-service-api</artifactId>
@@ -24,8 +19,7 @@
2419
<dependency>
2520
<groupId>github.javaguide</groupId>
2621
<artifactId>rpc-framework-simple</artifactId>
27-
<version>1.0-SNAPSHOT</version>
28-
<scope>compile</scope>
22+
<version>${project.version}</version>
2923
</dependency>
3024
</dependencies>
3125

example-server/src/main/java/github/javaguide/RpcFrameworkSimpleServerMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public class RpcFrameworkSimpleServerMain {
1010
public static void main(String[] args) {
1111
HelloService helloService = new HelloServiceImpl();
1212
SocketRpcServer socketRpcServer = new SocketRpcServer("127.0.0.1", 8080);
13-
socketRpcServer.publishService(helloService,HelloService.class);
13+
socketRpcServer.publishService(helloService, HelloService.class);
1414
}
1515
}

init.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cp config/git-hooks/pre-commit .git/hooks/
2+
chmod +x .git/hooks/pre-commit

pom.xml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
<!-- test -->
2424
<junit.jupiter.version>5.5.2</junit.jupiter.version>
2525
<junit.platform.version>1.5.2</junit.platform.version>
26+
<!-- checkstyle -->
27+
<checkstyle-maven-plugin.version>3.0.0</checkstyle-maven-plugin.version>
2628
</properties>
2729
<modules>
2830
<module>rpc-framework-simple</module>
2931
<module>hello-service-api</module>
3032
<module>example-client</module>
3133
<module>example-server</module>
3234
<module>rpc-framework-common</module>
33-
<module>rpc-framework-common</module>
3435
</modules>
3536
<dependencies>
3637
<!-- lombok -->
@@ -132,6 +133,33 @@
132133
<encoding>${encoding}</encoding>
133134
</configuration>
134135
</plugin>
136+
<plugin>
137+
<groupId>org.apache.maven.plugins</groupId>
138+
<artifactId>maven-checkstyle-plugin</artifactId>
139+
<version>${checkstyle-maven-plugin.version}</version>
140+
<configuration>
141+
<configLocation>config/checkstyle.xml</configLocation>
142+
</configuration>
143+
<executions>
144+
<execution>
145+
<goals>
146+
<goal>check</goal>
147+
</goals>
148+
</execution>
149+
</executions>
150+
</plugin>
135151
</plugins>
136152
</build>
153+
<reporting>
154+
<plugins>
155+
<plugin>
156+
<groupId>org.apache.maven.plugins</groupId>
157+
<artifactId>maven-checkstyle-plugin</artifactId>
158+
<version>${checkstyle-maven-plugin.version}</version>
159+
<configuration>
160+
<configLocation>checkstyle.xml</configLocation>
161+
</configuration>
162+
</plugin>
163+
</plugins>
164+
</reporting>
137165
</project>

rpc-framework-simple/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
<dependency>
1414
<groupId>github.javaguide</groupId>
1515
<artifactId>rpc-framework-common</artifactId>
16-
<version>1.0-SNAPSHOT</version>
17-
<scope>compile</scope>
16+
<version>${project.version}</version>
1817
</dependency>
1918
<dependency>
2019
<groupId>io.netty</groupId>

0 commit comments

Comments
 (0)