Skip to content

Commit 72001b5

Browse files
author
Vova Kolmakov
committed
build: add spotless, checkstyle, and enforcer plugin configuration
1 parent fa2ea76 commit 72001b5

3 files changed

Lines changed: 283 additions & 0 deletions

File tree

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
[*.java]
10+
indent_style = space
11+
indent_size = 4
12+
max_line_length = 100
13+
14+
[*.{xml,yml,yaml}]
15+
indent_style = space
16+
indent_size = 2
17+
18+
[Makefile]
19+
indent_style = tab

checkstyle.xml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<!--
2+
~ Licensed to the Apache Software Foundation (ASF) under one or more
3+
~ contributor license agreements. See the NOTICE file distributed with
4+
~ this work for additional information regarding copyright ownership.
5+
~ The ASF licenses this file to You under the Apache License, Version 2.0
6+
~ (the "License"); you may not use this file except in compliance with
7+
~ the License. You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<!DOCTYPE module PUBLIC
19+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
20+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
21+
22+
<module name = "Checker">
23+
<property name="charset" value="UTF-8"/>
24+
25+
<property name="severity" value="error"/>
26+
27+
<property name="fileExtensions" value="java, properties, xml"/>
28+
29+
<!-- Checks for whitespace -->
30+
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
31+
<module name="FileTabCharacter">
32+
<property name="eachLine" value="true"/>
33+
</module>
34+
35+
<module name="RegexpSingleline">
36+
<!-- \s matches whitespace character, $ matches end of line. -->
37+
<property name="format" value="\s+$"/>
38+
<property name="message" value="No trailing whitespace allowed."/>
39+
</module>
40+
41+
<module name="LineLength">
42+
<property name="max" value="100"/>
43+
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
44+
</module>
45+
46+
<module name="TreeWalker">
47+
<!--
48+
If you wish to turn off checking for a section of code, you can put a comment in the source
49+
before and after the section, with the following syntax:
50+
51+
// checkstyle.off: XXX (such as checkstyle.off: NoFinalizer)
52+
... // stuff that breaks the styles
53+
// checkstyle.on: XXX (such as checkstyle.on: NoFinalizer)
54+
-->
55+
<module name="SuppressionCommentFilter">
56+
<property name="offCommentFormat" value="checkstyle\.off\: ([\w\|]+)"/>
57+
<property name="onCommentFormat" value="checkstyle\.on\: ([\w\|]+)"/>
58+
<property name="checkFormat" value="$1"/>
59+
</module>
60+
<module name="OuterTypeFilename"/>
61+
<module name="IllegalTokenText">
62+
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
63+
<property name="format" value="\\u00(08|09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
64+
<property name="message" value="Avoid using corresponding octal or Unicode escape."/>
65+
</module>
66+
<module name="AvoidEscapedUnicodeCharacters">
67+
<property name="allowEscapesForControlCharacters" value="true"/>
68+
<property name="allowByTailComment" value="true"/>
69+
<property name="allowNonPrintableEscapes" value="true"/>
70+
</module>
71+
<module name="NoLineWrap"/>
72+
<module name="EmptyBlock">
73+
<property name="option" value="TEXT"/>
74+
<property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
75+
</module>
76+
<module name="NeedBraces">
77+
<property name="allowSingleLineStatement" value="true"/>
78+
</module>
79+
<module name="OneStatementPerLine"/>
80+
<module name="ArrayTypeStyle"/>
81+
<module name="FallThrough"/>
82+
<module name="UpperEll"/>
83+
<module name="ModifierOrder"/>
84+
<module name="SeparatorWrap">
85+
<property name="tokens" value="DOT"/>
86+
<property name="option" value="nl"/>
87+
</module>
88+
<module name="SeparatorWrap">
89+
<property name="tokens" value="COMMA"/>
90+
<property name="option" value="EOL"/>
91+
</module>
92+
<module name="PackageName">
93+
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
94+
<message key="name.invalidPattern"
95+
value="Package name ''{0}'' must match pattern ''{1}''."/>
96+
</module>
97+
<module name="ClassTypeParameterName">
98+
<property name="format" value="([A-Z][a-zA-Z0-9]*$)"/>
99+
<message key="name.invalidPattern"
100+
value="Class type name ''{0}'' must match pattern ''{1}''."/>
101+
</module>
102+
<module name="MethodTypeParameterName">
103+
<property name="format" value="([A-Z][a-zA-Z0-9]*)"/>
104+
<message key="name.invalidPattern"
105+
value="Method type name ''{0}'' must match pattern ''{1}''."/>
106+
</module>
107+
<module name="GenericWhitespace">
108+
<message key="ws.followed"
109+
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
110+
<message key="ws.preceded"
111+
value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
112+
<message key="ws.illegalFollow"
113+
value="GenericWhitespace ''{0}'' should followed by whitespace."/>
114+
<message key="ws.notPreceded"
115+
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
116+
</module>
117+
<module name="MethodParamPad"/>
118+
<module name="AnnotationLocation">
119+
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
120+
</module>
121+
<module name="AnnotationLocation">
122+
<property name="tokens" value="VARIABLE_DEF"/>
123+
<property name="allowSamelineMultipleAnnotations" value="true"/>
124+
</module>
125+
<module name="MethodName">
126+
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
127+
<message key="name.invalidPattern"
128+
value="Method name ''{0}'' must match pattern ''{1}''."/>
129+
</module>
130+
<module name="EmptyCatchBlock">
131+
<property name="exceptionVariableName" value="expected"/>
132+
</module>
133+
<module name="CommentsIndentation"/>
134+
<module name="UnusedImports"/>
135+
<module name="RedundantImport"/>
136+
<module name="RedundantModifier"/>
137+
<module name="RegexpSinglelineJava">
138+
<property name="format" value="throw new \w+Error\("/>
139+
<property name="message" value="Avoid throwing error in application code."/>
140+
</module>
141+
<module name="RegexpSinglelineJava">
142+
<property name="format" value="Objects\.toStringHelper"/>
143+
<property name="message" value="Avoid using Object.toStringHelper. Use ToStringBuilder instead." />
144+
</module>
145+
<module name="RegexpSinglelineJava">
146+
<property name="format" value="new (java\.lang\.)?(Byte|Integer|Long|Short)\("/>
147+
<property name="message" value="Use static factory 'valueOf' or 'parseXXX' instead of the deprecated constructors." />
148+
</module>
149+
<module name="RegexpSinglelineJava">
150+
<property name="format" value="Files\.createTempDir\("/>
151+
<property name="message"
152+
value="Avoid using com.google.common.io.Files.createTempDir() due to CVE-2020-8908. Use java.nio.file.Files.createTempDirectory() instead." />
153+
</module>
154+
<module name="RegexpSinglelineJava">
155+
<property name="format" value="FileBackedOutputStream"/>
156+
<property name="message" value="Avoid using FileBackedOutputStream due to CVE-2023-2976." />
157+
</module>
158+
<module name="RegexpSinglelineJava">
159+
<property name="format" value="AtomicDoubleArray"/>
160+
<property name="message" value="Avoid using AtomicDoubleArray due to CVE-2018-10237." />
161+
</module>
162+
<module name="RegexpSinglelineJava">
163+
<property name="format" value="CompoundOrdering"/>
164+
<property name="message" value="Avoid using CompoundOrdering due to CVE-2018-10237." />
165+
</module>
166+
<module name="RegexpSinglelineJava">
167+
<property name="format" value="@Test\(expected"/>
168+
<property name="message" value="Please use the `assertThrows` method to test for exceptions." />
169+
</module>
170+
<module name="IllegalImport">
171+
<property name="illegalPkgs" value="org.apache.log4j,org.apache.commons.lang" />
172+
</module>
173+
</module>
174+
</module>

pom.xml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@
2727
<log4j.version>2.20.0</log4j.version>
2828
<mockito.version>5.3.1</mockito.version>
2929
<assertj.version>3.24.2</assertj.version>
30+
31+
<!-- Code style tooling -->
32+
<spotless.version>2.43.0</spotless.version>
33+
<spotless.java.googlejavaformat.version>1.19.2</spotless.java.googlejavaformat.version>
34+
<spotless.delimiter>package</spotless.delimiter>
35+
<spotless.license.header>
36+
/*
37+
* Licensed under the Apache License, Version 2.0 (the "License");
38+
* you may not use this file except in compliance with the License.
39+
* You may obtain a copy of the License at
40+
*
41+
* http://www.apache.org/licenses/LICENSE-2.0
42+
*
43+
* Unless required by applicable law or agreed to in writing, software
44+
* distributed under the License is distributed on an "AS IS" BASIS,
45+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
46+
* See the License for the specific language governing permissions and
47+
* limitations under the License.
48+
*/
49+
</spotless.license.header>
50+
<maven-checkstyle-plugin.version>3.3.1</maven-checkstyle-plugin.version>
51+
<maven-enforcer-plugin.version>3.4.1</maven-enforcer-plugin.version>
3052
</properties>
3153

3254
<dependencies>
@@ -345,6 +367,74 @@
345367
</execution>
346368
</executions>
347369
</plugin>
370+
371+
<!-- Spotless code formatter (invoked explicitly: mvn spotless:check / spotless:apply) -->
372+
<plugin>
373+
<groupId>com.diffplug.spotless</groupId>
374+
<artifactId>spotless-maven-plugin</artifactId>
375+
<version>${spotless.version}</version>
376+
<configuration>
377+
<upToDateChecking>
378+
<enabled>true</enabled>
379+
</upToDateChecking>
380+
<java>
381+
<includes>
382+
<include>src/main/java/**/*.java</include>
383+
<include>src/test/java/**/*.java</include>
384+
</includes>
385+
<googleJavaFormat>
386+
<version>${spotless.java.googlejavaformat.version}</version>
387+
<style>GOOGLE</style>
388+
</googleJavaFormat>
389+
<importOrder>
390+
<order>org.apache.flink,,javax,java,\#</order>
391+
</importOrder>
392+
<removeUnusedImports/>
393+
</java>
394+
<licenseHeader>
395+
<content>${spotless.license.header}</content>
396+
<delimiter>${spotless.delimiter}</delimiter>
397+
</licenseHeader>
398+
</configuration>
399+
</plugin>
400+
401+
<!-- Checkstyle (invoked explicitly: mvn checkstyle:check) -->
402+
<plugin>
403+
<groupId>org.apache.maven.plugins</groupId>
404+
<artifactId>maven-checkstyle-plugin</artifactId>
405+
<version>${maven-checkstyle-plugin.version}</version>
406+
<configuration>
407+
<configLocation>checkstyle.xml</configLocation>
408+
<consoleOutput>true</consoleOutput>
409+
<failsOnError>true</failsOnError>
410+
<violationSeverity>warning</violationSeverity>
411+
<linkXRef>false</linkXRef>
412+
</configuration>
413+
</plugin>
414+
415+
<!-- Enforcer: Maven version + ban duplicate dependency versions -->
416+
<plugin>
417+
<groupId>org.apache.maven.plugins</groupId>
418+
<artifactId>maven-enforcer-plugin</artifactId>
419+
<version>${maven-enforcer-plugin.version}</version>
420+
<executions>
421+
<execution>
422+
<id>enforce-versions</id>
423+
<phase>validate</phase>
424+
<goals>
425+
<goal>enforce</goal>
426+
</goals>
427+
<configuration>
428+
<rules>
429+
<requireMavenVersion>
430+
<version>3.6.3</version>
431+
</requireMavenVersion>
432+
<banDuplicatePomDependencyVersions/>
433+
</rules>
434+
</configuration>
435+
</execution>
436+
</executions>
437+
</plugin>
348438
</plugins>
349439
</build>
350440

0 commit comments

Comments
 (0)