Skip to content

Commit 7e8a34e

Browse files
authored
chore(codegen): apply spotless eclipse formatting (#7573)
1 parent 83462d2 commit 7e8a34e

File tree

88 files changed

+4727
-3487
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+4727
-3487
lines changed

codegen/build.gradle.kts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
import org.jreleaser.model.Active
1717
import com.github.spotbugs.snom.Effort
18+
import java.io.Serializable
19+
import java.util.regex.Pattern
20+
import com.diffplug.spotless.FormatterFunc
1821

1922
plugins {
2023
`java-library`
@@ -24,6 +27,7 @@ plugins {
2427
jacoco
2528
id("com.github.spotbugs") version "6.3.0"
2629
id("org.jreleaser") version "1.20.0"
30+
id("com.diffplug.spotless") version "8.1.0"
2731
}
2832

2933
allprojects {
@@ -253,6 +257,62 @@ subprojects {
253257
excludeFilter.set(excludeFile)
254258
}
255259
}
260+
261+
apply(plugin = "com.diffplug.spotless")
262+
263+
spotless {
264+
java {
265+
// Enforce a common license header on all files
266+
licenseHeaderFile("${project.rootDir}/gradleConfig/spotless/license-header.txt")
267+
.onlyIfContentMatches("^((?!SKIPLICENSECHECK)[\\s\\S])*\$")
268+
leadingTabsToSpaces()
269+
endWithNewline()
270+
eclipse().configFile("${project.rootDir}/gradleConfig/spotless/formatting.xml")
271+
272+
// Fixes for some strange formatting applied by eclipse:
273+
// see: https://github.com/kamkie/demo-spring-jsf/blob/bcacb9dc90273a5f8d2569470c5bf67b171c7d62/build.gradle.kts#L159
274+
// These have to be implemented with anonymous classes this way instead of lambdas because of:
275+
// https://github.com/diffplug/spotless/issues/2387
276+
custom(
277+
"Lambda fix",
278+
object : Serializable, FormatterFunc {
279+
override fun apply(input: String): String = input.replace("} )", "})").replace("} ,", "},")
280+
},
281+
)
282+
custom(
283+
"Long literal fix",
284+
object : Serializable, FormatterFunc {
285+
override fun apply(input: String): String = Pattern.compile("([0-9_]+) [Ll]").matcher(input).replaceAll("\$1L")
286+
},
287+
)
288+
289+
// Static first, then everything else alphabetically
290+
removeUnusedImports()
291+
importOrder("\\#", "")
292+
// Ignore generated code for formatter check
293+
targetExclude("*/build/**/*.*")
294+
}
295+
296+
// Formatting for build.gradle.kts files
297+
kotlinGradle {
298+
ktlint()
299+
leadingTabsToSpaces()
300+
trimTrailingWhitespace()
301+
endWithNewline()
302+
licenseHeaderFile(
303+
"${project.rootDir}/gradleConfig/spotless/license-header.txt",
304+
"import|tasks|apply|plugins|rootProject",
305+
)
306+
}
307+
tasks {
308+
// If the property "noFormat" is set, don't auto-format source file (like in CI)
309+
if (!project.hasProperty("noFormat")) {
310+
build {
311+
dependsOn(spotlessApply)
312+
}
313+
}
314+
}
315+
}
256316
}
257317
}
258318

codegen/gradleConfig/checkstyle/checkstyle.xml

Lines changed: 3 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
-->
66

77
<!DOCTYPE module PUBLIC
8-
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
9-
"https://checkstyle.org/dtds/configuration_1_3.dtd">
8+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
9+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
1010

1111
<module name="Checker">
1212
<module name="SuppressWarningsFilter"/>
@@ -19,30 +19,16 @@
1919
<property name="fileNamePattern" value="(module\-info\.java$|Test.java$|src/test/java)"/>
2020
</module>
2121

22-
<!-- Files must contain a copyright header. -->
22+
<!-- Files must contain a copyright header without a year. The check for 2019-2023 is retained for historical purposes. -->
2323
<module name="RegexpHeader">
2424
<property name="header"
2525
value="/\*\n \* Copyright( 20(19|20|21|22|23)|) Amazon\.com, Inc\. or its affiliates\. All Rights Reserved\.\n"/>
2626
<property name="fileExtensions" value="java"/>
2727
</module>
2828

29-
<module name="NewlineAtEndOfFile">
30-
<property name="lineSeparator" value="lf_cr_crlf"/>
31-
</module>
32-
33-
<!-- See http://checkstyle.sf.net/config_sizes.html -->
34-
<module name="LineLength">
35-
<property name="max" value="${checkstyle.linelength}" default="120"/>
36-
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
37-
</module>
38-
3929
<!-- Checks for whitespace -->
4030
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
4131
<module name="FileTabCharacter"/>
42-
<module name="RegexpSingleline">
43-
<property name="format" value="\s+$"/>
44-
<property name="message" value="Line has trailing spaces."/>
45-
</module>
4632

4733
<module name="TreeWalker">
4834
<!-- Make comments and annotations available for the suppression comment filter. -->
@@ -97,65 +83,11 @@
9783
<property name="severity" value="warning"/>
9884
</module>
9985

100-
<!-- Checks for whitespace -->
101-
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
102-
<module name="EmptyForIteratorPad"/>
103-
<module name="GenericWhitespace"/>
104-
<module name="MethodParamPad"/>
105-
<module name="NoWhitespaceAfter"/>
106-
<module name="NoWhitespaceBefore"/>
107-
<module name="OperatorWrap"/>
108-
<module name="ParenPad"/>
109-
<module name="TypecastParenPad"/>
110-
<module name="WhitespaceAfter"/>
111-
<module name="WhitespaceAround">
112-
<property name="allowEmptyConstructors" value="true"/>
113-
<property name="allowEmptyMethods" value="true"/>
114-
<property name="allowEmptyTypes" value="true"/>
115-
<property name="allowEmptyLoops" value="true"/>
116-
</module>
117-
<module name="SeparatorWrap">
118-
<property name="id" value="SeparatorWrapDot"/>
119-
<property name="tokens" value="DOT"/>
120-
<property name="option" value="nl"/>
121-
</module>
122-
<module name="SeparatorWrap">
123-
<property name="id" value="SeparatorWrapComma"/>
124-
<property name="tokens" value="COMMA"/>
125-
<property name="option" value="EOL"/>
126-
</module>
127-
<module name="EmptyLineSeparator">
128-
<property name="allowNoEmptyLineBetweenFields" value="true"/>
129-
</module>
130-
13186
<!-- Modifier Checks -->
13287
<!-- See http://checkstyle.sf.net/config_modifiers.html -->
13388
<module name="ModifierOrder"/>
13489
<module name="RedundantModifier"/>
13590

136-
<!-- Checks for blocks. You know, those {}'s -->
137-
<!-- See http://checkstyle.sf.net/config_blocks.html -->
138-
<!-- Braces must not be empty for most language constructs. -->
139-
<module name="EmptyBlock">
140-
<property name="option" value="TEXT"/>
141-
<property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
142-
</module>
143-
<module name="LeftCurly"/>
144-
<module name="NeedBraces">
145-
<property name="allowEmptyLoopBody" value="true"/>
146-
</module>
147-
<module name="RightCurly">
148-
<property name="id" value="RightCurlySame"/>
149-
<property name="tokens"
150-
value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE"/>
151-
</module>
152-
<module name="RightCurly">
153-
<property name="id" value="RightCurlyAlone"/>
154-
<property name="option" value="alone"/>
155-
<property name="tokens"
156-
value="CLASS_DEF, METHOD_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT, INSTANCE_INIT"/>
157-
</module>
158-
15991
<!-- Checks for common coding problems -->
16092
<!-- See http://checkstyle.sf.net/config_coding.html -->
16193
<module name="EqualsHashCode"/>

0 commit comments

Comments
 (0)