@@ -7,42 +7,42 @@ import java.io.PrintWriter
77
88tasks {
99 register(" formatJava" ) {
10- val sourceSets = project.sourceSets
10+ val resultFilePath = " build/formatJava-result.txt"
11+ var files = project.sourceSets.flatMap { it.allSource }
12+ files = files.filter { it.name.endsWith(" .java" ) && " generated-src" !in it.absolutePath }
13+ inputs.files(files)
14+ outputs.file(project.file(resultFilePath))
1115 doLast {
1216 val formatter = Main (PrintWriter (System .out , true ), PrintWriter (System .err, true ), System .`in `)
13- for (item in sourceSets)
14- for (file in item.allSource) {
15- if (! file.name.endsWith(" .java" ) || " generated-src" in file.absolutePath)
16- continue
17- if (formatter.format(" -a" , " -i" , file.absolutePath) != 0 )
18- throw GradleException (" Format java failed: " + file.absolutePath)
17+ for (f in files) {
18+ if (formatter.format(" -a" , " -i" , f.absolutePath) != 0 ) {
19+ throw GradleException (" Format java failed: " + f.absolutePath)
1920 }
21+ }
22+ File (resultFilePath).writeText(" Success" )
2023 }
2124 }
2225
2326 val verifyJava by registering {
2427 val resultFilePath = " build/verifyJava-result.txt"
25- inputs.files(project.sourceSets.flatMap { it.allSource })
26- inputs.files(project.fileTree(" generated-src" ))
28+ var files = project.sourceSets.flatMap { it.allSource }
29+ files = files.filter { it.name.endsWith(" .java" ) && " generated-src" !in it.absolutePath }
30+ inputs.files(files)
2731 outputs.file(project.file(resultFilePath))
28-
29- val proj = project
3032 doLast {
3133 val formatter = Main (PrintWriter (System .out , true ), PrintWriter (System .err, true ), System .`in `)
32- for (item in proj.sourceSets)
33- for (file in item.allSource) {
34- if (! file.name.endsWith(" .java" ) || " generated-src" in file.absolutePath)
35- continue
36- if (formatter.format(" -a" , " -n" , " --set-exit-if-changed" , file.absolutePath) != 0 )
37- throw GradleException (
38- " File not formatted: " + file.absolutePath
39- + System .lineSeparator()
40- + " In order to reformat your code, run './gradlew formatJava' (or './gradlew fJ' for short)"
41- + System .lineSeparator()
42- + " See https://github.com/deepjavalibrary/djl/blob/master/docs/development/development_guideline.md#coding-conventions for more details"
43- )
34+ for (f in files) {
35+ if (formatter.format(" -a" , " -n" , " --set-exit-if-changed" , f.absolutePath) != 0 ) {
36+ throw GradleException (
37+ " File not formatted: " + f.absolutePath
38+ + System .lineSeparator()
39+ + " In order to reformat your code, run './gradlew formatJava' (or './gradlew fJ' for short)"
40+ + System .lineSeparator()
41+ + " See https://github.com/deepjavalibrary/djl/blob/master/docs/development/development_guideline.md#coding-conventions for more details"
42+ )
4443 }
45- proj.file(resultFilePath).writeText(" Success" )
44+ }
45+ File (resultFilePath).writeText(" Success" )
4646 }
4747 }
4848
0 commit comments