@@ -3,8 +3,6 @@ plugins {
3
3
id " java-library"
4
4
5
5
id " com.diffplug.spotless"
6
- id " checkstyle"
7
-
8
6
id " jacoco"
9
7
}
10
8
@@ -52,9 +50,6 @@ tasks.withType( JavaCompile ).configureEach {javaCompile->
52
50
options. warnings false
53
51
}
54
52
55
- tasks. named( " checkstyleMain" ) {
56
- dependsOn( tasks. named( " spotlessJavaApply" ) )
57
- }
58
53
59
54
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60
55
// Javadoc
@@ -95,15 +90,46 @@ spotless {
95
90
96
91
97
92
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98
- // Checkstyle
93
+ // Enforced rules
99
94
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100
95
101
- checkstyle {
102
- sourceSets = [ project. sourceSets. main ]
103
- showViolations = false
96
+ def enforceRulesTask = tasks. register( " enforceRules" ) {
97
+ description " Enforces some formatting rules to src/main/java files"
98
+ doLast {
99
+ def illegalImport = ~/ ^import (sun|java.awt|org.slf4j)/
100
+ def missingNewline = ~/ ^\s *}\s *(else|catch|finally)/
101
+ def lowerEll = ~/ \b\d +l\b /
102
+ def errors = 0
103
+ def tree = fileTree( " src/main/java/" )
104
+ tree. include " **/*.java"
105
+ tree. each { file ->
106
+ def lineNum = 0
107
+ def shortName = file. path. substring( rootDir. path. length() )
108
+ file. eachLine { line ->
109
+ lineNum++
110
+ if ( line =~ illegalImport ) {
111
+ errors++
112
+ logger. error( " Illegal import in ${ shortName} \n ${ lineNum} : ${ line} " )
113
+ }
114
+ if ( line =~ missingNewline ) {
115
+ errors++
116
+ logger. error( " Missing newline in ${ shortName} \n ${ lineNum} : ${ line} " )
117
+ }
118
+ if ( line =~ lowerEll ) {
119
+ errors++
120
+ logger. error( " Lowercase long literal in ${ shortName} \n ${ lineNum} : ${ line} " )
121
+ }
122
+ }
123
+ }
124
+ if ( errors > 0 ) {
125
+ throw new GradleException ( " Code rules were violated ($errors problems)" )
126
+ }
127
+ }
104
128
}
105
129
106
130
131
+
132
+
107
133
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
108
134
// JaCoCo
109
135
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -121,5 +147,7 @@ jacocoTestReport {
121
147
}
122
148
123
149
tasks. named( " check" ) {
150
+ dependsOn enforceRulesTask
151
+ dependsOn tasks. named( " spotlessCheck" )
124
152
dependsOn jacocoReportTask
125
153
}
0 commit comments