Skip to content

Commit daf8e04

Browse files
onobcdsyer
authored andcommitted
Adds checkstyles to project
This commit configures in the Puppycrawl checkstyle with the Spring JavaFormat. To avoid the intrusive nature of such a change, the spring-grpc-core module is the only one to have the checkstyles applied. I will handle the other modules as time permits. Signed-off-by: Chris Bono <[email protected]>
1 parent 33483bb commit daf8e04

31 files changed

+574
-63
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ Before submitting a PR, please run the following commands to ensure proper forma
1010

1111
The `-Pjavadoc` is a profile that enables Javadoc processing so as to avoid a long build time when developing.
1212

13+
<dl><dt><strong>📌 NOTE</strong></dt><dd>
14+
15+
We use the [Spring JavaFormat](https://github.com/spring-io/spring-javaformat) project to apply code formatting conventions as well as checkstyle rules for many of our code conventions.
16+
17+
The code can also be formatted from your IDE when the formatter plugin [has been installed](https://github.com/spring-projects-experimental/spring-grpc/wiki/Working-with-the-Code#install-the-spring-formatter-plugin).
18+
</dd></dl>
19+
1320
## Contributing a New GRPC Features
1421

1522
To contribute a new feature, adhere to the following steps:

idea/codeStyleConfig.xml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<code_scheme name="Spring gRPC" version="173">
2+
<option name="AUTODETECT_INDENTS" value="false"/>
3+
<option name="OTHER_INDENT_OPTIONS">
4+
<value>
5+
<option name="USE_TAB_CHARACTER" value="true"/>
6+
</value>
7+
</option>
8+
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="50"/>
9+
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="500"/>
10+
<option name="IMPORT_LAYOUT_TABLE">
11+
<value>
12+
<package name="java" withSubpackages="true" static="false"/>
13+
<emptyLine/>
14+
<package name="javax" withSubpackages="true" static="false"/>
15+
<emptyLine/>
16+
<package name="" withSubpackages="true" static="false"/>
17+
<emptyLine/>
18+
<package name="org.springframework" withSubpackages="true" static="false"/>
19+
<emptyLine/>
20+
<package name="" withSubpackages="true" static="true"/>
21+
</value>
22+
</option>
23+
<option name="RIGHT_MARGIN" value="90"/>
24+
<option name="ENABLE_JAVADOC_FORMATTING" value="false"/>
25+
<option name="JD_ALIGN_PARAM_COMMENTS" value="false"/>
26+
<option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false"/>
27+
<option name="JD_KEEP_EMPTY_LINES" value="false"/>
28+
<GroovyCodeStyleSettings>
29+
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="500"/>
30+
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="500"/>
31+
<option name="IMPORT_LAYOUT_TABLE">
32+
<value>
33+
<emptyLine/>
34+
<package name="javax" withSubpackages="true" static="false"/>
35+
<package name="java" withSubpackages="true" static="false"/>
36+
<emptyLine/>
37+
<package name="" withSubpackages="true" static="false"/>
38+
<emptyLine/>
39+
<package name="org.springframework" withSubpackages="true"
40+
static="false"/>
41+
<emptyLine/>
42+
<package name="" withSubpackages="true" static="true"/>
43+
</value>
44+
</option>
45+
</GroovyCodeStyleSettings>
46+
<JavaCodeStyleSettings>
47+
<option name="CLASS_NAMES_IN_JAVADOC" value="3"/>
48+
<option name="INSERT_INNER_CLASS_IMPORTS" value="true"/>
49+
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="50"/>
50+
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="500"/>
51+
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
52+
<value/>
53+
</option>
54+
<option name="IMPORT_LAYOUT_TABLE">
55+
<value>
56+
<package name="" withSubpackages="true" static="true"/>
57+
<emptyLine/>
58+
<package name="java" withSubpackages="true" static="false"/>
59+
<emptyLine/>
60+
<package name="javax" withSubpackages="true" static="false"/>
61+
<emptyLine/>
62+
<package name="org" withSubpackages="true" static="false"/>
63+
<emptyLine/>
64+
<package name="org.springframework" withSubpackages="true" static="false"/>
65+
</value>
66+
</option>
67+
<option name="ENABLE_JAVADOC_FORMATTING" value="false"/>
68+
<option name="JD_ALIGN_PARAM_COMMENTS" value="false"/>
69+
<option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false"/>
70+
<option name="JD_KEEP_INVALID_TAGS" value="false"/>
71+
<option name="JD_KEEP_EMPTY_LINES" value="false"/>
72+
</JavaCodeStyleSettings>
73+
<JetCodeStyleSettings>
74+
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
75+
<value>
76+
<package name="java.util" withSubpackages="false" static="false"/>
77+
<package name="kotlinx.android.synthetic" withSubpackages="false"
78+
static="false"/>
79+
</value>
80+
</option>
81+
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="20"/>
82+
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="20"/>
83+
</JetCodeStyleSettings>
84+
<XML>
85+
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true"/>
86+
</XML>
87+
<editorconfig>
88+
<option name="ENABLED" value="false"/>
89+
</editorconfig>
90+
<codeStyleSettings language="Groovy">
91+
<indentOptions>
92+
<option name="USE_TAB_CHARACTER" value="true"/>
93+
</indentOptions>
94+
</codeStyleSettings>
95+
<codeStyleSettings language="JAVA">
96+
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1"/>
97+
<option name="BLANK_LINES_AROUND_FIELD" value="1"/>
98+
<option name="BLANK_LINES_AROUND_FIELD_IN_INTERFACE" value="1"/>
99+
<option name="ELSE_ON_NEW_LINE" value="true"/>
100+
<option name="CATCH_ON_NEW_LINE" value="true"/>
101+
<option name="FINALLY_ON_NEW_LINE" value="true"/>
102+
<option name="ALIGN_MULTILINE_PARAMETERS" value="false"/>
103+
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACES" value="true"/>
104+
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true"/>
105+
<option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true"/>
106+
<option name="KEEP_SIMPLE_CLASSES_IN_ONE_LINE" value="true"/>
107+
<option name="KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE" value="true"/>
108+
<indentOptions>
109+
<option name="USE_TAB_CHARACTER" value="true"/>
110+
</indentOptions>
111+
</codeStyleSettings>
112+
<codeStyleSettings language="JSON">
113+
<indentOptions>
114+
<option name="TAB_SIZE" value="2"/>
115+
</indentOptions>
116+
</codeStyleSettings>
117+
<codeStyleSettings language="XML">
118+
<indentOptions>
119+
<option name="USE_TAB_CHARACTER" value="true"/>
120+
</indentOptions>
121+
</codeStyleSettings>
122+
<codeStyleSettings language="kotlin">
123+
<indentOptions>
124+
<option name="USE_TAB_CHARACTER" value="true"/>
125+
</indentOptions>
126+
</codeStyleSettings>
127+
</code_scheme>

pom.xml

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
<spring-boot.version>3.3.4</spring-boot.version>
7979
<jackson.version>2.17.2</jackson.version>
8080
<junit.version>5.10.5</junit.version>
81-
81+
<assertj.version>3.26.3</assertj.version>
8282
<!-- documentation dependencies -->
8383
<io.spring.maven.antora-version>0.0.4</io.spring.maven.antora-version>
8484
<asciidoctorj-pdf.version>1.6.2</asciidoctorj-pdf.version> <!-- FIXME build failure with
@@ -103,8 +103,17 @@
103103
<maven-site-plugin.version>4.0.0-M13</maven-site-plugin.version>
104104
<maven-project-info-reports-plugin.version>3.4.5</maven-project-info-reports-plugin.version>
105105
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
106-
<spring-javaformat-maven-plugin.version>0.0.39</spring-javaformat-maven-plugin.version>
107-
106+
<!-- BEGIN format + checkstyle properties -->
107+
<spring-javaformat-maven-plugin.version>0.0.43</spring-javaformat-maven-plugin.version>
108+
<maven-checkstyle-plugin.version>3.6.0</maven-checkstyle-plugin.version>
109+
<puppycrawl-tools-checkstyle.version>9.3</puppycrawl-tools-checkstyle.version>
110+
<spring-javaformat-checkstyle.version>0.0.43</spring-javaformat-checkstyle.version>
111+
<disable.format.checks>false</disable.format.checks>
112+
<disable.checkstyle.checks>false</disable.checkstyle.checks>
113+
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>
114+
<maven-checkstyle-plugin.failOnViolation>true</maven-checkstyle-plugin.failOnViolation>
115+
<maven-checkstyle-plugin.includeTestSourceDirectory>true</maven-checkstyle-plugin.includeTestSourceDirectory>
116+
<!-- END format + checkstyle properties -->
108117
</properties>
109118

110119
<build>
@@ -117,12 +126,53 @@
117126
<execution>
118127
<phase>validate</phase>
119128
<inherited>true</inherited>
129+
<configuration>
130+
<skip>${disable.format.checks}</skip>
131+
</configuration>
120132
<goals>
121133
<goal>validate</goal>
122134
</goals>
123135
</execution>
124136
</executions>
125137
</plugin>
138+
<plugin>
139+
<groupId>org.apache.maven.plugins</groupId>
140+
<artifactId>maven-checkstyle-plugin</artifactId>
141+
<version>${maven-checkstyle-plugin.version}</version>
142+
<dependencies>
143+
<dependency>
144+
<groupId>com.puppycrawl.tools</groupId>
145+
<artifactId>checkstyle</artifactId>
146+
<version>${puppycrawl-tools-checkstyle.version}</version>
147+
</dependency>
148+
<dependency>
149+
<groupId>io.spring.javaformat</groupId>
150+
<artifactId>spring-javaformat-checkstyle</artifactId>
151+
<version>${spring-javaformat-checkstyle.version}</version>
152+
</dependency>
153+
</dependencies>
154+
<executions>
155+
<execution>
156+
<id>checkstyle-validation</id>
157+
<phase>validate</phase>
158+
<inherited>true</inherited>
159+
<configuration>
160+
<configLocation>src/checkstyle/checkstyle.xml</configLocation>
161+
<propertyExpansion>
162+
config_loc=src/checkstyle
163+
</propertyExpansion>
164+
<skip>${disable.checkstyle.checks}</skip>
165+
<includeTestSourceDirectory>${maven-checkstyle-plugin.includeTestSourceDirectory}</includeTestSourceDirectory>
166+
<failsOnError>${maven-checkstyle-plugin.failsOnError}</failsOnError>
167+
<failOnViolation>${maven-checkstyle-plugin.failOnViolation}</failOnViolation>
168+
<consoleOutput>true</consoleOutput>
169+
</configuration>
170+
<goals>
171+
<goal>check</goal>
172+
</goals>
173+
</execution>
174+
</executions>
175+
</plugin>
126176
<plugin>
127177
<groupId>org.apache.maven.plugins</groupId>
128178
<artifactId>maven-site-plugin</artifactId>
@@ -438,6 +488,20 @@
438488
<type>pom</type>
439489
<scope>import</scope>
440490
</dependency>
491+
<dependency>
492+
<groupId>org.junit</groupId>
493+
<artifactId>junit-bom</artifactId>
494+
<version>${junit.version}</version>
495+
<type>pom</type>
496+
<scope>import</scope>
497+
</dependency>
498+
<dependency>
499+
<groupId>org.assertj</groupId>
500+
<artifactId>assertj-bom</artifactId>
501+
<version>${assertj.version}</version>
502+
<type>pom</type>
503+
<scope>import</scope>
504+
</dependency>
441505
</dependencies>
442506
</dependencyManagement>
443507

spring-grpc-core/pom.xml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66
<parent>
77
<groupId>org.springframework.grpc</groupId>
@@ -16,8 +16,10 @@
1616

1717
<scm>
1818
<url>https://github.com/spring-projects-experimental/spring-grpc</url>
19-
<connection>git://github.com/spring-projects-experimental/spring-grpc.git</connection>
20-
<developerConnection>[email protected]:spring-projects-experimental/spring-grpc.git</developerConnection>
19+
<connection>git://github.com/spring-projects-experimental/spring-grpc.git
20+
</connection>
21+
<developerConnection>[email protected]:spring-projects-experimental/spring-grpc.git
22+
</developerConnection>
2123
</scm>
2224

2325
<dependencies>
@@ -70,7 +72,11 @@
7072
<dependency>
7173
<groupId>org.junit.jupiter</groupId>
7274
<artifactId>junit-jupiter</artifactId>
73-
<version>${junit.version}</version>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.assertj</groupId>
79+
<artifactId>assertj-core</artifactId>
7480
<scope>test</scope>
7581
</dependency>
7682

spring-grpc-core/src/main/java/org/springframework/grpc/client/ChannelCredentialsProvider.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15-
*/
15+
* */
16+
1617
package org.springframework.grpc.client;
1718

1819
import io.grpc.ChannelCredentials;
1920
import io.grpc.InsecureChannelCredentials;
2021

2122
/**
2223
* A provider for obtaining channel credentials for gRPC client.
24+
*
25+
* @author David Syer
2326
*/
2427
public interface ChannelCredentialsProvider {
2528

26-
static final ChannelCredentialsProvider INSECURE = path -> InsecureChannelCredentials.create();
29+
/** Insecure credentials provider instance. */
30+
ChannelCredentialsProvider INSECURE = path -> InsecureChannelCredentials.create();
2731

2832
ChannelCredentials getChannelCredentials(String path);
2933

spring-grpc-core/src/main/java/org/springframework/grpc/client/DefaultGrpcChannelFactory.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15-
*/
15+
* */
16+
1617
package org.springframework.grpc.client;
1718

1819
import java.util.ArrayList;
@@ -58,10 +59,10 @@ public void setCredentialsProvider(ChannelCredentialsProvider credentials) {
5859

5960
@Override
6061
public ManagedChannelBuilder<?> createChannel(String authority) {
61-
ManagedChannelBuilder<?> target = builders.computeIfAbsent(authority, path -> {
62-
ManagedChannelBuilder<?> builder = newChannel(targets.getTarget(path),
63-
credentials.getChannelCredentials(path));
64-
for (GrpcChannelConfigurer configurer : configurers) {
62+
ManagedChannelBuilder<?> target = this.builders.computeIfAbsent(authority, path -> {
63+
ManagedChannelBuilder<?> builder = newChannel(this.targets.getTarget(path),
64+
this.credentials.getChannelCredentials(path));
65+
for (GrpcChannelConfigurer configurer : this.configurers) {
6566
configurer.configure(path, builder);
6667
}
6768
return builder;
@@ -75,8 +76,8 @@ protected ManagedChannelBuilder<?> newChannel(String path, ChannelCredentials cr
7576
}
7677

7778
@Override
78-
public void destroy() throws Exception {
79-
for (ManagedChannel channel : channels.values()) {
79+
public void destroy() {
80+
for (ManagedChannel channel : this.channels.values()) {
8081
channel.shutdown();
8182
}
8283
}
@@ -87,19 +88,20 @@ class DisposableChannelBuilder extends ForwardingChannelBuilder2<DisposableChann
8788

8889
private final String authority;
8990

90-
public DisposableChannelBuilder(String authority, ManagedChannelBuilder<?> delegate) {
91+
DisposableChannelBuilder(String authority, ManagedChannelBuilder<?> delegate) {
9192
this.authority = authority;
9293
this.delegate = delegate;
9394
}
9495

9596
@Override
9697
protected ManagedChannelBuilder<?> delegate() {
97-
return delegate;
98+
return this.delegate;
9899
}
99100

100101
@Override
101102
public ManagedChannel build() {
102-
ManagedChannel channel = channels.computeIfAbsent(authority, name -> super.build());
103+
ManagedChannel channel = DefaultGrpcChannelFactory.this.channels.computeIfAbsent(this.authority,
104+
name -> super.build());
103105
return channel;
104106
}
105107

spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelConfigurer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15-
*/
15+
* */
16+
1617
package org.springframework.grpc.client;
1718

1819
import io.grpc.ManagedChannelBuilder;
1920

2021
@FunctionalInterface
2122
public interface GrpcChannelConfigurer {
2223

23-
public void configure(String authority, ManagedChannelBuilder<?> builder);
24+
void configure(String authority, ManagedChannelBuilder<?> builder);
2425

2526
}

spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.grpc.client;
1718

1819
import io.grpc.ManagedChannelBuilder;

0 commit comments

Comments
 (0)