Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 57 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,48 @@ spotless {
"termux/**/*",
)

// Dirs to PRUNE during the walk. Passing a fileTree to target() bypasses
// Spotless's auto-prune of .git/.gradle/build, so restore them. flox is the
// ADFA-4816 fix: its /nix/store symlinks (millions of files) made
// spotlessCheck take 12+ minutes.
// Bare dir names required: Gradle prunes a subtree only when an exclude
// matches the dir node itself; `dir/**` matches contents and forces a
// descend-and-filter (no pruning).
val traversalExcludes =
arrayOf(
"flox",
"**/.flox",
"**/.git",
"**/.gradle",
)

// Gradle build-output dirs (root + subprojects), relative to rootDir. Not
// "**/build": source packages named `build` exist (e.g.
// app/src/main/java/.../actions/build) and would be dropped.
val buildOutputExcludes =
allprojects
.map {
it.layout.buildDirectory
.get()
.asFile
.relativeTo(rootDir)
.invariantSeparatorsPath
}.filter { it.isNotEmpty() && !it.startsWith("..") }
.toTypedArray()

// Target tree with the shared excludes applied; format-specific ones go in
// extraExcludes.
fun spotlessTarget(
vararg includes: String,
extraExcludes: Array<String> = emptyArray(),
) = fileTree(rootDir) {
include(*includes)
exclude(*commonTargetExcludes)
exclude(*traversalExcludes)
exclude(*buildOutputExcludes)
exclude(*extraExcludes)
}

// ALWAYS use line feeds (LF -- '\n')
lineEndings = LineEnding.UNIX

Expand Down Expand Up @@ -181,8 +223,7 @@ spotless {
},
)

target("**/src/*/java/**/*.java")
targetExclude(*commonTargetExcludes)
target(spotlessTarget("**/src/*/java/**/*.java"))
}

kotlin {
Expand All @@ -197,10 +238,11 @@ spotless {
endWithNewline()

target(
"**/src/*/java/**/*.kt",
"**/src/*/kotlin/**/*.kt",
spotlessTarget(
"**/src/*/java/**/*.kt",
"**/src/*/kotlin/**/*.kt",
),
)
targetExclude(*commonTargetExcludes)

suppressLintsFor {
// suppress the 'file name <some-file> should conform PascalCase' errors
Expand All @@ -215,8 +257,7 @@ spotless {
trimTrailingWhitespace()
endWithNewline()

target("**/*.gradle.kts")
targetExclude(*commonTargetExcludes)
target(spotlessTarget("**/*.gradle.kts"))
}

format("xml") {
Expand All @@ -227,22 +268,22 @@ spotless {
trimTrailingWhitespace()
endWithNewline()

target("**/src/*/res/**/*.xml")
targetExclude(*commonTargetExcludes)

// Formatting strings.xml with Eclipse WTP causes the strings to be
// split into multiple lines, which is not what we want.
// Exclude strings.xml from this rule.
targetExclude("**/src/*/res/values*/strings.xml")
// Eclipse WTP splits strings.xml entries across lines, so exclude it.
target(
spotlessTarget(
"**/src/*/res/**/*.xml",
extraExcludes = arrayOf("**/src/*/res/values*/strings.xml"),
),
)
}

format("misc") {
leadingSpacesToTabs()
trimTrailingWhitespace()
endWithNewline()

target("**/.gitignore", "**/.gradle")
targetExclude(*commonTargetExcludes)
// Only .gitignore; `.gradle` is a cache dir, pruned via traversalExcludes.
target(spotlessTarget("**/.gitignore"))
}

shell {
Expand Down
Loading