diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a8df5f75..29e17143 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. +
📌 NOTE
+ +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). +
+ ## Contributing a New GRPC Features To contribute a new feature, adhere to the following steps: diff --git a/idea/codeStyleConfig.xml b/idea/codeStyleConfig.xml new file mode 100644 index 00000000..725de484 --- /dev/null +++ b/idea/codeStyleConfig.xml @@ -0,0 +1,127 @@ + + + + diff --git a/pom.xml b/pom.xml index 3929412f..4eadb262 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ 3.3.4 2.17.2 5.10.5 - + 3.26.3 0.0.4 1.6.2 + 0.0.43 + 3.6.0 + 9.3 + 0.0.43 + false + false + true + true + true + @@ -117,12 +126,53 @@ validate true + + ${disable.format.checks} + validate + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + + + com.puppycrawl.tools + checkstyle + ${puppycrawl-tools-checkstyle.version} + + + io.spring.javaformat + spring-javaformat-checkstyle + ${spring-javaformat-checkstyle.version} + + + + + checkstyle-validation + validate + true + + src/checkstyle/checkstyle.xml + + config_loc=src/checkstyle + + ${disable.checkstyle.checks} + ${maven-checkstyle-plugin.includeTestSourceDirectory} + ${maven-checkstyle-plugin.failsOnError} + ${maven-checkstyle-plugin.failOnViolation} + true + + + check + + + + org.apache.maven.plugins maven-site-plugin @@ -438,6 +488,20 @@ pom import + + org.junit + junit-bom + ${junit.version} + pom + import + + + org.assertj + assertj-bom + ${assertj.version} + pom + import + diff --git a/spring-grpc-core/pom.xml b/spring-grpc-core/pom.xml index db63d3c2..a3901230 100644 --- a/spring-grpc-core/pom.xml +++ b/spring-grpc-core/pom.xml @@ -1,7 +1,7 @@ + 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"> 4.0.0 org.springframework.grpc @@ -16,8 +16,10 @@ https://github.com/spring-projects-experimental/spring-grpc - git://github.com/spring-projects-experimental/spring-grpc.git - git@github.com:spring-projects-experimental/spring-grpc.git + git://github.com/spring-projects-experimental/spring-grpc.git + + git@github.com:spring-projects-experimental/spring-grpc.git + @@ -70,7 +72,11 @@ org.junit.jupiter junit-jupiter - ${junit.version} + test + + + org.assertj + assertj-core test diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/client/ChannelCredentialsProvider.java b/spring-grpc-core/src/main/java/org/springframework/grpc/client/ChannelCredentialsProvider.java index ec249c61..c6ce3515 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/client/ChannelCredentialsProvider.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/client/ChannelCredentialsProvider.java @@ -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 io.grpc.ChannelCredentials; @@ -20,10 +21,13 @@ /** * 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); diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/client/DefaultGrpcChannelFactory.java b/spring-grpc-core/src/main/java/org/springframework/grpc/client/DefaultGrpcChannelFactory.java index 911220ba..b0a57b9a 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/client/DefaultGrpcChannelFactory.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/client/DefaultGrpcChannelFactory.java @@ -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; @@ -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; @@ -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(); } } @@ -87,19 +88,20 @@ class DisposableChannelBuilder extends ForwardingChannelBuilder2 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; } diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelConfigurer.java b/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelConfigurer.java index a839319b..05748a68 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelConfigurer.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelConfigurer.java @@ -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 io.grpc.ManagedChannelBuilder; @@ -20,6 +21,6 @@ @FunctionalInterface public interface GrpcChannelConfigurer { - public void configure(String authority, ManagedChannelBuilder builder); + void configure(String authority, ManagedChannelBuilder builder); } diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelFactory.java b/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelFactory.java index b0cdc2a8..9fbfac7f 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelFactory.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/client/GrpcChannelFactory.java @@ -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; diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/client/NegotiationType.java b/spring-grpc-core/src/main/java/org/springframework/grpc/client/NegotiationType.java index 005f582e..a670f00a 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/client/NegotiationType.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/client/NegotiationType.java @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.grpc.client; /** * Identifies the negotiation used for starting up HTTP/2. * + * @author David Syer * @see io.grpc.netty.NegotiationType NegotiationType */ public enum NegotiationType { @@ -39,4 +41,4 @@ public enum NegotiationType { */ PLAINTEXT; -} \ No newline at end of file +} diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/client/VirtualTargets.java b/spring-grpc-core/src/main/java/org/springframework/grpc/client/VirtualTargets.java index a35952c0..07e35d8d 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/client/VirtualTargets.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/client/VirtualTargets.java @@ -13,14 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.grpc.client; import java.util.regex.Pattern; public interface VirtualTargets { - static Pattern AUTHORITY_PATTERN = Pattern.compile("([^:]+)(?::(\\d+))?"); + /** Regex to match the default authority pattern. */ + Pattern AUTHORITY_PATTERN = Pattern.compile("([^:]+)(?::(\\d+))?"); + /** Default VirtualTargets instance. */ VirtualTargets DEFAULT = path -> { if (AUTHORITY_PATTERN.matcher(path).matches()) { return "static://" + path; diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/internal/GrpcUtils.java b/spring-grpc-core/src/main/java/org/springframework/grpc/internal/GrpcUtils.java index 2a32dac0..3e1e17cb 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/internal/GrpcUtils.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/internal/GrpcUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2024-2024 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.grpc.internal; -public class GrpcUtils { +/** + * Provides convenience methods for various gRPC functions. + * + * @author David Syer + */ +public final class GrpcUtils { + + private GrpcUtils() { + } + /** Default port to use. */ public static int DEFAULT_PORT = 9090; + /** + * Gets port given an address. + * @param address the address to extract port from + * @return the port + */ public static int getPort(String address) { String value = address; if (value.contains(":")) { diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/internal/InsecureTrustManagerFactory.java b/spring-grpc-core/src/main/java/org/springframework/grpc/internal/InsecureTrustManagerFactory.java index c4812ef4..1065feac 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/internal/InsecureTrustManagerFactory.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/internal/InsecureTrustManagerFactory.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.grpc.internal; import java.net.Socket; @@ -36,9 +37,12 @@ * trust manager. This trust manager does not perform any certificate validation and * accepts all certificates. It is intended for testing or development purposes only and * should not be used in production environments. + * + * @author David Syer */ public class InsecureTrustManagerFactory extends TrustManagerFactory { + /** Single instance of the factory. */ public static final TrustManagerFactory INSTANCE = new InsecureTrustManagerFactory(); private static final Provider provider = new Provider("", "0.0", "") { diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/package-info.java b/spring-grpc-core/src/main/java/org/springframework/grpc/package-info.java index 1b3bd40a..0f14041c 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/package-info.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/package-info.java @@ -13,4 +13,5 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.grpc; \ No newline at end of file + +package org.springframework.grpc; diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/server/DefaultGrpcServerFactory.java b/spring-grpc-core/src/main/java/org/springframework/grpc/server/DefaultGrpcServerFactory.java index a67e04f6..3b4646be 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/server/DefaultGrpcServerFactory.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/server/DefaultGrpcServerFactory.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,10 +26,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.grpc.internal.GrpcUtils; import com.google.common.collect.Lists; - import io.grpc.Grpc; import io.grpc.InsecureServerCredentials; import io.grpc.Server; @@ -46,9 +46,9 @@ *

* The server builder implementation is discovered via Java's SPI mechanism. * + * @param the type of server builder * @author David Syer * @author Chris Bono - * @param the type of server builder * @see ServerProvider#provider() */ public class DefaultGrpcServerFactory> implements GrpcServerFactory { @@ -116,6 +116,7 @@ protected int port() { } /** + * Get server credentials. * @return some server credentials (default is insecure) */ protected ServerCredentials credentials() { @@ -159,7 +160,7 @@ protected void configureServices(T builder, List servic if (!serviceNames.add(serviceName)) { throw new IllegalStateException("Found duplicate service implementation: " + serviceName); } - logger.info("Registered gRPC service: " + serviceName); + this.logger.info("Registered gRPC service: " + serviceName); builder.addService(service); }); } diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/server/GrpcServerFactory.java b/spring-grpc-core/src/main/java/org/springframework/grpc/server/GrpcServerFactory.java index 816b667c..ea734863 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/server/GrpcServerFactory.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/server/GrpcServerFactory.java @@ -1,11 +1,11 @@ /* - * Copyright 2024-2024 the original author or authors. + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,11 +18,11 @@ package org.springframework.grpc.server; +import org.springframework.grpc.server.lifecycle.GrpcServerLifecycle; + import io.grpc.Server; import io.grpc.ServerServiceDefinition; -import org.springframework.grpc.server.lifecycle.GrpcServerLifecycle; - /** * Factory interface that can be used to create a {@link Server gRPC Server}. * diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/server/GrpcServiceDiscoverer.java b/spring-grpc-core/src/main/java/org/springframework/grpc/server/GrpcServiceDiscoverer.java index 8d825421..0e2c6ebb 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/server/GrpcServiceDiscoverer.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/server/GrpcServiceDiscoverer.java @@ -1,11 +1,11 @@ /* - * Copyright (c) 2024-2024 The gRPC-Spring Authors + * Copyright 2023-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/server/NettyGrpcServerFactory.java b/spring-grpc-core/src/main/java/org/springframework/grpc/server/NettyGrpcServerFactory.java index 2550ff46..2e6c9c1f 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/server/NettyGrpcServerFactory.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/server/NettyGrpcServerFactory.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/server/ServerBuilderCustomizer.java b/spring-grpc-core/src/main/java/org/springframework/grpc/server/ServerBuilderCustomizer.java index d7e64f4f..9b76050f 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/server/ServerBuilderCustomizer.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/server/ServerBuilderCustomizer.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.grpc.server; import io.grpc.ServerBuilder; @@ -20,8 +21,8 @@ /** * Callback interface that can be used to customize a {@link ServerBuilder}. * - * @author Chris Bono * @param the type of server builder + * @author Chris Bono */ @FunctionalInterface public interface ServerBuilderCustomizer> { diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/server/ShadedNettyGrpcServerFactory.java b/spring-grpc-core/src/main/java/org/springframework/grpc/server/ShadedNettyGrpcServerFactory.java index 083b999b..3ad992a8 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/server/ShadedNettyGrpcServerFactory.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/server/ShadedNettyGrpcServerFactory.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerLifecycle.java b/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerLifecycle.java index 3dea988b..1278c2aa 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerLifecycle.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerLifecycle.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,14 +19,15 @@ package org.springframework.grpc.server.lifecycle; import static java.util.Objects.requireNonNull; -import static java.util.concurrent.TimeUnit.MILLISECONDS; import java.io.IOException; import java.time.Duration; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.SmartLifecycle; import org.springframework.grpc.server.GrpcServerFactory; @@ -43,7 +44,7 @@ public class GrpcServerLifecycle implements SmartLifecycle { private static final Log logger = LogFactory.getLog(GrpcServerLifecycle.class); - private static AtomicInteger serverCounter = new AtomicInteger(-1); + private static final AtomicInteger serverCounter = new AtomicInteger(-1); private final GrpcServerFactory factory; @@ -54,7 +55,7 @@ public class GrpcServerLifecycle implements SmartLifecycle { private Server server; /** - * Creates a new GrpcServerLifecycle + * Creates a new GrpcServerLifecycle. * @param factory The server factory to use. * @param shutdownGracePeriod The time to wait for the server to gracefully shut down. * @param eventPublisher The event publisher to use. @@ -150,7 +151,7 @@ protected void stopAndReleaseGrpcServer() { // the spring context try { if (millis > 0) { - localServer.awaitTermination(millis, MILLISECONDS); + localServer.awaitTermination(millis, TimeUnit.MILLISECONDS); } else if (millis == 0) { // Do not wait diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerLifecycleEvent.java b/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerLifecycleEvent.java index 2f910609..f93d3e32 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerLifecycleEvent.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerLifecycleEvent.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,6 +28,8 @@ /** * The base event for {@link GrpcServerLifecycle}. + * + * @author Michael (yidongnan@gmail.com) */ public abstract class GrpcServerLifecycleEvent extends ApplicationEvent { diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerShutdownEvent.java b/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerShutdownEvent.java index 55214293..6fb7e784 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerShutdownEvent.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerShutdownEvent.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -26,9 +26,9 @@ * This event will be fired before the server starts to shutdown. The server will no * longer process new requests. * + * @author Daniel Theuke (daniel.theuke@heuboe.de) * @see Server#shutdown() * @see Server#isShutdown() - * @author Daniel Theuke (daniel.theuke@heuboe.de) */ public class GrpcServerShutdownEvent extends GrpcServerLifecycleEvent { diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerStartedEvent.java b/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerStartedEvent.java index 9cbe8d2c..09100b3b 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerStartedEvent.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerStartedEvent.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -27,8 +27,8 @@ /** * This event will be fired after the server has been started. * - * @see Server#start() * @author Daniel Theuke (daniel.theuke@heuboe.de) + * @see Server#start() */ public class GrpcServerStartedEvent extends GrpcServerLifecycleEvent { diff --git a/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerTerminatedEvent.java b/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerTerminatedEvent.java index 1b9b6dc7..3e56dbf0 100644 --- a/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerTerminatedEvent.java +++ b/spring-grpc-core/src/main/java/org/springframework/grpc/server/lifecycle/GrpcServerTerminatedEvent.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,6 +15,7 @@ * * Partial copy from net.devh:grpc-spring-boot-starter. */ + package org.springframework.grpc.server.lifecycle; import java.time.Clock; @@ -25,8 +26,8 @@ * This event will be fired after the server completed to shutdown. The server will no * longer process requests. * - * @see Server#isTerminated() * @author Daniel Theuke (daniel.theuke@heuboe.de) + * @see Server#isTerminated() */ public class GrpcServerTerminatedEvent extends GrpcServerLifecycleEvent { diff --git a/spring-grpc-core/src/test/java/org/springframework/grpc/internal/GrpcUtilsTests.java b/spring-grpc-core/src/test/java/org/springframework/grpc/internal/GrpcUtilsTests.java index 08d196a2..dab26ac8 100644 --- a/spring-grpc-core/src/test/java/org/springframework/grpc/internal/GrpcUtilsTests.java +++ b/spring-grpc-core/src/test/java/org/springframework/grpc/internal/GrpcUtilsTests.java @@ -1,6 +1,21 @@ +/* + * Copyright 2023-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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.internal; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.Test; @@ -8,36 +23,36 @@ class GrpcUtilsTests { @Test void testGetPortFromAddress() { - assertEquals(8080, GrpcUtils.getPort("localhost:8080")); + assertThat(GrpcUtils.getPort("localhost:8080")).isEqualTo(8080); } @Test void testGetNoPort() { - assertEquals(9090, GrpcUtils.getPort("localhost")); + assertThat(GrpcUtils.getPort("localhost")).isEqualTo(9090); } @Test void testGetPortFromAddressWithPath() { String address = "example.com:1234/path"; - assertEquals(1234, GrpcUtils.getPort(address)); + assertThat(GrpcUtils.getPort(address)).isEqualTo(1234); } @Test void testGetDomainAddress() { String address = "unix:/some/file/somewhere"; - assertEquals(-1, GrpcUtils.getPort(address)); + assertThat(GrpcUtils.getPort(address)).isEqualTo(-1); } @Test void testGetStaticSchema() { String address = "static://localhost"; - assertEquals(9090, GrpcUtils.getPort(address)); + assertThat(GrpcUtils.getPort(address)).isEqualTo(9090); } @Test void testGetInvalidAddress() { String address = "invalid:broken"; - assertEquals(9090, GrpcUtils.getPort(address)); // -1? + assertThat(GrpcUtils.getPort(address)).isEqualTo(9090); // -1? } -} \ No newline at end of file +} diff --git a/spring-grpc-docs/pom.xml b/spring-grpc-docs/pom.xml index 707586bb..45d67443 100644 --- a/spring-grpc-docs/pom.xml +++ b/spring-grpc-docs/pom.xml @@ -19,6 +19,7 @@ ${project.basedir}/src/main/antora/modules/ROOT/partials/_configprops.adoc spring.grpc.* 9.4.6.0 + true @@ -215,4 +216,4 @@ - \ No newline at end of file + diff --git a/spring-grpc-docs/src/main/antora/modules/ROOT/pages/contribution-guidelines.adoc b/spring-grpc-docs/src/main/antora/modules/ROOT/pages/contribution-guidelines.adoc index 05ffc778..debe7790 100644 --- a/spring-grpc-docs/src/main/antora/modules/ROOT/pages/contribution-guidelines.adoc +++ b/spring-grpc-docs/src/main/antora/modules/ROOT/pages/contribution-guidelines.adoc @@ -11,6 +11,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. +[NOTE] +==== +We use the https://github.com/spring-io/spring-javaformat[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 https://github.com/spring-projects-experimental/spring-grpc/wiki/Working-with-the-Code#install-the-spring-formatter-plugin[has been installed]. +==== + == Contributing a New GRPC Features To contribute a new feature, adhere to the following steps: @@ -103,4 +110,3 @@ You may also be asked to rework the submission. If asked to make corrections, simply push the changes against the same branch, and your pull request will be updated. In other words, you do not need to create a new pull request when asked to make changes. - diff --git a/spring-grpc-spring-boot-autoconfigure/pom.xml b/spring-grpc-spring-boot-autoconfigure/pom.xml index 74f57b2a..eaa8fa05 100644 --- a/spring-grpc-spring-boot-autoconfigure/pom.xml +++ b/spring-grpc-spring-boot-autoconfigure/pom.xml @@ -20,6 +20,10 @@ git@github.com:spring-projects-experimental/spring-grpc.git + + true + + @@ -101,4 +105,4 @@ - \ No newline at end of file + diff --git a/src/checkstyle/checkstyle-header.txt b/src/checkstyle/checkstyle-header.txt new file mode 100644 index 00000000..965e455a --- /dev/null +++ b/src/checkstyle/checkstyle-header.txt @@ -0,0 +1,14 @@ +^\Q/*\E$ +^\Q * Copyright \E20\d\d(\-20\d\d)?\Q the original author or authors.\E$ +^\Q *\E$ +^\Q * Licensed under the Apache License, Version 2.0 (the "License");\E$ +^\Q * you may not use this file except in compliance with the License.\E$ +^\Q * You may obtain a copy of the License at\E$ +^\Q *\E$ +^\Q * https://www.apache.org/licenses/LICENSE-2.0\E$ +^\Q *\E$ +^\Q * Unless required by applicable law or agreed to in writing, software\E$ +^\Q * distributed under the License is distributed on an "AS IS" BASIS,\E$ +^\Q * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\E$ +^\Q * See the License for the specific language governing permissions and\E$ +^\Q * limitations under the License.\E$ diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml new file mode 100644 index 00000000..b1b406d7 --- /dev/null +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml new file mode 100644 index 00000000..283f96fd --- /dev/null +++ b/src/checkstyle/checkstyle.xml @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +