Skip to content

Commit

Permalink
Adds checkstyles to project
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
onobc authored and dsyer committed Nov 7, 2024
1 parent 33483bb commit daf8e04
Show file tree
Hide file tree
Showing 31 changed files with 574 additions and 63 deletions.
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ Before submitting a PR, please run the following commands to ensure proper forma

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

<dl><dt><strong>📌 NOTE</strong></dt><dd>

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.

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).
</dd></dl>

## Contributing a New GRPC Features

To contribute a new feature, adhere to the following steps:
Expand Down
127 changes: 127 additions & 0 deletions idea/codeStyleConfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<code_scheme name="Spring gRPC" version="173">
<option name="AUTODETECT_INDENTS" value="false"/>
<option name="OTHER_INDENT_OPTIONS">
<value>
<option name="USE_TAB_CHARACTER" value="true"/>
</value>
</option>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="50"/>
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="500"/>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="java" withSubpackages="true" static="false"/>
<emptyLine/>
<package name="javax" withSubpackages="true" static="false"/>
<emptyLine/>
<package name="" withSubpackages="true" static="false"/>
<emptyLine/>
<package name="org.springframework" withSubpackages="true" static="false"/>
<emptyLine/>
<package name="" withSubpackages="true" static="true"/>
</value>
</option>
<option name="RIGHT_MARGIN" value="90"/>
<option name="ENABLE_JAVADOC_FORMATTING" value="false"/>
<option name="JD_ALIGN_PARAM_COMMENTS" value="false"/>
<option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false"/>
<option name="JD_KEEP_EMPTY_LINES" value="false"/>
<GroovyCodeStyleSettings>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="500"/>
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="500"/>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<emptyLine/>
<package name="javax" withSubpackages="true" static="false"/>
<package name="java" withSubpackages="true" static="false"/>
<emptyLine/>
<package name="" withSubpackages="true" static="false"/>
<emptyLine/>
<package name="org.springframework" withSubpackages="true"
static="false"/>
<emptyLine/>
<package name="" withSubpackages="true" static="true"/>
</value>
</option>
</GroovyCodeStyleSettings>
<JavaCodeStyleSettings>
<option name="CLASS_NAMES_IN_JAVADOC" value="3"/>
<option name="INSERT_INNER_CLASS_IMPORTS" value="true"/>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="50"/>
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="500"/>
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
<value/>
</option>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true"/>
<emptyLine/>
<package name="java" withSubpackages="true" static="false"/>
<emptyLine/>
<package name="javax" withSubpackages="true" static="false"/>
<emptyLine/>
<package name="org" withSubpackages="true" static="false"/>
<emptyLine/>
<package name="org.springframework" withSubpackages="true" static="false"/>
</value>
</option>
<option name="ENABLE_JAVADOC_FORMATTING" value="false"/>
<option name="JD_ALIGN_PARAM_COMMENTS" value="false"/>
<option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false"/>
<option name="JD_KEEP_INVALID_TAGS" value="false"/>
<option name="JD_KEEP_EMPTY_LINES" value="false"/>
</JavaCodeStyleSettings>
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value>
<package name="java.util" withSubpackages="false" static="false"/>
<package name="kotlinx.android.synthetic" withSubpackages="false"
static="false"/>
</value>
</option>
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="20"/>
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="20"/>
</JetCodeStyleSettings>
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true"/>
</XML>
<editorconfig>
<option name="ENABLED" value="false"/>
</editorconfig>
<codeStyleSettings language="Groovy">
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true"/>
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="JAVA">
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1"/>
<option name="BLANK_LINES_AROUND_FIELD" value="1"/>
<option name="BLANK_LINES_AROUND_FIELD_IN_INTERFACE" value="1"/>
<option name="ELSE_ON_NEW_LINE" value="true"/>
<option name="CATCH_ON_NEW_LINE" value="true"/>
<option name="FINALLY_ON_NEW_LINE" value="true"/>
<option name="ALIGN_MULTILINE_PARAMETERS" value="false"/>
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACES" value="true"/>
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true"/>
<option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true"/>
<option name="KEEP_SIMPLE_CLASSES_IN_ONE_LINE" value="true"/>
<option name="KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE" value="true"/>
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true"/>
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="JSON">
<indentOptions>
<option name="TAB_SIZE" value="2"/>
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="XML">
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true"/>
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true"/>
</indentOptions>
</codeStyleSettings>
</code_scheme>
70 changes: 67 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<spring-boot.version>3.3.4</spring-boot.version>
<jackson.version>2.17.2</jackson.version>
<junit.version>5.10.5</junit.version>

<assertj.version>3.26.3</assertj.version>
<!-- documentation dependencies -->
<io.spring.maven.antora-version>0.0.4</io.spring.maven.antora-version>
<asciidoctorj-pdf.version>1.6.2</asciidoctorj-pdf.version> <!-- FIXME build failure with
Expand All @@ -103,8 +103,17 @@
<maven-site-plugin.version>4.0.0-M13</maven-site-plugin.version>
<maven-project-info-reports-plugin.version>3.4.5</maven-project-info-reports-plugin.version>
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
<spring-javaformat-maven-plugin.version>0.0.39</spring-javaformat-maven-plugin.version>

<!-- BEGIN format + checkstyle properties -->
<spring-javaformat-maven-plugin.version>0.0.43</spring-javaformat-maven-plugin.version>
<maven-checkstyle-plugin.version>3.6.0</maven-checkstyle-plugin.version>
<puppycrawl-tools-checkstyle.version>9.3</puppycrawl-tools-checkstyle.version>
<spring-javaformat-checkstyle.version>0.0.43</spring-javaformat-checkstyle.version>
<disable.format.checks>false</disable.format.checks>
<disable.checkstyle.checks>false</disable.checkstyle.checks>
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>
<maven-checkstyle-plugin.failOnViolation>true</maven-checkstyle-plugin.failOnViolation>
<maven-checkstyle-plugin.includeTestSourceDirectory>true</maven-checkstyle-plugin.includeTestSourceDirectory>
<!-- END format + checkstyle properties -->
</properties>

<build>
Expand All @@ -117,12 +126,53 @@
<execution>
<phase>validate</phase>
<inherited>true</inherited>
<configuration>
<skip>${disable.format.checks}</skip>
</configuration>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${puppycrawl-tools-checkstyle.version}</version>
</dependency>
<dependency>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-checkstyle</artifactId>
<version>${spring-javaformat-checkstyle.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>checkstyle-validation</id>
<phase>validate</phase>
<inherited>true</inherited>
<configuration>
<configLocation>src/checkstyle/checkstyle.xml</configLocation>
<propertyExpansion>
config_loc=src/checkstyle
</propertyExpansion>
<skip>${disable.checkstyle.checks}</skip>
<includeTestSourceDirectory>${maven-checkstyle-plugin.includeTestSourceDirectory}</includeTestSourceDirectory>
<failsOnError>${maven-checkstyle-plugin.failsOnError}</failsOnError>
<failOnViolation>${maven-checkstyle-plugin.failOnViolation}</failOnViolation>
<consoleOutput>true</consoleOutput>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
Expand Down Expand Up @@ -438,6 +488,20 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-bom</artifactId>
<version>${assertj.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
16 changes: 11 additions & 5 deletions spring-grpc-core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.grpc</groupId>
Expand All @@ -16,8 +16,10 @@

<scm>
<url>https://github.com/spring-projects-experimental/spring-grpc</url>
<connection>git://github.com/spring-projects-experimental/spring-grpc.git</connection>
<developerConnection>[email protected]:spring-projects-experimental/spring-grpc.git</developerConnection>
<connection>git://github.com/spring-projects-experimental/spring-grpc.git
</connection>
<developerConnection>[email protected]:spring-projects-experimental/spring-grpc.git
</developerConnection>
</scm>

<dependencies>
Expand Down Expand Up @@ -70,7 +72,11 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,22 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* */

package org.springframework.grpc.client;

import io.grpc.ChannelCredentials;
import io.grpc.InsecureChannelCredentials;

/**
* A provider for obtaining channel credentials for gRPC client.
*
* @author David Syer
*/
public interface ChannelCredentialsProvider {

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

ChannelCredentials getChannelCredentials(String path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* */

package org.springframework.grpc.client;

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

@Override
public ManagedChannelBuilder<?> createChannel(String authority) {
ManagedChannelBuilder<?> target = builders.computeIfAbsent(authority, path -> {
ManagedChannelBuilder<?> builder = newChannel(targets.getTarget(path),
credentials.getChannelCredentials(path));
for (GrpcChannelConfigurer configurer : configurers) {
ManagedChannelBuilder<?> target = this.builders.computeIfAbsent(authority, path -> {
ManagedChannelBuilder<?> builder = newChannel(this.targets.getTarget(path),
this.credentials.getChannelCredentials(path));
for (GrpcChannelConfigurer configurer : this.configurers) {
configurer.configure(path, builder);
}
return builder;
Expand All @@ -75,8 +76,8 @@ protected ManagedChannelBuilder<?> newChannel(String path, ChannelCredentials cr
}

@Override
public void destroy() throws Exception {
for (ManagedChannel channel : channels.values()) {
public void destroy() {
for (ManagedChannel channel : this.channels.values()) {
channel.shutdown();
}
}
Expand All @@ -87,19 +88,20 @@ class DisposableChannelBuilder extends ForwardingChannelBuilder2<DisposableChann

private final String authority;

public DisposableChannelBuilder(String authority, ManagedChannelBuilder<?> delegate) {
DisposableChannelBuilder(String authority, ManagedChannelBuilder<?> delegate) {
this.authority = authority;
this.delegate = delegate;
}

@Override
protected ManagedChannelBuilder<?> delegate() {
return delegate;
return this.delegate;
}

@Override
public ManagedChannel build() {
ManagedChannel channel = channels.computeIfAbsent(authority, name -> super.build());
ManagedChannel channel = DefaultGrpcChannelFactory.this.channels.computeIfAbsent(this.authority,
name -> super.build());
return channel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* */

package org.springframework.grpc.client;

import io.grpc.ManagedChannelBuilder;

@FunctionalInterface
public interface GrpcChannelConfigurer {

public void configure(String authority, ManagedChannelBuilder<?> builder);
void configure(String authority, ManagedChannelBuilder<?> builder);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.grpc.client;

import io.grpc.ManagedChannelBuilder;
Expand Down
Loading

0 comments on commit daf8e04

Please sign in to comment.