Skip to content

Commit c3891b5

Browse files
authored
Checkstyle suppression in code where possible (helidon-io#7588)
Updated dev guidelines Using https endpoints for configuration files schema locations
1 parent 1e1c60c commit c3891b5

8 files changed

Lines changed: 44 additions & 91 deletions

File tree

DEV-GUIDELINES.md

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ Some of these rules are enforced by checkstyle, some are checked during code rev
1212
# General coding rules
1313
1. Use unchecked Throwables - descendants of RuntimeException in API
1414
1. Never use RuntimeException directly - always create a descendant appropriate for your module, or
15-
use an existing exception declared in the module
15+
use an existing exception declared in the module
1616
2. Our APIs should never throw a checked exception unless enforced by implemented/extended interface - e.g. when
17-
we implement a java.io.Closeable, we must declare the checked exception.
18-
1. Usage of `null` is discouraged and should not exist in any public APIs of Helidon
17+
we implement a java.io.Closeable, we must declare the checked exception.
18+
3. In some cases we may use existing runtime exceptions if they fit the problem (`NoSuchElementException`, `IllegalStateException`)
19+
2. Usage of `null` is discouraged and should not exist in any public APIs of Helidon
1920
1. If a method accepts a `null`, refactor it to a different approach
2021
- a setter: create a method to remove the field value rather than setting a `null` value
2122
(such as `host(String)` to set a host, and `unsetHost()` to revert to default value)
@@ -70,9 +71,7 @@ Some of these rules are enforced by checkstyle, some are checked during code rev
7071
2. Default: component has a well defined and documented default value for such a property
7172
3. Optional: component behaves in a well defined and documented manner if such a property is not
7273
configured (e.g. a component may expect tracing endpoint - if not defined, tracing may be disabled)
73-
5. We have introduced `helidon-builder` module, that provides capability to generate builders that support both programmatic and configuration approach. See [helidon-builder](builder/README.md) for more details about modules, and [helidon-builder-api](builder/api/README.md) for explanation of APIs and naming rules. The `Blueprint` approach should be used for all builders (and the API of the prototype). Exceptions must be consulted with project architect (this may result in either changing the processor to support the required feature, or in removing such feature and redesigning the problem, or in an exception (documented) to the rule)
74-
75-
Example: [io.helidon.faulttolerance.RetryConfigBlueprint](nima/fault-tolerance/fault-tolerance/src/main/java/io/helidon/nima/faulttolerance/RetryConfigBlueprint.java)
74+
5. We have introduced `helidon-builder` module, see [Builders](#Builders)
7675

7776
# Getters and Setters
7877
1. We do not use the verb, e.g. when a property "port" exists, the following methods are used:
@@ -90,6 +89,11 @@ Example: [io.helidon.security.providers.oidc.common.OidcConfig](security/provide
9089
2. When using control methods (such as Server server = Server.create().start())
9190

9291
# Builders
92+
We have introduced code generation for builders that enforces the rules mentioned below.
93+
94+
See [helidon-builder](builder/README.md) for more details about modules, and [helidon-builder-api](builder/api/README.md) for explanation of APIs and naming rules. The `Blueprint` approach should be used for all builders (and the API of the prototype). Exceptions must be consulted with project architect (this may result in either changing the processor to support the required feature, or in removing such feature and redesigning the problem, or in an exception (documented) to the rule).
95+
96+
9397
1. We use builders to create instances that need any parameters for construction
9498
1. **This implies that there are no public API classes that would use public constructors**
9599
2. Allowed exceptions to this rule:
@@ -112,24 +116,16 @@ Example: [io.helidon.security.providers.oidc.common.OidcConfig](security/provide
112116
"success(Subject subject)" etc. - **these methods MUST use builder to build the instance internally**
113117
5. An internal class named "Builder" that is building instances of the containing class
114118
1. it is allowed to have the builder as a top level class, in such a case the name must reflect the class it is
115-
building (e.g. FooBarBuilder)
116-
3. Builder class
117-
1. Must have:
118-
1. Implements "io.helidon.common.Builder<FooBar>"
119-
2. All methods configuring the builder return a builder instance with updated configuration
120-
3. Validation done either on setters or in method build() (latest) - e.g. we should fail to
121-
build an instance if the configuration is not correct
122-
2. May have:
123-
1. May accept other classes that are built using a builder, either directly, or as Supplier<T>
124-
(as builder implements Supplier, this allows us to pass a builder to such a method, as well as a nice lambda)
125-
126-
Example: [io.helidon.security.providers.oidc.common.OidcConfig](security/providers/oidc-common/src/main/java/io/helidon/security/oidc/common/OidcConfig.java)
119+
building (e.g. FooBarBuilder)
120+
121+
Example: [io.helidon.faulttolerance.RetryConfigBlueprint](nima/fault-tolerance/fault-tolerance/src/main/java/io/helidon/nima/faulttolerance/RetryConfigBlueprint.java)
127122

128123
# JPMS
129124
1. Each java module that is released has a `module-info.java`
130125
2. Provided services of released modules are declared ONLY in `module-info.java`, `META-INF/services` is generated
131126
automatically by a Maven plugin. `META-INF/services` in sources of released modules will fail the build
132127
3. Javadoc is using modules, so do not forget to add javadoc to `module-info.java`
128+
4. Provided and used services should be always using fully qualified class names
133129

134130
# Testing
135131

config/config/src/main/java/io/helidon/config/ClasspathConfigSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2023 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

etc/checkstyle-suppressions.xml

Lines changed: 21 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -19,85 +19,38 @@
1919

2020
<!DOCTYPE suppressions PUBLIC
2121
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
22-
"http://checkstyle.sourceforge.net/dtds/suppressions_1_1.dtd">
22+
"https://checkstyle.sourceforge.net/dtds/suppressions_1_1.dtd">
2323

24+
<!--
25+
Use in Helidon:
26+
This file is used when running the aggregate report (and configuration in modules is ignored in that case).
27+
This file SHOULD ONLY contain exclusions for whole modules where appropriate.
28+
Single check exclusions should be handled through @SuppressWarning("checkstyle:....") annotation.
29+
30+
Only exceptional cases that cannot be handled through annotations may be provided here.
31+
This is to keep the checkstyle exclusions co-located with the code, so if the code changes, we do not leave an outdated
32+
record here.
33+
-->
2434
<suppressions>
25-
<!-- to do comment suppression for to do project -->
26-
<suppress checks="TodoComment"
27-
files="examples/todo-app/.*"/>
28-
29-
<suppress checks="FileLength"
30-
files="config/config/src/main/java/io/helidon/config/Config.java|integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaExtension\.java|security/providers/oidc-common/src/main/java/io/helidon/security/providers/oidc/common/OidcConfig\.java"
31-
lines="1"/>
32-
33-
<!-- Java comments with AsciiDoc tag:: and end:: in import section incorrectly flagged
34-
as unacceptable blank lines within a package's imports. -->
35-
<suppress checks="ImportOrder"
36-
files="examples/guides/se-restful-webservice/src/main/java/io/helidon/guides/se/restfulwebservice/Main.java"/>
37-
<suppress checks="ImportOrder"
38-
files="examples/guides/se-restful-webservice/src/main/java/io/helidon/guides/se/restfulwebservice/GreetService.java"/>
39-
<suppress checks="NoWhitespaceBefore|SeparatorWrap"
40-
files="examples/guides/mp-restful-webservice/src/main/java/io/helidon/guides/mp/restfulwebservice/GreetApplication.java"/>
4135
<!--
42-
The following files are work taken over from other projects,
43-
where we want to keep the author tag untouched
36+
- File exclusions (exceptions)
37+
- FileLength cannot be excluded using a @SuppressWarnings
4438
-->
45-
<!-- Common HTTP project -->
46-
<suppress id="Javadoc.javadocNoAuthor"
47-
files="common/http/Preconditions\.java|common/http/Ascii\.java|common/http/CharMatcher\.java"/>
48-
<!-- Webserver project -->
49-
<suppress id="Javadoc.javadocNoAuthor"
50-
files="webserver/UriComponent\.java"/>
51-
52-
<!-- Building a Graph involves a lot of instanceof checks and state manipulation. -->
53-
<suppress checks="MethodLength"
54-
files="HelidonReactiveStreamsEngine\.java"/>
55-
56-
<!-- PKCS#1 private keys - required for OCI Instance Principal Authentication -->
57-
<suppress checks="IllegalImport"
58-
files="DerUtils\.java"/>
59-
60-
<!-- this is a record style, all parameters are always needed, no benefit of changing to builder -->
61-
<suppress files="webserver/http2/src/main/java/io/helidon/webserver/http2/spi/Http2SubProtocolSelector.java"
62-
checks="ParameterNumber"/>
63-
64-
<!-- this is a record style, all parameters are always needed, no benefit of changing to builder -->
65-
<suppress files="webserver/webserver/src/main/java/io/helidon/webserver/ConnectionContext.java"
66-
checks="ParameterNumber"/>
67-
68-
<!-- this is a record style, all parameters are always needed, no benefit of changing to builder -->
69-
<suppress files="webserver/webserver/src/main/java/io/helidon/webserver/http1/Http1ServerRequest.java"
70-
checks="ParameterNumber"/>
71-
7239
<!-- the huffman constants are long, but this is not actual code, just a set of constants -->
73-
<suppress files="http/http2/src/main/java/io/helidon/http/http2/Http2HuffmanConstants.java"
40+
<suppress files="http/http2/src/main/java/io/helidon/http/http2/Http2HuffmanConstants\.java"
7441
checks="FileLength"/>
7542

76-
<suppress files="webserver/benchmark/"
77-
checks=".*"/>
78-
79-
<!-- builder brings no benefit, all parameters always needed -->
80-
<suppress files="webserver/http2/webserver/src/main/java/io/helidon/webserver/http2/spi/Http2SubProtocolProvider.java"
81-
checks="ParameterNumber"/>
82-
83-
<!-- builder brings no benefit, all parameters always needed, and a private method -->
84-
<suppress files="src/main/java/io/helidon/metrics/serviceapi/PrometheusFormat.java"
85-
checks="ParameterNumber"/>
43+
<suppress files="integrations/cdi/jpa-cdi/src/main/java/io/helidon/integrations/cdi/jpa/JpaExtension\.java"
44+
checks="FileLength"/>
8645

87-
<!-- builder brings no benefit, all parameters always needed, and a private method -->
88-
<suppress files="microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/NonJaxRsResource.java"
89-
checks="ParameterNumber"/>
46+
<!--
47+
- Module exclusions
48+
-->
9049

91-
<!-- builder exclusions -->
92-
<suppress files="builder/tests/builder/src/main/java/io/helidon/builder/test/testsubjects/.*"
50+
<!-- JMH benchmark is not required to follow code style -->
51+
<suppress files="webserver/benchmark/"
9352
checks=".*"/>
9453

95-
<!-- interfaces implemented by generated code, ensuring methods don't interfere with the interlaced methods from the user -->
96-
<suppress files="builder/builder-config/src/main/java/io/helidon/builder/config/spi/GeneratedConfig.*.java"
97-
checks="MethodName"/>
98-
<suppress files="builder/builder-config/src/main/java/io/helidon/builder/config/spi/ConfigProvider.java"
99-
checks="MethodName"/>
100-
10154
<!-- injection tests need to violate to check different user scenarios -->
10255
<suppress files="builder/tests/"
10356
checks=".*"/>

etc/checkstyle.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright (c) 2016, 2022 Oracle and/or its affiliates.
4+
Copyright (c) 2016, 2023 Oracle and/or its affiliates.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -17,7 +17,8 @@
1717
1818
-->
1919

20-
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
20+
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
21+
"https://www.puppycrawl.com/dtds/configuration_1_3.dtd">
2122
<!--
2223
This file is based on maven-checkstyle-plugin config/sun_checks.xml file.
2324
Checkstyle configuration that checks the coding conventions based on:

microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/NonJaxRsResource.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ private void handleRequest(ServerRequest req, ServerResponse res) {
119119
}
120120
}
121121

122+
@SuppressWarnings("checkstyle:ParameterNumber") // all parameters required, no benefit using a record wrapper
122123
private void handleRequest(ServerRequest req,
123124
ServerResponse res,
124125
String type,

microprofile/reactive-streams/src/main/java/io/helidon/microprofile/reactive/HelidonReactiveStreamsEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -126,7 +126,7 @@ static void requireNullTerminal(Object o, Stage stage) {
126126
}
127127
}
128128

129-
@SuppressWarnings({ "unchecked", "rawtypes" })
129+
@SuppressWarnings({ "unchecked", "rawtypes", "checkstyle:MethodLength" }) // lot of instanceof checks required, long method
130130
static Object build(Iterable<Stage> graph, Mode mode) throws UnsupportedStageException {
131131
Flow.Subscriber graphInlet = null;
132132
Multi result = null;

webserver/http2/src/main/java/io/helidon/webserver/http2/spi/Http2SubProtocolSelector.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public interface Http2SubProtocolSelector {
5353
* @param router router
5454
* @return sub-protocol result
5555
*/
56+
@SuppressWarnings("checkstyle:ParameterNumber") // all parameters required, no benefit using a record wrapper
5657
SubProtocolResult subProtocol(ConnectionContext ctx,
5758
HttpPrologue prologue,
5859
Http2Headers headers,

webserver/webserver/src/main/java/io/helidon/webserver/http1/Http1ServerRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ static Http1ServerRequest create(ConnectionContext ctx,
8181
/*
8282
* Create a new request with an entity.
8383
*/
84+
@SuppressWarnings("checkstyle:ParameterNumber") // all parameters are always needed, record would not bring any benefit
8485
static Http1ServerRequest create(ConnectionContext ctx,
8586
Http1Connection connection,
8687
Http1Config http1Config,

0 commit comments

Comments
 (0)