Skip to content

Commit

Permalink
Bump Spotless to v7
Browse files Browse the repository at this point in the history
This updates spotless to v7

Kotlin lambdas can't be serialized effectively by {spotless / gradle}
right now so this replaces those lambdas with anonymous classes that
implement `FormatterFunc`
  • Loading branch information
JordonPhillips committed Feb 26, 2025
1 parent 5891534 commit 559eec1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
22 changes: 18 additions & 4 deletions buildSrc/src/main/kotlin/smithy.formatting-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.diffplug.spotless.FormatterFunc
import java.io.Serializable
import java.util.regex.Pattern

plugins {
Expand All @@ -14,13 +16,25 @@ spotless {
// Enforce a common license header on all files
licenseHeaderFile("${project.rootDir}/config/spotless/license-header.txt")
.onlyIfContentMatches("^((?!SKIPLICENSECHECK)[\\s\\S])*\$")
indentWithSpaces()
leadingTabsToSpaces()
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") }
// These have to be implemented with anonymous classes this way instead of lambdas because of:
// https://github.com/diffplug/spotless/issues/2387
custom("Lambda fix", object : Serializable, FormatterFunc {
override fun apply(input: String) : String {
return input.replace("} )", "})").replace("} ,", "},")
}
})
custom("Long literal fix", object : Serializable, FormatterFunc {
override fun apply(input: String) : String {
return Pattern.compile("([0-9_]+) [Ll]").matcher(input).replaceAll("\$1L")
}
})

// Static first, then everything else alphabetically
removeUnusedImports()
importOrder("\\#", "")
Expand All @@ -31,7 +45,7 @@ spotless {
// Formatting for build.gradle.kts files
kotlinGradle {
ktlint()
indentWithSpaces()
leadingTabsToSpaces()
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ junit5 = "5.11.3"
hamcrest = "3.0"
jmh = "0.6.6"
spotbugs = "6.0.22"
spotless = "6.25.0"
spotless = "7.0.2"
smithy-gradle = "1.1.0"
assertj = "3.26.3"
prettier4j = "0.1.1"
Expand Down Expand Up @@ -56,4 +56,4 @@ smithy-jar = { id = "software.amazon.smithy.gradle.smithy-jar", version.ref = "s
shadow = { id = "com.gradleup.shadow", version.ref = "shadow" }
jreleaser = { id = "org.jreleaser", version.ref = "jreleaser" }
runtime = { id = "org.beryx.runtime", version.ref = "runtime"}
checksum = { id = "org.gradle.crypto.checksum", version.ref = "gradle-checksum" }
checksum = { id = "org.gradle.crypto.checksum", version.ref = "gradle-checksum" }
17 changes: 12 additions & 5 deletions smithy-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,15 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
// This is needed in order for integration tests to find the CLI runtime image
val smithyBinary =
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
layout.buildDirectory.file("image/smithy-cli-$imageOs/bin/smithy.bat").get().asFile.path
layout.buildDirectory
.file("image/smithy-cli-$imageOs/bin/smithy.bat")
.get()
.asFile.path
} else {
layout.buildDirectory.file("image/smithy-cli-$imageOs/bin/smithy").get().asFile.path
layout.buildDirectory
.file("image/smithy-cli-$imageOs/bin/smithy")
.get()
.asFile.path
}
System.setProperty("SMITHY_BINARY", smithyBinary)

Expand Down Expand Up @@ -142,9 +148,10 @@ runtime {
// is configured for the runtime
// NOTE: For the runtime task, you *must* have the right JDK set up in your environment (17 at the time of writing)
javaHome =
javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(imageJreVersion))
}.map { it.metadata.installationPath.asFile.path }
javaToolchains
.launcherFor {
languageVersion.set(JavaLanguageVersion.of(imageJreVersion))
}.map { it.metadata.installationPath.asFile.path }
}

tasks {
Expand Down

0 comments on commit 559eec1

Please sign in to comment.