Skip to content

Commit

Permalink
Adds Spotless configuration for Java (#2485)
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenbaker authored Dec 20, 2024
1 parent 50eb16d commit 472a3d5
Show file tree
Hide file tree
Showing 1,763 changed files with 17,919 additions and 26,164 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
distribution: 'corretto'

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

- name: Allow long file names in git for windows
if: matrix.os == 'windows-latest'
Expand Down
1 change: 0 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies {
implementation(libs.spotbugs)
implementation(libs.spotless)
implementation(libs.jmh)

// https://github.com/gradle/gradle/issues/15383
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
30 changes: 28 additions & 2 deletions buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import java.util.regex.Pattern

plugins {
checkstyle
id("com.diffplug.spotless")
}

// TODO: Add spotless java configuration
/*
* Formatting
* ==================
* see: https://github.com/diffplug/spotless/blob/main/plugin-gradle/README.md
*/
spotless {
java {
// Enforce a common license header on all files
licenseHeaderFile("${project.rootDir}/config/spotless/license-header.txt")
.onlyIfContentMatches("^((?!SKIPLICENSECHECK)[\\s\\S])*\$")
indentWithSpaces()
endWithNewline()
eclipse().configFile("${project.rootDir}/config/spotless/formatting.xml")
// Fixes for some strange formatting applied by eclipse:
// see: https://github.com/kamkie/demo-spring-jsf/blob/bcacb9dc90273a5f8d2569470c5bf67b171c7d62/build.gradle.kts#L159
custom("Lambda fix") { it.replace("} )", "})").replace("} ,", "},") }
custom("Long literal fix") { Pattern.compile("([0-9_]+) [Ll]").matcher(it).replaceAll("\$1L") }
// Static first, then everything else alphabetically
removeUnusedImports()
importOrder("\\#", "")
// Ignore generated code for formatter check
targetExclude("*/build/**/*.*")
}

// Formatting for build.gradle.kts files
kotlinGradle {
ktlint()
Expand All @@ -21,4 +39,12 @@ spotless {
"import|tasks|apply|plugins|rootProject"
)
}
tasks {
// If the property "noFormat" is set, don't auto-format source file (like in CI)
if(!project.hasProperty("noFormat")) {
build {
dependsOn(spotlessApply)
}
}
}
}
6 changes: 0 additions & 6 deletions buildSrc/src/main/kotlin/smithy.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ if (project.hasProperty("log-tests")) {
}
}

// ==== CheckStyle ====
// https://docs.gradle.org/current/userguide/checkstyle_plugin.html
tasks.named("checkstyleTest") {
enabled = false
}

// ==== Code coverage ====
// https://docs.gradle.org/current/userguide/jacoco_plugin.html

Expand Down
200 changes: 0 additions & 200 deletions config/checkstyle/checkstyle.xml

This file was deleted.

31 changes: 0 additions & 31 deletions config/checkstyle/suppressions.xml

This file was deleted.

Loading

0 comments on commit 472a3d5

Please sign in to comment.