Skip to content

Commit 5defb65

Browse files
build: fix PMD
Signed-off-by: Andreas Reichel <andreas@manticore-projects.com> Signed-off-by: manticore-projects <andreas@manticore-projects.com>
1 parent 209cb02 commit 5defb65

File tree

2 files changed

+55
-49
lines changed

2 files changed

+55
-49
lines changed

build.gradle

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,18 @@ javadoc {
222222
jar {
223223
manifest {
224224
attributes (
225-
"Automatic-Module-Name": "net.sf.jsqlparser"
225+
"Automatic-Module-Name": "net.sf.jsqlparser"
226226
)
227227
}
228228

229229
bundle {
230230
properties.empty()
231231
bnd(
232-
"Created-By": System.properties.get('user.name'),
233-
"Bundle-SymbolicName": "net.sf.jsqlparser",
234-
"Import-Package": "*",
235-
"Export-Package": "net.sf.jsqlparser.*",
236-
"Automatic-Module-Name": "net.sf.jsqlparser"
232+
"Created-By": System.properties.get('user.name'),
233+
"Bundle-SymbolicName": "net.sf.jsqlparser",
234+
"Import-Package": "*",
235+
"Export-Package": "net.sf.jsqlparser.*",
236+
"Automatic-Module-Name": "net.sf.jsqlparser"
237237
)
238238
}
239239

@@ -344,7 +344,7 @@ jacocoTestCoverageVerification {
344344

345345
//@todo: temporarily increased to 7000, we need to bring that down to 5500 after accepting the Keywords PR
346346
maximum = 20000
347-
}
347+
}
348348
excludes = [
349349
'net.sf.jsqlparser.util.validation.*',
350350
'net.sf.jsqlparser.**.*Adapter',
@@ -379,29 +379,31 @@ spotbugsMain {
379379
spotbugs {
380380
// fail only on P1 and without the net.sf.jsqlparser.parser.*
381381
excludeFilter = file("config/spotbugs/spotBugsExcludeFilter.xml")
382+
}
382383

383-
// do not run over the test, although we should do that eventually
384-
spotbugsTest.enabled = false
384+
// do not run over the test, although we should do that eventually
385+
tasks.named('spotbugsTest').configure {
386+
enabled = false
385387
}
386388

387389
pmd {
388-
rulesMinimumPriority = 5
390+
// later versions throw NPE
391+
toolVersion = '7.17.0'
389392

390393
consoleOutput = true
391394
sourceSets = [sourceSets.main]
392395

393396
// clear the ruleset in order to use configured rules only
394397
ruleSets = []
395-
396-
//rulesMinimumPriority = 1
398+
rulesMinimumPriority = 2
397399
ruleSetFiles = files("config/pmd/ruleset.xml")
400+
}
398401

399-
pmdMain {
400-
excludes = [
401-
"build/generated/*"
402-
, "**/net/sf/jsqlparser/parser/SimpleCharStream.java"
403-
]
404-
}
402+
tasks.named('pmdMain').configure {
403+
excludes = [
404+
"build/generated/*"
405+
, "**/net/sf/jsqlparser/parser/SimpleCharStream.java"
406+
]
405407
}
406408

407409
checkstyle {
@@ -464,18 +466,19 @@ tasks.register('renderRR') {
464466
}
465467

466468
// Convert JJ file to EBNF
467-
tasks.register("convertJJ", JavaExec) {
468-
standardOutput = new FileOutputStream(new File(rrDir, "JSqlParserCC.ebnf"))
469-
mainClass = "-jar"
469+
def ebnfFile = new File(rrDir, "JSqlParserCC.ebnf")
470+
project.javaexec {
471+
standardOutput = new FileOutputStream(ebnfFile)
472+
mainClass.set("-jar")
470473
args = [
471474
new File(rrDir, "convert.war").absolutePath,
472475
layout.buildDirectory.dir("generated/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jj").get().asFile.absolutePath
473476
]
474-
}.get().exec()
477+
}
475478

476479
// Generate RR diagrams
477-
tasks.register("generateRR", JavaExec) {
478-
mainClass = "-jar"
480+
project.javaexec {
481+
mainClass.set("-jar")
479482
args = [
480483
new File(rrDir, "rr.war").absolutePath,
481484
"-noepsilon",
@@ -485,7 +488,7 @@ tasks.register('renderRR') {
485488
"-out:${new File(rrDir, "JSqlParserCC.xhtml")}",
486489
new File(rrDir, "JSqlParserCC.ebnf").absolutePath
487490
]
488-
}.get().exec()
491+
}
489492
}
490493
}
491494

@@ -537,7 +540,7 @@ tasks.register('updateKeywords', JavaExec) {
537540
file('src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt').absolutePath
538541
, file('src/site/sphinx/keywords.rst').absolutePath
539542
]
540-
main("net.sf.jsqlparser.parser.ParserKeywordsUtils")
543+
mainClass.set("net.sf.jsqlparser.parser.ParserKeywordsUtils")
541544

542545
dependsOn(compileJava)
543546
}
@@ -735,4 +738,4 @@ jmh {
735738
fork = 3
736739
iterations = 5
737740
timeOnIteration = '1s'
738-
}
741+
}

config/pmd/ruleset.xml

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ under the License.
2020
<ruleset name="Default Maven PMD Plugin Ruleset" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
2121

2222
<description>
23-
The default ruleset used by the Maven PMD Plugin, when no other ruleset is specified.
24-
It contains the rules of the old (pre PMD 6.0.0) rulesets java-basic, java-empty, java-imports,
25-
java-unnecessary, java-unusedcode.
23+
Custom PMD ruleset, compatible with PMD 7.x.
2624

27-
This ruleset might be used as a starting point for an own customized ruleset [0].
25+
Based on the old (pre PMD 6.0.0) rulesets java-basic, java-empty, java-imports,
26+
java-unnecessary, java-unusedcode, migrated for PMD 7.
2827

29-
[0] https://pmd.github.io/latest/pmd_userdocs_making_rulesets.html
30-
</description>
28+
This ruleset might be used as a starting point for an own customized ruleset [0].
29+
30+
[0] https://pmd.github.io/latest/pmd_userdocs_making_rulesets.html
31+
</description>
3132

3233
<rule ref="category/java/bestpractices.xml/AvoidUsingHardCodedIP" />
3334
<rule ref="category/java/bestpractices.xml/CheckResultSet" />
@@ -46,6 +47,14 @@ under the License.
4647
<rule ref="category/java/codestyle.xml/UselessParentheses" />
4748
<rule ref="category/java/codestyle.xml/UselessQualifiedThis" />
4849

50+
<!-- PMD 7: replaces EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer,
51+
EmptyStatementBlock, EmptySwitchStatements, EmptySynchronizedBlock,
52+
EmptyTryBlock, EmptyWhileStmt (all removed in PMD 7) -->
53+
<rule ref="category/java/codestyle.xml/EmptyControlStatement" />
54+
55+
<!-- PMD 7: replaces EmptyStatementNotInLoop (removed in PMD 7) -->
56+
<rule ref="category/java/codestyle.xml/UnnecessarySemicolon" />
57+
4958
<rule ref="category/java/codestyle.xml/MethodNamingConventions">
5059
<properties>
5160
<property name="methodPattern" value="[a-z][a-zA-Z0-9]*" />
@@ -63,14 +72,15 @@ under the License.
6372
<rule ref="category/java/design.xml/UselessOverridingMethod" />
6473
<rule ref="category/java/design.xml/AvoidThrowingNullPointerException" />
6574

66-
6775
<rule ref="category/java/design.xml/CyclomaticComplexity">
6876
<properties>
6977
<property name="classReportLevel" value="200" />
7078
<property name="methodReportLevel" value="120" />
7179
</properties>
7280
</rule>
73-
<rule ref="category/java/design.xml/ExcessiveMethodLength" />
81+
82+
<!-- PMD 7: ExcessiveMethodLength was removed, use NcssCount instead -->
83+
<rule ref="category/java/design.xml/NcssCount" />
7484

7585
<rule ref="category/java/errorprone.xml/AvoidBranchingStatementAsLastInLoop" />
7686
<rule ref="category/java/errorprone.xml/AvoidDecimalLiteralsInBigDecimalConstructor" />
@@ -80,32 +90,25 @@ under the License.
8090
<rule ref="category/java/errorprone.xml/CheckSkipResult" />
8191
<rule ref="category/java/errorprone.xml/ClassCastExceptionWithToArray" />
8292
<rule ref="category/java/errorprone.xml/DontUseFloatTypeForLoopIndices" />
93+
94+
<!-- EmptyCatchBlock is explicitly kept as a separate rule in PMD 7 -->
8395
<rule ref="category/java/errorprone.xml/EmptyCatchBlock" />
84-
<rule ref="category/java/errorprone.xml/EmptyFinallyBlock" />
85-
<rule ref="category/java/errorprone.xml/EmptyIfStmt" />
86-
<rule ref="category/java/errorprone.xml/EmptyInitializer" />
87-
<rule ref="category/java/errorprone.xml/EmptyStatementBlock" />
88-
<rule ref="category/java/errorprone.xml/EmptyStatementNotInLoop" />
89-
<rule ref="category/java/errorprone.xml/EmptySwitchStatements" />
90-
<rule ref="category/java/errorprone.xml/EmptySynchronizedBlock" />
91-
<rule ref="category/java/errorprone.xml/EmptyTryBlock" />
92-
<rule ref="category/java/errorprone.xml/EmptyWhileStmt" />
96+
9397
<rule ref="category/java/errorprone.xml/JumbledIncrementer" />
9498
<rule ref="category/java/errorprone.xml/MisplacedNullCheck" />
9599
<rule ref="category/java/errorprone.xml/OverrideBothEqualsAndHashcode" />
96100
<rule ref="category/java/errorprone.xml/ReturnFromFinallyBlock" />
97101
<rule ref="category/java/errorprone.xml/UnconditionalIfStatement" />
98102
<rule ref="category/java/errorprone.xml/UnnecessaryConversionTemporary" />
99103
<rule ref="category/java/errorprone.xml/UnusedNullCheckInEquals" />
100-
<rule ref="category/java/errorprone.xml/UselessOperationOnImmutable" />
101-
102-
<!-- for Codazy -->
104+
105+
<!-- for Codazy -->
103106
<rule ref="category/java/multithreading.xml/AvoidThreadGroup" />
104107
<rule ref="category/java/multithreading.xml/DontCallThreadRun" />
105108
<rule ref="category/java/multithreading.xml/DoubleCheckedLocking" />
106109

107110
<rule ref="category/java/performance.xml/BigIntegerInstantiation" />
108111

109-
<!-- for Codazy -->
112+
<!-- for Codazy -->
110113
<!-- <rule ref="category/java/documentation.xml/UncommentedEmptyMethodBody" /> -->
111-
</ruleset>
114+
</ruleset>

0 commit comments

Comments
 (0)