Skip to content

Commit 472a3d5

Browse files
authored
Adds Spotless configuration for Java (#2485)
1 parent 50eb16d commit 472a3d5

1,763 files changed

Lines changed: 17919 additions & 26164 deletions

File tree

Some content is hidden

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

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
distribution: 'corretto'
2727

2828
- name: Clean, build, test, and javadoc
29-
run: ./gradlew clean build javadoc -Plog-tests --stacktrace
29+
run: ./gradlew clean build javadoc -PnoFormat -Plog-tests --stacktrace
3030

3131
- name: Allow long file names in git for windows
3232
if: matrix.os == 'windows-latest'

buildSrc/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ dependencies {
1212
implementation(libs.spotbugs)
1313
implementation(libs.spotless)
1414
implementation(libs.jmh)
15-
1615
// https://github.com/gradle/gradle/issues/15383
1716
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
1817
}

buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1+
import java.util.regex.Pattern
2+
13
plugins {
2-
checkstyle
34
id("com.diffplug.spotless")
45
}
56

6-
// TODO: Add spotless java configuration
77
/*
88
* Formatting
99
* ==================
1010
* see: https://github.com/diffplug/spotless/blob/main/plugin-gradle/README.md
1111
*/
1212
spotless {
13+
java {
14+
// Enforce a common license header on all files
15+
licenseHeaderFile("${project.rootDir}/config/spotless/license-header.txt")
16+
.onlyIfContentMatches("^((?!SKIPLICENSECHECK)[\\s\\S])*\$")
17+
indentWithSpaces()
18+
endWithNewline()
19+
eclipse().configFile("${project.rootDir}/config/spotless/formatting.xml")
20+
// Fixes for some strange formatting applied by eclipse:
21+
// see: https://github.com/kamkie/demo-spring-jsf/blob/bcacb9dc90273a5f8d2569470c5bf67b171c7d62/build.gradle.kts#L159
22+
custom("Lambda fix") { it.replace("} )", "})").replace("} ,", "},") }
23+
custom("Long literal fix") { Pattern.compile("([0-9_]+) [Ll]").matcher(it).replaceAll("\$1L") }
24+
// Static first, then everything else alphabetically
25+
removeUnusedImports()
26+
importOrder("\\#", "")
27+
// Ignore generated code for formatter check
28+
targetExclude("*/build/**/*.*")
29+
}
30+
1331
// Formatting for build.gradle.kts files
1432
kotlinGradle {
1533
ktlint()
@@ -21,4 +39,12 @@ spotless {
2139
"import|tasks|apply|plugins|rootProject"
2240
)
2341
}
42+
tasks {
43+
// If the property "noFormat" is set, don't auto-format source file (like in CI)
44+
if(!project.hasProperty("noFormat")) {
45+
build {
46+
dependsOn(spotlessApply)
47+
}
48+
}
49+
}
2450
}

buildSrc/src/main/kotlin/smithy.java-conventions.gradle.kts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ if (project.hasProperty("log-tests")) {
106106
}
107107
}
108108

109-
// ==== CheckStyle ====
110-
// https://docs.gradle.org/current/userguide/checkstyle_plugin.html
111-
tasks.named("checkstyleTest") {
112-
enabled = false
113-
}
114-
115109
// ==== Code coverage ====
116110
// https://docs.gradle.org/current/userguide/jacoco_plugin.html
117111

config/checkstyle/checkstyle.xml

Lines changed: 0 additions & 200 deletions
This file was deleted.

config/checkstyle/suppressions.xml

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)