Skip to content

Commit 62fac35

Browse files
Sync spotless changes (#153)
- Add spotless configuration top level - Speed up formatting by defining formatted sources explicitly and avoid using **
1 parent 0fa6438 commit 62fac35

File tree

2 files changed

+50
-27
lines changed

2 files changed

+50
-27
lines changed

build.gradle

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ plugins {
1313
alias(libs.plugins.aggregate.javadoc)
1414
}
1515

16+
apply from: 'formattedSources.gradle'
17+
18+
spotless {
19+
java {
20+
target(formatExtension("java"))
21+
targetExclude("*/src/test/**")
22+
importOrder()
23+
googleJavaFormat()
24+
endWithNewline()
25+
toggleOffOn('formatter:off', 'formatter:on')
26+
}
27+
kotlin {
28+
target(formatExtension("kt"))
29+
ktlint()
30+
endWithNewline()
31+
toggleOffOn('formatter:off', 'formatter:on')
32+
}
33+
groovyGradle {
34+
target("*/*.gradle")
35+
greclipse()
36+
endWithNewline()
37+
toggleOffOn('formatter:off', 'formatter:on')
38+
}
39+
}
40+
1641
allprojects {
1742
group = 'com.guardsquare'
1843
version = proguardCoreVersion
@@ -34,23 +59,6 @@ allprojects {
3459
javadoc {
3560
options.addStringOption('Xdoclint:none', '-quiet')
3661
}
37-
38-
spotless {
39-
java {
40-
importOrder()
41-
googleJavaFormat()
42-
endWithNewline()
43-
}
44-
}
45-
}
46-
47-
pluginManager.withPlugin('kotlin') {
48-
spotless {
49-
kotlin {
50-
ktlint()
51-
endWithNewline()
52-
}
53-
}
5462
}
5563

5664
tasks.withType(KotlinCompile).configureEach {
@@ -65,16 +73,6 @@ allprojects {
6573
.configureEach {
6674
compilerOptions.languageVersion = KotlinVersion.KOTLIN_1_8
6775
}
68-
69-
apply plugin: 'com.diffplug.spotless'
70-
71-
spotless {
72-
groovyGradle {
73-
greclipse()
74-
endWithNewline()
75-
toggleOffOn('formatter:off', 'formatter:on')
76-
}
77-
}
7876
}
7977

8078
dependencies {

formattedSources.gradle

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.nio.file.Files
2+
import java.nio.file.Paths
3+
4+
def formattedSourcesPaths = [
5+
"base/src",
6+
"android/src",
7+
"examples/src",
8+
"tools/src",
9+
]
10+
11+
project.ext.formatExtension = { String fileExtension ->
12+
def rootDir = project.rootDir
13+
def folders = formattedSourcesPaths.collect { path -> "$rootDir${File.separator}$path" }
14+
def nonexistentPaths = folders.findAll { path -> Files.notExists(Paths.get(path)) }.join("\n")
15+
if (!nonexistentPaths.isEmpty()){
16+
throw new IllegalArgumentException("Formatted sources contains non existing paths:\n$nonexistentPaths")
17+
}
18+
def nonSrcPaths = folders.findAll { path -> !path.endsWith("/src") }.join("\n")
19+
if (!nonSrcPaths.isEmpty()) {
20+
throw new IllegalArgumentException(
21+
"The following paths do not end with /src:\n$nonSrcPaths\n" +
22+
"Not specifying the src directory can lead to intermediate build files being scanned.")
23+
}
24+
return folders.collect { fileTree(dir: it).include("**/*.${fileExtension}") }.flatten()
25+
}

0 commit comments

Comments
 (0)