Compare commits
52 commits
Author | SHA1 | Date | |
---|---|---|---|
9ea433edce | |||
86ea747ba2 | |||
9e8f6c0497 | |||
a15218eb1d | |||
7ae1650677 | |||
d304b931f9 | |||
355cdf770a | |||
4feba23b90 | |||
91c9556bd9 | |||
67ce6546fe | |||
cfbeeeb5c7 | |||
fb0acda205 | |||
e28496ca16 | |||
a2d37055c6 | |||
dca8baf3ad | |||
af25b2f507 | |||
25bce33323 | |||
e7fac3130b | |||
a1d0b30968 | |||
bc60dcbcf8 | |||
71253717bf | |||
28f9d29d9a | |||
682c50e949 | |||
6882490430 | |||
9184979e2f | |||
e7b366eaf0 | |||
dfdc311607 | |||
586e4a0e19 | |||
21edab586b | |||
f58d4ac052 | |||
c7e5731d9e | |||
4af11d862b | |||
5c33fd2a15 | |||
f46d75c2fe | |||
592c0c514d | |||
3b0550add2 | |||
22b7ab9220 | |||
a986add8ee | |||
d20f3e41b8 | |||
47c0b14ce9 | |||
176929cd29 | |||
3e18345efe | |||
2b6b4a5e82 | |||
e63c1a636e | |||
fec530d26e | |||
9cb3191dd4 | |||
a253342bd6 | |||
efce6b9729 | |||
03fd552702 | |||
f7216e6d11 | |||
12552137ee | |||
af395dd69b |
19 changed files with 767 additions and 231 deletions
17
.github/workflows/bld.yml
vendored
17
.github/workflows/bld.yml
vendored
|
@ -1,14 +1,16 @@
|
||||||
name: bld-ci
|
name: bld-ci
|
||||||
|
|
||||||
on: [push, pull_request, workflow_dispatch]
|
on: [ push, pull_request, workflow_dispatch ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-bld-project:
|
build-bld-project:
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
java-version: [17, 21, 22]
|
java-version: [ 17, 21, 24 ]
|
||||||
|
kotlin-version: [ 1.9.25, 2.0.21, 2.1.20 ]
|
||||||
|
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout source repository
|
- name: Checkout source repository
|
||||||
|
@ -22,11 +24,8 @@ jobs:
|
||||||
distribution: "zulu"
|
distribution: "zulu"
|
||||||
java-version: ${{ matrix.java-version }}
|
java-version: ${{ matrix.java-version }}
|
||||||
|
|
||||||
- name: Grant execute permission for bld
|
- name: Download dependencies
|
||||||
run: chmod +x bld
|
|
||||||
|
|
||||||
- name: Download the dependencies
|
|
||||||
run: ./bld download
|
run: ./bld download
|
||||||
|
|
||||||
- name: Run tests with bld
|
- name: Run tests
|
||||||
run: ./bld compile test
|
run: ./bld compile test
|
4
.github/workflows/pages.yml
vendored
4
.github/workflows/pages.yml
vendored
|
@ -47,11 +47,11 @@ jobs:
|
||||||
uses: actions/configure-pages@v3
|
uses: actions/configure-pages@v3
|
||||||
|
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-pages-artifact@v1
|
uses: actions/upload-pages-artifact@v3
|
||||||
with:
|
with:
|
||||||
# Upload generated Javadocs repository
|
# Upload generated Javadocs repository
|
||||||
path: "build/javadoc/"
|
path: "build/javadoc/"
|
||||||
|
|
||||||
- name: Deploy to GitHub Pages
|
- name: Deploy to GitHub Pages
|
||||||
id: deployment
|
id: deployment
|
||||||
uses: actions/deploy-pages@v1
|
uses: actions/deploy-pages@v4
|
||||||
|
|
6
.idea/bld.xml
generated
Normal file
6
.idea/bld.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="BldConfiguration">
|
||||||
|
<events />
|
||||||
|
</component>
|
||||||
|
</project>
|
13
.idea/icon.svg
generated
Normal file
13
.idea/icon.svg
generated
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
|
<svg width="100%" height="100%" viewBox="0 0 179 108" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
|
||||||
|
<g transform="matrix(1,0,0,1,-210.511,-96.3382)">
|
||||||
|
<g transform="matrix(1,0,0,1,-23.3386,-649.816)">
|
||||||
|
<g transform="matrix(0.221288,0,0,0.24,73.9536,390.254)">
|
||||||
|
<path d="M722.568,1482.92L722.568,1921.1L808.968,1921.1L808.968,1888.7C822.168,1907.9 846.168,1930.1 893.568,1930.1C933.168,1930.1 961.968,1917.5 985.368,1893.5C1012.97,1865.9 1027.37,1827.5 1027.37,1786.1C1027.37,1741.7 1011.17,1705.1 985.368,1680.5C961.968,1658.3 928.968,1644.5 892.368,1644.5C862.968,1644.5 830.568,1654.1 808.968,1683.5L808.968,1482.92L722.568,1482.92ZM871.368,1718.9C888.768,1718.9 903.768,1723.7 917.568,1736.9C930.168,1748.9 938.568,1766.3 938.568,1787.9C938.568,1807.7 930.168,1825.1 917.568,1837.1C904.368,1849.7 887.568,1855.7 872.568,1855.7C856.368,1855.7 837.168,1849.1 823.368,1835.9C813.168,1826.3 803.568,1810.1 803.568,1787.9C803.568,1765.1 812.568,1749.5 822.768,1738.7C836.568,1724.3 852.768,1718.9 871.368,1718.9Z" style="fill:rgb(35,146,255);fill-rule:nonzero;"/>
|
||||||
|
<rect x="1083.77" y="1482.92" width="86.4" height="438.182" style="fill:rgb(250,144,82);fill-rule:nonzero;"/>
|
||||||
|
<path d="M1531.37,1482.92L1444.97,1482.92L1444.97,1683.5C1423.37,1654.1 1390.97,1644.5 1361.57,1644.5C1324.97,1644.5 1291.97,1658.3 1268.57,1680.5C1242.77,1705.1 1226.57,1741.7 1226.57,1786.1C1226.57,1827.5 1240.97,1865.9 1268.57,1893.5C1291.97,1917.5 1320.77,1930.1 1360.37,1930.1C1407.77,1930.1 1431.77,1907.9 1444.97,1888.7L1444.97,1921.1L1531.37,1921.1L1531.37,1482.92ZM1382.57,1718.9C1401.17,1718.9 1417.37,1724.3 1431.17,1738.7C1441.37,1749.5 1450.37,1765.1 1450.37,1787.9C1450.37,1810.1 1440.77,1826.3 1430.57,1835.9C1416.77,1849.1 1397.57,1855.7 1381.37,1855.7C1366.37,1855.7 1349.57,1849.7 1336.37,1837.1C1323.77,1825.1 1315.37,1807.7 1315.37,1787.9C1315.37,1766.3 1323.77,1748.9 1336.37,1736.9C1350.17,1723.7 1365.17,1718.9 1382.57,1718.9Z" style="fill:rgb(35,146,255);fill-rule:nonzero;"/>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.4 KiB |
4
.idea/libraries/bld.xml
generated
4
.idea/libraries/bld.xml
generated
|
@ -2,12 +2,12 @@
|
||||||
<library name="bld">
|
<library name="bld">
|
||||||
<CLASSES>
|
<CLASSES>
|
||||||
<root url="file://$PROJECT_DIR$/lib/bld" />
|
<root url="file://$PROJECT_DIR$/lib/bld" />
|
||||||
<root url="jar://$USER_HOME$/.bld/dist/bld-1.9.1.jar!/" />
|
<root url="jar://$USER_HOME$/.bld/dist/bld-2.2.1.jar!/" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
<root url="file://$PROJECT_DIR$/lib/bld" />
|
<root url="file://$PROJECT_DIR$/lib/bld" />
|
||||||
<root url="jar://$USER_HOME$/.bld/dist/bld-1.9.1-sources.jar!/" />
|
<root url="jar://$USER_HOME$/.bld/dist/bld-2.2.1-sources.jar!/" />
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<excluded>
|
<excluded>
|
||||||
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
|
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
|
||||||
|
|
4
.idea/libraries/compile.xml
generated
4
.idea/libraries/compile.xml
generated
|
@ -7,7 +7,7 @@
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
<root url="file://$PROJECT_DIR$/lib/compile" />
|
<root url="file://$PROJECT_DIR$/lib/compile" />
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="false" />
|
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="true" />
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="false" type="SOURCES" />
|
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="true" type="SOURCES" />
|
||||||
</library>
|
</library>
|
||||||
</component>
|
</component>
|
4
.idea/libraries/runtime.xml
generated
4
.idea/libraries/runtime.xml
generated
|
@ -7,7 +7,7 @@
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
<root url="file://$PROJECT_DIR$/lib/runtime" />
|
<root url="file://$PROJECT_DIR$/lib/runtime" />
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib/runtime" recursive="false" />
|
<jarDirectory url="file://$PROJECT_DIR$/lib/runtime" recursive="true" />
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib/runtime" recursive="false" type="SOURCES" />
|
<jarDirectory url="file://$PROJECT_DIR$/lib/runtime" recursive="true" type="SOURCES" />
|
||||||
</library>
|
</library>
|
||||||
</component>
|
</component>
|
4
.idea/libraries/test.xml
generated
4
.idea/libraries/test.xml
generated
|
@ -7,7 +7,7 @@
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
<root url="file://$PROJECT_DIR$/lib/test" />
|
<root url="file://$PROJECT_DIR$/lib/test" />
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib/test" recursive="false" />
|
<jarDirectory url="file://$PROJECT_DIR$/lib/test" recursive="true" />
|
||||||
<jarDirectory url="file://$PROJECT_DIR$/lib/test" recursive="false" type="SOURCES" />
|
<jarDirectory url="file://$PROJECT_DIR$/lib/test" recursive="true" type="SOURCES" />
|
||||||
</library>
|
</library>
|
||||||
</component>
|
</component>
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -9,7 +9,7 @@
|
||||||
],
|
],
|
||||||
"java.configuration.updateBuildConfiguration": "automatic",
|
"java.configuration.updateBuildConfiguration": "automatic",
|
||||||
"java.project.referencedLibraries": [
|
"java.project.referencedLibraries": [
|
||||||
"${HOME}/.bld/dist/bld-1.9.1.jar",
|
"${HOME}/.bld/dist/bld-2.2.1.jar",
|
||||||
"lib/**/*.jar"
|
"lib/**/*.jar"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
14
README.md
14
README.md
|
@ -2,14 +2,22 @@
|
||||||
|
|
||||||
[](https://opensource.org/licenses/Apache-2.0)
|
[](https://opensource.org/licenses/Apache-2.0)
|
||||||
[](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html)
|
[](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html)
|
||||||
[](https://rife2.com/bld)
|
[](https://rife2.com/bld)
|
||||||
[](https://repo.rife2.com/#/releases/com/uwyn/rife2/bld-pmd)
|
[](https://repo.rife2.com/#/releases/com/uwyn/rife2/bld-pmd)
|
||||||
[](https://repo.rife2.com/#/snapshots/com/uwyn/rife2/bld-pmd)
|
[](https://repo.rife2.com/#/snapshots/com/uwyn/rife2/bld-pmd)
|
||||||
[](https://github.com/rife2/bld-pmd/actions/workflows/bld.yml)
|
[](https://github.com/rife2/bld-pmd/actions/workflows/bld.yml)
|
||||||
|
|
||||||
To install, please refer to the [extensions documentation](https://github.com/rife2/bld/wiki/Extensions).
|
To install the latest version, add the following to the `lib/bld/bld-wrapper.properties` file:
|
||||||
|
|
||||||
To check all source code using the [Java Quickstart](https://docs.pmd-code.org/latest/pmd_rules_java.html) configuration, add the following to your build file:
|
```properties
|
||||||
|
bld.extension-pmd=com.uwyn.rife2:bld-pmd
|
||||||
|
```
|
||||||
|
|
||||||
|
For more information, please refer to the [extensions](https://github.com/rife2/bld/wiki/Extensions) documentation.
|
||||||
|
|
||||||
|
## Check Source with PMD
|
||||||
|
|
||||||
|
To check all source Codecode using the [Java Quickstart](https://docs.pmd-code.org/latest/pmd_rules_java.html) configuration, add the following to your build file:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
@BuildCommand(summary = "Checks source code with PMD")
|
@BuildCommand(summary = "Checks source code with PMD")
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
<!-- BEST PRACTICES -->
|
<!-- BEST PRACTICES -->
|
||||||
<rule ref="category/java/bestpractices.xml">
|
<rule ref="category/java/bestpractices.xml">
|
||||||
<exclude name="AvoidPrintStackTrace"/>
|
<exclude name="AvoidPrintStackTrace"/>
|
||||||
<exclude name="JUnit4TestShouldUseTestAnnotation"/>
|
|
||||||
<exclude name="JUnitTestContainsTooManyAsserts"/>
|
|
||||||
<exclude name="GuardLogStatement"/>
|
<exclude name="GuardLogStatement"/>
|
||||||
|
<exclude name="UnitTestContainsTooManyAsserts"/>
|
||||||
|
<exclude name="UnitTestShouldUseTestAnnotation"/>
|
||||||
</rule>
|
</rule>
|
||||||
|
|
||||||
<rule ref="category/java/bestpractices.xml/MissingOverride">
|
<rule ref="category/java/bestpractices.xml/MissingOverride">
|
||||||
|
|
Binary file not shown.
|
@ -2,4 +2,4 @@ bld.downloadExtensionJavadoc=false
|
||||||
bld.downloadExtensionSources=true
|
bld.downloadExtensionSources=true
|
||||||
bld.downloadLocation=
|
bld.downloadLocation=
|
||||||
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||||
bld.version=1.9.1
|
bld.version=2.2.1
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2023-2024 the original author or authors.
|
* Copyright 2023-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -23,8 +23,7 @@ import rife.bld.publish.PublishScm;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static rife.bld.dependencies.Repository.MAVEN_CENTRAL;
|
import static rife.bld.dependencies.Repository.*;
|
||||||
import static rife.bld.dependencies.Repository.RIFE2_RELEASES;
|
|
||||||
import static rife.bld.dependencies.Scope.*;
|
import static rife.bld.dependencies.Scope.*;
|
||||||
import static rife.bld.operations.JavadocOptions.DocLinkOption.NO_MISSING;
|
import static rife.bld.operations.JavadocOptions.DocLinkOption.NO_MISSING;
|
||||||
|
|
||||||
|
@ -32,25 +31,25 @@ public class PmdOperationBuild extends Project {
|
||||||
public PmdOperationBuild() {
|
public PmdOperationBuild() {
|
||||||
pkg = "rife.bld.extension";
|
pkg = "rife.bld.extension";
|
||||||
name = "bld-pmd";
|
name = "bld-pmd";
|
||||||
version = version(1, 1, 0);
|
version = version(1, 2, 3);
|
||||||
|
|
||||||
javaRelease = 17;
|
javaRelease = 17;
|
||||||
|
|
||||||
downloadSources = true;
|
downloadSources = true;
|
||||||
autoDownloadPurge = true;
|
autoDownloadPurge = true;
|
||||||
repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);
|
|
||||||
|
|
||||||
var pmd = version(7, 2, 0);
|
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES, RIFE2_SNAPSHOTS);
|
||||||
|
|
||||||
|
var pmd = version(7, 13, 0);
|
||||||
scope(compile)
|
scope(compile)
|
||||||
.include(dependency("com.uwyn.rife2", "bld", version(1, 9, 1)))
|
.include(dependency("com.uwyn.rife2", "bld", version(2, 2, 1)))
|
||||||
.include(dependency("net.sourceforge.pmd", "pmd-java", pmd));
|
.include(dependency("net.sourceforge.pmd", "pmd-java", pmd));
|
||||||
scope(runtime)
|
scope(runtime)
|
||||||
.include(dependency("net.sourceforge.pmd", "pmd-java", pmd))
|
.include(dependency("org.slf4j", "slf4j-simple", version(2, 0, 17)));
|
||||||
.include(dependency("org.slf4j", "slf4j-simple", version(2, 0, 13)));
|
|
||||||
scope(test)
|
scope(test)
|
||||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2)))
|
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 12, 2)))
|
||||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2)))
|
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 12, 2)))
|
||||||
.include(dependency("org.assertj", "assertj-core", version(3, 26, 0)));
|
.include(dependency("org.assertj", "assertj-core", version(3, 27, 3)));
|
||||||
|
|
||||||
javadocOperation()
|
javadocOperation()
|
||||||
.javadocOptions()
|
.javadocOptions()
|
||||||
|
@ -61,29 +60,26 @@ public class PmdOperationBuild extends Project {
|
||||||
.link("https://javadoc.io/doc/net.sourceforge.pmd/pmd-core/latest/");
|
.link("https://javadoc.io/doc/net.sourceforge.pmd/pmd-core/latest/");
|
||||||
|
|
||||||
publishOperation()
|
publishOperation()
|
||||||
// .repository(MAVEN_LOCAL)
|
|
||||||
.repository(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2"))
|
.repository(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2"))
|
||||||
|
.repository(repository("github"))
|
||||||
.info()
|
.info()
|
||||||
.groupId("com.uwyn.rife2")
|
.groupId("com.uwyn.rife2")
|
||||||
.artifactId("bld-pmd")
|
.artifactId("bld-pmd")
|
||||||
.description("bld Extension to Perform Static Code Analysis with PMD")
|
.description("bld Extension to Perform Static Code Analysis with PMD")
|
||||||
.url("https://github.com/rife2/bld-pmd")
|
.url("https://github.com/rife2/bld-pmd")
|
||||||
.developer(
|
.developer(new PublishDeveloper()
|
||||||
new PublishDeveloper()
|
.id("ethauvin").name("Erik C. Thauvin")
|
||||||
.id("ethauvin").name("Erik C. Thauvin")
|
.email("erik@thauvin.net")
|
||||||
.email("erik@thauvin.net")
|
.url("https://erik.thauvin.net/")
|
||||||
.url("https://erik.thauvin.net/")
|
|
||||||
)
|
)
|
||||||
.license(
|
.license(new PublishLicense()
|
||||||
new PublishLicense()
|
.name("The Apache License, Version 2.0")
|
||||||
.name("The Apache License, Version 2.0")
|
.url("https://www.apache.org/licenses/LICENSE-2.0.txt")
|
||||||
.url("https://www.apache.org/licenses/LICENSE-2.0.txt")
|
|
||||||
)
|
)
|
||||||
.scm(
|
.scm(new PublishScm()
|
||||||
new PublishScm()
|
.connection("scm:git:https://github.com/rife2/bld-pmd.git")
|
||||||
.connection("scm:git:https://github.com/rife2/bld-pmd.git")
|
.developerConnection("scm:git:git@github.com:rife2/bld-pmd.git")
|
||||||
.developerConnection("scm:git:git@github.com:rife2/bld-pmd.git")
|
.url("https://github.com/rife2/bld-pmd")
|
||||||
.url("https://github.com/rife2/bld-pmd")
|
|
||||||
)
|
)
|
||||||
.signKey(property("sign.key"))
|
.signKey(property("sign.key"))
|
||||||
.signPassphrase(property("sign.passphrase"));
|
.signPassphrase(property("sign.passphrase"));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2023-2024 the original author or authors.
|
* Copyright 2023-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -22,6 +22,7 @@ import net.sourceforge.pmd.lang.LanguageVersion;
|
||||||
import net.sourceforge.pmd.lang.rule.RulePriority;
|
import net.sourceforge.pmd.lang.rule.RulePriority;
|
||||||
import rife.bld.BaseProject;
|
import rife.bld.BaseProject;
|
||||||
import rife.bld.operations.AbstractOperation;
|
import rife.bld.operations.AbstractOperation;
|
||||||
|
import rife.bld.operations.exceptions.ExitStatusException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -48,6 +49,10 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
public static final String RULE_SET_DEFAULT = "rulesets/java/quickstart.xml";
|
public static final String RULE_SET_DEFAULT = "rulesets/java/quickstart.xml";
|
||||||
private static final Logger LOGGER = Logger.getLogger(PmdOperation.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(PmdOperation.class.getName());
|
||||||
private static final String PMD_DIR = "pmd";
|
private static final String PMD_DIR = "pmd";
|
||||||
|
/**
|
||||||
|
* The list of paths to exclude.
|
||||||
|
*/
|
||||||
|
private final Collection<Path> excludes_ = new ArrayList<>();
|
||||||
/**
|
/**
|
||||||
* The input paths (source) list.
|
* The input paths (source) list.
|
||||||
*/
|
*/
|
||||||
|
@ -68,6 +73,10 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* The encoding.
|
* The encoding.
|
||||||
*/
|
*/
|
||||||
private Charset encoding_ = StandardCharsets.UTF_8;
|
private Charset encoding_ = StandardCharsets.UTF_8;
|
||||||
|
/**
|
||||||
|
* The fail on error toggle.
|
||||||
|
*/
|
||||||
|
private boolean failOnError_ = true;
|
||||||
/**
|
/**
|
||||||
* The fail on violation toggle.
|
* The fail on violation toggle.
|
||||||
*/
|
*/
|
||||||
|
@ -96,6 +105,10 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* The default language version(s).
|
* The default language version(s).
|
||||||
*/
|
*/
|
||||||
private Collection<LanguageVersion> languageVersions_ = new ArrayList<>();
|
private Collection<LanguageVersion> languageVersions_ = new ArrayList<>();
|
||||||
|
/**
|
||||||
|
* The classpath to prepend.
|
||||||
|
*/
|
||||||
|
private String prependClasspath_;
|
||||||
/**
|
/**
|
||||||
* The project reference.
|
* The project reference.
|
||||||
*/
|
*/
|
||||||
|
@ -129,6 +142,146 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
*/
|
*/
|
||||||
private int threads_ = 1;
|
private int threads_ = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds paths to exclude from the analysis.
|
||||||
|
*
|
||||||
|
* @param excludes one or more paths to exclude
|
||||||
|
* @return this operation
|
||||||
|
* @see #excludes(Path...)
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
public PmdOperation addExcludes(Path... excludes) {
|
||||||
|
return addExcludes(List.of(excludes));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds paths to exclude from the analysis.
|
||||||
|
*
|
||||||
|
* @param excludes paths to exclude
|
||||||
|
* @return this operation
|
||||||
|
* @see #excludes(Collection)
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
public PmdOperation addExcludes(Collection<Path> excludes) {
|
||||||
|
excludes_.addAll(excludes);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds paths to exclude from the analysis.
|
||||||
|
*
|
||||||
|
* @param excludes one or more paths to exclude
|
||||||
|
* @return this operation
|
||||||
|
* @see #excludesFiles(Collection)
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
public PmdOperation addExcludesFiles(Collection<File> excludes) {
|
||||||
|
return addExcludes(excludes.stream().map(File::toPath).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds paths to exclude from the analysis.
|
||||||
|
*
|
||||||
|
* @param excludes one or more paths to exclude
|
||||||
|
* @return this operation
|
||||||
|
* @see #excludesFiles(File...)
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
public PmdOperation addExcludesFiles(File... excludes) {
|
||||||
|
return addExcludesFiles(List.of(excludes));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds paths to exclude from the analysis.
|
||||||
|
*
|
||||||
|
* @param excludes one or more paths to exclude
|
||||||
|
* @return this operation
|
||||||
|
* @see #excludesStrings(Collection)
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
public PmdOperation addExcludesStrings(Collection<String> excludes) {
|
||||||
|
return addExcludes(excludes.stream().map(Paths::get).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds paths to exclude from the analysis.
|
||||||
|
*
|
||||||
|
* @param excludes one or more paths to exclude
|
||||||
|
* @return this operation
|
||||||
|
* @see #excludesStrings(String...)
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
public PmdOperation addExcludesStrings(String... excludes) {
|
||||||
|
return addExcludesStrings(List.of(excludes));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds paths to source files, or directories containing source files to analyze.\
|
||||||
|
*
|
||||||
|
* @param inputPath one or more paths
|
||||||
|
* @return this operation
|
||||||
|
* @see #inputPaths(Path...)
|
||||||
|
*/
|
||||||
|
public PmdOperation addInputPaths(Path... inputPath) {
|
||||||
|
return inputPaths(List.of(inputPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds paths to source files, or directories containing source files to analyze.
|
||||||
|
*
|
||||||
|
* @param inputPath one or more paths
|
||||||
|
* @return this operation
|
||||||
|
* @see #inputPaths(File...)
|
||||||
|
*/
|
||||||
|
public PmdOperation addInputPaths(File... inputPath) {
|
||||||
|
return addInputPathsFiles(List.of(inputPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds paths to source files, or directories containing source files to analyze.
|
||||||
|
*
|
||||||
|
* @param inputPath one or more paths
|
||||||
|
* @return this operation
|
||||||
|
* @see #inputPaths(String...)
|
||||||
|
*/
|
||||||
|
public PmdOperation addInputPaths(String... inputPath) {
|
||||||
|
return addInputPathsStrings(List.of(inputPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds paths to source files, or directories containing source files to analyze.
|
||||||
|
*
|
||||||
|
* @param inputPath a collection of input paths
|
||||||
|
* @return this operation
|
||||||
|
* @see #inputPaths(Collection)
|
||||||
|
*/
|
||||||
|
public PmdOperation addInputPaths(Collection<Path> inputPath) {
|
||||||
|
inputPaths_.addAll(inputPath);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds paths to source files, or directories containing source files to analyze.
|
||||||
|
*
|
||||||
|
* @param inputPath a collection of input paths
|
||||||
|
* @return this operation
|
||||||
|
* @see #inputPathsFiles(Collection)
|
||||||
|
*/
|
||||||
|
public PmdOperation addInputPathsFiles(Collection<File> inputPath) {
|
||||||
|
return addInputPaths(inputPath.stream().map(File::toPath).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds paths to source files, or directories containing source files to analyze.
|
||||||
|
*
|
||||||
|
* @param inputPath a collection of input paths
|
||||||
|
* @return this operation
|
||||||
|
* @see #inputPathsStrings(Collection)
|
||||||
|
*/
|
||||||
|
public PmdOperation addInputPathsStrings(Collection<String> inputPath) {
|
||||||
|
return addInputPaths(inputPath.stream().map(Paths::get).toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds new rule set paths.
|
* Adds new rule set paths.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -150,8 +303,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* @see #ruleSets(String...)
|
* @see #ruleSets(String...)
|
||||||
*/
|
*/
|
||||||
public PmdOperation addRuleSet(String... ruleSet) {
|
public PmdOperation addRuleSet(String... ruleSet) {
|
||||||
ruleSets_.addAll(List.of(ruleSet));
|
return addRuleSet(List.of(ruleSet));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -170,9 +322,9 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* <li>{@code category/java/security.xml}</li>
|
* <li>{@code category/java/security.xml}</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @param ruleSet one or more rule set
|
* @param ruleSet a collection of rule set paths
|
||||||
* @return this operation
|
* @return this operation
|
||||||
* @see #ruleSets(Collection
|
* @see #ruleSets(Collection)
|
||||||
*/
|
*/
|
||||||
public PmdOperation addRuleSet(Collection<String> ruleSet) {
|
public PmdOperation addRuleSet(Collection<String> ruleSet) {
|
||||||
ruleSets_.addAll(ruleSet);
|
ruleSets_.addAll(ruleSet);
|
||||||
|
@ -187,6 +339,20 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the location of the cache file for incremental analysis.
|
||||||
|
*/
|
||||||
|
public PmdOperation cache(File cache) {
|
||||||
|
return cache(cache.toPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the location of the cache file for incremental analysis.
|
||||||
|
*/
|
||||||
|
public PmdOperation cache(String cache) {
|
||||||
|
return cache(Path.of(cache));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default language version to be used for all input files.
|
* Sets the default language version to be used for all input files.
|
||||||
*
|
*
|
||||||
|
@ -194,14 +360,13 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* @return this operation
|
* @return this operation
|
||||||
*/
|
*/
|
||||||
public PmdOperation defaultLanguageVersions(LanguageVersion... languageVersion) {
|
public PmdOperation defaultLanguageVersions(LanguageVersion... languageVersion) {
|
||||||
languageVersions_.addAll(List.of(languageVersion));
|
return languageVersions(List.of(languageVersion));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default language version to be used for all input files.
|
* Sets the default language version to be used for all input files.
|
||||||
*
|
*
|
||||||
* @param languageVersion the language versions
|
* @param languageVersion a collection language versions
|
||||||
* @return this operation
|
* @return this operation
|
||||||
*/
|
*/
|
||||||
public PmdOperation defaultLanguageVersions(Collection<LanguageVersion> languageVersion) {
|
public PmdOperation defaultLanguageVersions(Collection<LanguageVersion> languageVersion) {
|
||||||
|
@ -215,8 +380,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* <p>The valid values are the standard character sets of {@link java.nio.charset.Charset Charset}.</p>
|
* <p>The valid values are the standard character sets of {@link java.nio.charset.Charset Charset}.</p>
|
||||||
*/
|
*/
|
||||||
public PmdOperation encoding(String encoding) {
|
public PmdOperation encoding(String encoding) {
|
||||||
encoding_ = Charset.forName(encoding);
|
return encoding(Charset.forName(encoding));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -230,13 +394,100 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets paths to exclude from the analysis.
|
||||||
|
*
|
||||||
|
* @param excludes one or more paths to exclude
|
||||||
|
* @return this operation
|
||||||
|
* @see #addExcludes(Path...)
|
||||||
|
*/
|
||||||
|
public PmdOperation excludes(Path... excludes) {
|
||||||
|
excludes(List.of(excludes));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets paths to exclude from the analysis.
|
||||||
|
*
|
||||||
|
* @param excludes paths to exclude
|
||||||
|
* @return this operation
|
||||||
|
* @see #addExcludes(Collection)
|
||||||
|
*/
|
||||||
|
public PmdOperation excludes(Collection<Path> excludes) {
|
||||||
|
excludes_.clear();
|
||||||
|
excludes_.addAll(excludes);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the paths to exclude from the analysis.
|
||||||
|
*
|
||||||
|
* @return the exclude paths
|
||||||
|
*/
|
||||||
|
public Collection<Path> excludes() {
|
||||||
|
return excludes_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets paths to exclude from the analysis.
|
||||||
|
*
|
||||||
|
* @param excludes one or more paths to exclude
|
||||||
|
* @return this operation
|
||||||
|
* @see #excludesFiles(Collection)
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
public PmdOperation excludesFiles(Collection<File> excludes) {
|
||||||
|
excludes(excludes.stream().map(File::toPath).toList());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets paths to exclude from the analysis.
|
||||||
|
*
|
||||||
|
* @param excludes one or more paths to exclude
|
||||||
|
* @return this operation
|
||||||
|
* @see #excludesFiles(File...)
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
public PmdOperation excludesFiles(File... excludes) {
|
||||||
|
return excludesFiles(List.of(excludes));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets paths to exclude from the analysis.
|
||||||
|
*
|
||||||
|
* @param excludes one or more paths to exclude
|
||||||
|
* @return this operation
|
||||||
|
* @see #excludesStrings(Collection)
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
public PmdOperation excludesStrings(Collection<String> excludes) {
|
||||||
|
excludes(excludes.stream().map(Paths::get).toList());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets paths to exclude from the analysis.
|
||||||
|
*
|
||||||
|
* @param excludes one or more paths to exclude
|
||||||
|
* @return this operation
|
||||||
|
* @see #excludesStrings(String...)
|
||||||
|
* @since 1.2.0
|
||||||
|
*/
|
||||||
|
public PmdOperation excludesStrings(String... excludes) {
|
||||||
|
return excludesStrings(List.of(excludes));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the PMD code analysis operation.
|
* Performs the PMD code analysis operation.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() throws Exception {
|
||||||
if (project_ == null) {
|
if (project_ == null) {
|
||||||
throw new IllegalArgumentException("ERROR: project required.");
|
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
|
||||||
|
LOGGER.log(Level.SEVERE, "A project is required to run this operation.");
|
||||||
|
}
|
||||||
|
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
var commandName = project_.getCurrentCommandName();
|
var commandName = project_.getCurrentCommandName();
|
||||||
|
@ -244,7 +495,28 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether the build will continue on warnings.
|
* Sets whether the build will exit on recoverable errors.
|
||||||
|
* <p>
|
||||||
|
* Default is: {@code true}
|
||||||
|
* <p>
|
||||||
|
* Note: If only violations are found, see {@link #failOnViolation(boolean) failOnViolation}
|
||||||
|
*
|
||||||
|
* @param failOnError whether to exit and fail the build if recoverable errors occurred
|
||||||
|
* @return this operation
|
||||||
|
* @see #failOnViolation(boolean)
|
||||||
|
*/
|
||||||
|
public PmdOperation failOnError(boolean failOnError) {
|
||||||
|
failOnError_ = failOnError;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the build will continue on violations.
|
||||||
|
* <p>
|
||||||
|
* Note: If additionally recoverable errors occurred, see {@link #failOnError(boolean) failOnError}
|
||||||
|
*
|
||||||
|
* @param failOnViolation whether to exit and fail the build if violations are found
|
||||||
|
* @return this operation
|
||||||
*/
|
*/
|
||||||
public PmdOperation failOnViolation(boolean failOnViolation) {
|
public PmdOperation failOnViolation(boolean failOnViolation) {
|
||||||
failOnViolation_ = failOnViolation;
|
failOnViolation_ = failOnViolation;
|
||||||
|
@ -308,8 +580,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* @return this operation
|
* @return this operation
|
||||||
*/
|
*/
|
||||||
public PmdOperation ignoreFile(File ignoreFile) {
|
public PmdOperation ignoreFile(File ignoreFile) {
|
||||||
ignoreFile_ = ignoreFile.toPath();
|
return ignoreFile(ignoreFile.toPath());
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -319,8 +590,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* @return this operation
|
* @return this operation
|
||||||
*/
|
*/
|
||||||
public PmdOperation ignoreFile(String ignoreFile) {
|
public PmdOperation ignoreFile(String ignoreFile) {
|
||||||
ignoreFile_ = Paths.get(ignoreFile);
|
return ignoreFile(Path.of(ignoreFile));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -350,8 +620,17 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* @return this operation
|
* @return this operation
|
||||||
*/
|
*/
|
||||||
public PMDConfiguration initConfiguration(String commandName) {
|
public PMDConfiguration initConfiguration(String commandName) {
|
||||||
PMDConfiguration config = new PMDConfiguration();
|
var config = new PMDConfiguration();
|
||||||
|
|
||||||
|
// addRelativizeRoots
|
||||||
|
config.addRelativizeRoots(relativizeRoots_.stream().toList());
|
||||||
|
|
||||||
|
// prependAuxClasspath
|
||||||
|
if (prependClasspath_ != null) {
|
||||||
|
config.prependAuxClasspath(prependClasspath_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// setAnalysisCacheLocation
|
||||||
if (cache_ == null && project_ != null && incrementalAnalysis_) {
|
if (cache_ == null && project_ != null && incrementalAnalysis_) {
|
||||||
config.setAnalysisCacheLocation(
|
config.setAnalysisCacheLocation(
|
||||||
Paths.get(project_.buildDirectory().getPath(), PMD_DIR, PMD_DIR + "-cache").toFile().getAbsolutePath());
|
Paths.get(project_.buildDirectory().getPath(), PMD_DIR, PMD_DIR + "-cache").toFile().getAbsolutePath());
|
||||||
|
@ -359,37 +638,50 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
config.setAnalysisCacheLocation(cache_.toFile().getAbsolutePath());
|
config.setAnalysisCacheLocation(cache_.toFile().getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
config.setFailOnViolation(failOnViolation_);
|
// setDefaultLanguageVersions
|
||||||
|
|
||||||
if (languageVersions_ != null) {
|
if (languageVersions_ != null) {
|
||||||
config.setDefaultLanguageVersions(languageVersions_.stream().toList());
|
config.setDefaultLanguageVersions(languageVersions_.stream().toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setExcludes
|
||||||
|
if (!excludes_.isEmpty()) {
|
||||||
|
config.setExcludes(excludes_.stream().toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
// setFailOnError
|
||||||
|
config.setFailOnError(failOnError_);
|
||||||
|
// setFailOnViolation
|
||||||
|
config.setFailOnViolation(failOnViolation_);
|
||||||
|
|
||||||
|
// setForceLanguageVersion
|
||||||
if (forcedLanguageVersion_ != null) {
|
if (forcedLanguageVersion_ != null) {
|
||||||
config.setForceLanguageVersion(forcedLanguageVersion_);
|
config.setForceLanguageVersion(forcedLanguageVersion_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setIgnoreFilePath
|
||||||
if (ignoreFile_ != null) {
|
if (ignoreFile_ != null) {
|
||||||
config.setIgnoreFilePath(ignoreFile_);
|
config.setIgnoreFilePath(ignoreFile_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setIgnoreIncrementalAnalysis
|
||||||
config.setIgnoreIncrementalAnalysis(!incrementalAnalysis_);
|
config.setIgnoreIncrementalAnalysis(!incrementalAnalysis_);
|
||||||
|
|
||||||
|
// setInputPathList
|
||||||
if (inputPaths_.isEmpty()) {
|
if (inputPaths_.isEmpty()) {
|
||||||
throw new IllegalArgumentException(commandName + ": InputPaths required.");
|
throw new IllegalArgumentException(commandName + ": InputPaths required.");
|
||||||
} else {
|
} else {
|
||||||
config.setInputPathList(inputPaths_.stream().toList());
|
config.setInputPathList(inputPaths_.stream().toList());
|
||||||
}
|
}
|
||||||
if (reportProperties_ != null) {
|
|
||||||
config.setReportProperties(reportProperties_);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// setInputUri
|
||||||
if (inputUri_ != null) {
|
if (inputUri_ != null) {
|
||||||
config.setInputUri(inputUri_);
|
config.setInputUri(inputUri_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setMinimumPriority
|
||||||
config.setMinimumPriority(rulePriority_);
|
config.setMinimumPriority(rulePriority_);
|
||||||
|
|
||||||
|
// setReportFile
|
||||||
if (project_ != null) {
|
if (project_ != null) {
|
||||||
config.setReportFile(Objects.requireNonNullElseGet(reportFile_,
|
config.setReportFile(Objects.requireNonNullElseGet(reportFile_,
|
||||||
() -> Paths.get(project_.buildDirectory().getPath(),
|
() -> Paths.get(project_.buildDirectory().getPath(),
|
||||||
|
@ -398,12 +690,25 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
config.setReportFile(reportFile_);
|
config.setReportFile(reportFile_);
|
||||||
}
|
}
|
||||||
|
|
||||||
config.addRelativizeRoots(relativizeRoots_.stream().toList());
|
// setReportFormat
|
||||||
config.setReportFormat(reportFormat_);
|
config.setReportFormat(reportFormat_);
|
||||||
|
|
||||||
|
// setReportProperties
|
||||||
|
if (reportProperties_ != null) {
|
||||||
|
config.setReportProperties(reportProperties_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// setRuleSets
|
||||||
config.setRuleSets(ruleSets_.stream().toList());
|
config.setRuleSets(ruleSets_.stream().toList());
|
||||||
|
|
||||||
|
// setShowSuppressedViolations
|
||||||
config.setShowSuppressedViolations(showSuppressed_);
|
config.setShowSuppressedViolations(showSuppressed_);
|
||||||
|
// setSourceEncoding
|
||||||
config.setSourceEncoding(encoding_);
|
config.setSourceEncoding(encoding_);
|
||||||
|
// setSuppressMarker
|
||||||
config.setSuppressMarker(suppressedMarker_);
|
config.setSuppressMarker(suppressedMarker_);
|
||||||
|
|
||||||
|
// setThreads
|
||||||
config.setThreads(threads_);
|
config.setThreads(threads_);
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
@ -417,9 +722,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* @see #addInputPaths(Path...)
|
* @see #addInputPaths(Path...)
|
||||||
*/
|
*/
|
||||||
public PmdOperation inputPaths(Path... inputPath) {
|
public PmdOperation inputPaths(Path... inputPath) {
|
||||||
inputPaths_.clear();
|
return inputPaths(List.of(inputPath));
|
||||||
inputPaths_.addAll(List.of(inputPath));
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -432,30 +735,28 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* @see #addInputPaths(File...)
|
* @see #addInputPaths(File...)
|
||||||
*/
|
*/
|
||||||
public PmdOperation inputPaths(File... inputPath) {
|
public PmdOperation inputPaths(File... inputPath) {
|
||||||
inputPaths_.clear();
|
return inputPathsFiles(List.of(inputPath));
|
||||||
inputPaths_.addAll(Arrays.stream(inputPath).map(File::toPath).toList());
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets paths to source files, or directories containing source files to analyze.
|
* Sets paths to source files, or directories containing source files to analyze.
|
||||||
* <p>
|
* <p>
|
||||||
* Previous entries are disregarded.
|
* Previous entries are disregarded.
|
||||||
|
*
|
||||||
* @param inputPath one or more paths
|
* @param inputPath one or more paths
|
||||||
* @return this operation
|
* @return this operation
|
||||||
* @see #addInputPaths(String...)
|
* @see #addInputPaths(String...)
|
||||||
*/
|
*/
|
||||||
public PmdOperation inputPaths(String... inputPath) {
|
public PmdOperation inputPaths(String... inputPath) {
|
||||||
inputPaths_.clear();
|
return inputPathsStrings(List.of(inputPath));
|
||||||
inputPaths_.addAll(Arrays.stream(inputPath).map(Paths::get).toList());
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets paths to source files, or directories containing source files to analyze.
|
* Sets paths to source files, or directories containing source files to analyze.
|
||||||
* <p>
|
* <p>
|
||||||
* Previous entries are disregarded.
|
* Previous entries are disregarded.
|
||||||
* @param inputPath the input paths
|
*
|
||||||
|
* @param inputPath a collection of input paths
|
||||||
* @return this operation
|
* @return this operation
|
||||||
* @see #addInputPaths(Collection)
|
* @see #addInputPaths(Collection)
|
||||||
*/
|
*/
|
||||||
|
@ -464,53 +765,6 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
inputPaths_.addAll(inputPath);
|
inputPaths_.addAll(inputPath);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Adds paths to source files, or directories containing source files to analyze.\
|
|
||||||
*
|
|
||||||
* @param inputPath one or more paths
|
|
||||||
* @return this operation
|
|
||||||
* @see #inputPaths(Path...)
|
|
||||||
*/
|
|
||||||
public PmdOperation addInputPaths(Path... inputPath) {
|
|
||||||
inputPaths_.addAll(List.of(inputPath));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds paths to source files, or directories containing source files to analyze.
|
|
||||||
*
|
|
||||||
* @param inputPath one or more paths
|
|
||||||
* @return this operation
|
|
||||||
* @see #inputPaths(File...)
|
|
||||||
*/
|
|
||||||
public PmdOperation addInputPaths(File... inputPath) {
|
|
||||||
inputPaths_.addAll(Arrays.stream(inputPath).map(File::toPath).toList());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds paths to source files, or directories containing source files to analyze.
|
|
||||||
*
|
|
||||||
* @param inputPath one or more paths
|
|
||||||
* @return this operation
|
|
||||||
* @see #addInputPaths(String...)
|
|
||||||
*/
|
|
||||||
public PmdOperation addInputPaths(String... inputPath) {
|
|
||||||
inputPaths_.addAll(Arrays.stream(inputPath).map(Paths::get).toList());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds paths to source files, or directories containing source files to analyze.
|
|
||||||
*
|
|
||||||
* @param inputPath the input paths
|
|
||||||
* @return this operation
|
|
||||||
* @see #inputPaths(Collection)
|
|
||||||
*/
|
|
||||||
public PmdOperation addInputPaths(Collection<Path> inputPath) {
|
|
||||||
inputPaths_.addAll(inputPath);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns paths to source files, or directories containing source files to analyze.
|
* Returns paths to source files, or directories containing source files to analyze.
|
||||||
|
@ -521,6 +775,32 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
return inputPaths_;
|
return inputPaths_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets paths to source files, or directories containing source files to analyze.
|
||||||
|
* <p>
|
||||||
|
* Previous entries are disregarded.
|
||||||
|
*
|
||||||
|
* @param inputPath a collection of input paths
|
||||||
|
* @return this operation
|
||||||
|
* @see #addInputPathsFiles(Collection)
|
||||||
|
*/
|
||||||
|
public PmdOperation inputPathsFiles(Collection<File> inputPath) {
|
||||||
|
return inputPaths(inputPath.stream().map(File::toPath).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets paths to source files, or directories containing source files to analyze.
|
||||||
|
* <p>
|
||||||
|
* Previous entries are disregarded.
|
||||||
|
*
|
||||||
|
* @param inputPath a collection of input paths
|
||||||
|
* @return this operation
|
||||||
|
* @see #addInputPathsStrings(Collection)
|
||||||
|
*/
|
||||||
|
public PmdOperation inputPathsStrings(Collection<String> inputPath) {
|
||||||
|
return inputPaths(inputPath.stream().map(Paths::get).toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default language versions.
|
* Sets the default language versions.
|
||||||
*
|
*
|
||||||
|
@ -528,14 +808,13 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* @return this operation
|
* @return this operation
|
||||||
*/
|
*/
|
||||||
public PmdOperation languageVersions(LanguageVersion... languageVersion) {
|
public PmdOperation languageVersions(LanguageVersion... languageVersion) {
|
||||||
languageVersions_.addAll(List.of(languageVersion));
|
return languageVersions(List.of(languageVersion));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default language versions.
|
* Sets the default language versions.
|
||||||
*
|
*
|
||||||
* @param languageVersions the language versions
|
* @param languageVersions a collection language versions
|
||||||
* @return this operation
|
* @return this operation
|
||||||
*/
|
*/
|
||||||
public PmdOperation languageVersions(Collection<LanguageVersion> languageVersions) {
|
public PmdOperation languageVersions(Collection<LanguageVersion> languageVersions) {
|
||||||
|
@ -567,21 +846,22 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
*
|
*
|
||||||
* @param commandName the command name
|
* @param commandName the command name
|
||||||
* @param config the configuration
|
* @param config the configuration
|
||||||
* @return the number of errors
|
* @return the number of violations
|
||||||
* @throws RuntimeException if an error occurs
|
* @throws ExitStatusException if an error occurs
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"PMD.CloseResource", "PMD.AvoidInstantiatingObjectsInLoops"})
|
@SuppressWarnings({"PMD.CloseResource", "PMD.AvoidInstantiatingObjectsInLoops"})
|
||||||
public int performPmdAnalysis(String commandName, PMDConfiguration config) throws RuntimeException {
|
public int performPmdAnalysis(String commandName, PMDConfiguration config) throws ExitStatusException {
|
||||||
var pmd = PmdAnalysis.create(config);
|
var pmd = PmdAnalysis.create(config);
|
||||||
var report = pmd.performAnalysisAndCollectReport();
|
var report = pmd.performAnalysisAndCollectReport();
|
||||||
if (LOGGER.isLoggable(Level.INFO)) {
|
if (LOGGER.isLoggable(Level.INFO) && !silent()) {
|
||||||
LOGGER.log(Level.INFO, "[{0}] inputPaths{1}", new Object[]{commandName, inputPaths_});
|
LOGGER.log(Level.INFO, "[{0}] inputPaths{1}", new Object[]{commandName, inputPaths_});
|
||||||
LOGGER.log(Level.INFO, "[{0}] ruleSets{1}", new Object[]{commandName, ruleSets_});
|
LOGGER.log(Level.INFO, "[{0}] ruleSets{1}", new Object[]{commandName, ruleSets_});
|
||||||
}
|
}
|
||||||
var numErrors = report.getViolations().size();
|
|
||||||
if (numErrors > 0) {
|
var numViolations = report.getViolations().size();
|
||||||
|
if (numViolations > 0) {
|
||||||
for (var v : report.getViolations()) {
|
for (var v : report.getViolations()) {
|
||||||
if (LOGGER.isLoggable(Level.WARNING)) {
|
if (LOGGER.isLoggable(Level.WARNING) && !silent()) {
|
||||||
final String msg;
|
final String msg;
|
||||||
if (includeLineNumber_) {
|
if (includeLineNumber_) {
|
||||||
msg = "[{0}] {1}:{2}\n\t{3} ({4})\n\t\t--> {5}";
|
msg = "[{0}] {1}:{2}\n\t{3} ({4})\n\t\t--> {5}";
|
||||||
|
@ -601,15 +881,18 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
}
|
}
|
||||||
|
|
||||||
var violations = String.format(
|
var violations = String.format(
|
||||||
"[%s] %d rule violations were found. See the report at: %s", commandName, numErrors,
|
"[%s] %d rule violations were found. See the report at: %s", commandName, numViolations,
|
||||||
config.getReportFilePath().toUri());
|
config.getReportFilePath().toUri());
|
||||||
if (config.isFailOnViolation()) {
|
if (config.isFailOnViolation()) {
|
||||||
throw new RuntimeException(violations); // NOPMD
|
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
|
||||||
} else {
|
LOGGER.log(Level.SEVERE, violations);
|
||||||
if (LOGGER.isLoggable(Level.WARNING)) {
|
|
||||||
LOGGER.warning(violations);
|
|
||||||
}
|
}
|
||||||
|
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||||
|
} else if (LOGGER.isLoggable(Level.WARNING) && !silent()) {
|
||||||
|
LOGGER.warning(violations);
|
||||||
}
|
}
|
||||||
|
} else if (pmd.getReporter().numErrors() > 0 && failOnError_) {
|
||||||
|
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||||
} else {
|
} else {
|
||||||
var rules = pmd.getRulesets();
|
var rules = pmd.getRulesets();
|
||||||
if (!rules.isEmpty()) {
|
if (!rules.isEmpty()) {
|
||||||
|
@ -617,52 +900,78 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
for (var rule : rules) {
|
for (var rule : rules) {
|
||||||
count += rule.getRules().size();
|
count += rule.getRules().size();
|
||||||
}
|
}
|
||||||
if (LOGGER.isLoggable(Level.INFO)) {
|
if (LOGGER.isLoggable(Level.INFO) && !silent()) {
|
||||||
LOGGER.info(String.format("[%s] %d rules were checked.", commandName, count));
|
LOGGER.info(String.format("[%s] %d rules were checked.", commandName, count));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return numErrors;
|
return numViolations;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepend the specified classpath like string to the current ClassLoader of the configuration. If no ClassLoader
|
||||||
|
* is currently configured, the ClassLoader used to load the PMDConfiguration class will be used as the parent
|
||||||
|
* ClassLoader of the created ClassLoader.
|
||||||
|
* <p>
|
||||||
|
* If the classpath String looks like a URL to a file (i.e. starts with {@code file://}) the file will be read with
|
||||||
|
* each line representing an entry on the classpath.
|
||||||
|
*
|
||||||
|
* @param classpath one or more classpath
|
||||||
|
* @return this operation
|
||||||
|
*/
|
||||||
|
public PmdOperation prependAuxClasspath(String... classpath) {
|
||||||
|
prependClasspath_ = String.join(File.pathSeparator, classpath);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the prepended classpath.
|
||||||
|
*
|
||||||
|
* @return the classpath
|
||||||
|
*/
|
||||||
|
public String prependAuxClasspath() {
|
||||||
|
return prependClasspath_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds several paths to shorten paths that are output in the report.
|
* Adds several paths to shorten paths that are output in the report.
|
||||||
*
|
*
|
||||||
* @param relativeRoot one or more relative root paths
|
* @param relativeRoot one or more relative root paths
|
||||||
* @return this operations
|
* @return this operation
|
||||||
|
* @see #relativizeRoots(Collection)
|
||||||
*/
|
*/
|
||||||
public PmdOperation relativizeRoots(Path... relativeRoot) {
|
public PmdOperation relativizeRoots(Path... relativeRoot) {
|
||||||
relativizeRoots_.addAll(List.of(relativeRoot));
|
return relativizeRoots(List.of(relativeRoot));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds several paths to shorten paths that are output in the report.
|
* Adds several paths to shorten paths that are output in the report.
|
||||||
*
|
*
|
||||||
* @param relativeRoot one or more relative root paths
|
* @param relativeRoot one or more relative root paths
|
||||||
* @return this operations
|
* @return this operation
|
||||||
|
* @see #relativizeRootsFiles(Collection)
|
||||||
*/
|
*/
|
||||||
public PmdOperation relativizeRoots(File... relativeRoot) {
|
public PmdOperation relativizeRoots(File... relativeRoot) {
|
||||||
relativizeRoots_.addAll(Arrays.stream(relativeRoot).map(File::toPath).toList());
|
return relativizeRootsFiles(List.of(relativeRoot));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds several paths to shorten paths that are output in the report.
|
* Adds several paths to shorten paths that are output in the report.
|
||||||
*
|
*
|
||||||
* @param relativeRoot one or more relative root paths
|
* @param relativeRoot one or more relative root paths
|
||||||
* @return this operations
|
* @return this operation
|
||||||
|
* @see #relativizeRootsStrings(Collection)
|
||||||
*/
|
*/
|
||||||
public PmdOperation relativizeRoots(String... relativeRoot) {
|
public PmdOperation relativizeRoots(String... relativeRoot) {
|
||||||
relativizeRoots_.addAll(Arrays.stream(relativeRoot).map(Paths::get).toList());
|
return relativizeRootsStrings(List.of(relativeRoot));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds several paths to shorten paths that are output in the report.
|
* Adds several paths to shorten paths that are output in the report.
|
||||||
*
|
*
|
||||||
* @param relativeRoot the relative root paths
|
* @param relativeRoot a collection of relative root paths
|
||||||
* @return this operations
|
* @return this operation
|
||||||
|
* @see #relativizeRoots(Path...)
|
||||||
*/
|
*/
|
||||||
public PmdOperation relativizeRoots(Collection<Path> relativeRoot) {
|
public PmdOperation relativizeRoots(Collection<Path> relativeRoot) {
|
||||||
relativizeRoots_.addAll(relativeRoot);
|
relativizeRoots_.addAll(relativeRoot);
|
||||||
|
@ -678,6 +987,28 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
return relativizeRoots_;
|
return relativizeRoots_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds several paths to shorten paths that are output in the report.
|
||||||
|
*
|
||||||
|
* @param relativeRoot a collection of relative root paths
|
||||||
|
* @return this operation
|
||||||
|
* @see #relativizeRoots(File...)
|
||||||
|
*/
|
||||||
|
public PmdOperation relativizeRootsFiles(Collection<File> relativeRoot) {
|
||||||
|
return relativizeRoots(relativeRoot.stream().map(File::toPath).toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds several paths to shorten paths that are output in the report.
|
||||||
|
*
|
||||||
|
* @param relativeRoot a collection of relative root paths
|
||||||
|
* @return this operation
|
||||||
|
* @see #relativizeRoots(String...)
|
||||||
|
*/
|
||||||
|
public PmdOperation relativizeRootsStrings(Collection<String> relativeRoot) {
|
||||||
|
return relativizeRoots(relativeRoot.stream().map(Paths::get).toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the path to the report page.
|
* Sets the path to the report page.
|
||||||
*
|
*
|
||||||
|
@ -696,8 +1027,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* @return this operation
|
* @return this operation
|
||||||
*/
|
*/
|
||||||
public PmdOperation reportFile(File reportFile) {
|
public PmdOperation reportFile(File reportFile) {
|
||||||
reportFile_ = reportFile.toPath();
|
return reportFile(reportFile.toPath());
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -707,8 +1037,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* @return this operation
|
* @return this operation
|
||||||
*/
|
*/
|
||||||
public PmdOperation reportFile(String reportFile) {
|
public PmdOperation reportFile(String reportFile) {
|
||||||
reportFile_ = Paths.get(reportFile);
|
return reportFile(Paths.get(reportFile));
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -763,9 +1092,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* @see #addRuleSet(String...)
|
* @see #addRuleSet(String...)
|
||||||
*/
|
*/
|
||||||
public PmdOperation ruleSets(String... ruleSet) {
|
public PmdOperation ruleSets(String... ruleSet) {
|
||||||
ruleSets_.clear();
|
return ruleSets(List.of(ruleSet));
|
||||||
ruleSets_.addAll(List.of(ruleSet));
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -784,7 +1111,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
* <li>{@code category/java/security.xml}</li>
|
* <li>{@code category/java/security.xml}</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @param ruleSet one or more rule set
|
* @param ruleSet a collection of rule set paths
|
||||||
* @return this operation
|
* @return this operation
|
||||||
* @see #addRuleSet(Collection)
|
* @see #addRuleSet(Collection)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2023-2024 the original author or authors.
|
* Copyright 2023-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -19,8 +19,10 @@ package rife.bld.extension;
|
||||||
import net.sourceforge.pmd.PMDConfiguration;
|
import net.sourceforge.pmd.PMDConfiguration;
|
||||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||||
import net.sourceforge.pmd.lang.rule.RulePriority;
|
import net.sourceforge.pmd.lang.rule.RulePriority;
|
||||||
|
import org.assertj.core.api.AutoCloseableSoftAssertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import rife.bld.BaseProject;
|
import rife.bld.BaseProject;
|
||||||
|
import rife.bld.operations.exceptions.ExitStatusException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -45,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThatCode;
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
class PmdOperationTest {
|
class PmdOperationTest {
|
||||||
|
static final String BAR = "bar";
|
||||||
static final String CATEGORY_FOO = "category/foo.xml";
|
static final String CATEGORY_FOO = "category/foo.xml";
|
||||||
static final Path CODE_STYLE_SAMPLE = Path.of("src/test/resources/java/CodeStyle.java");
|
static final Path CODE_STYLE_SAMPLE = Path.of("src/test/resources/java/CodeStyle.java");
|
||||||
static final String CODE_STYLE_XML = "category/java/codestyle.xml";
|
static final String CODE_STYLE_XML = "category/java/codestyle.xml";
|
||||||
|
@ -53,6 +56,11 @@ class PmdOperationTest {
|
||||||
static final String DOCUMENTATION_XML = "category/java/documentation.xml";
|
static final String DOCUMENTATION_XML = "category/java/documentation.xml";
|
||||||
static final Path ERROR_PRONE_SAMPLE = Path.of("src/test/resources/java/ErrorProne.java");
|
static final Path ERROR_PRONE_SAMPLE = Path.of("src/test/resources/java/ErrorProne.java");
|
||||||
static final String ERROR_PRONE_XML = "category/java/errorprone.xml";
|
static final String ERROR_PRONE_XML = "category/java/errorprone.xml";
|
||||||
|
static final File FILE_BAR = new File(BAR);
|
||||||
|
static final String FOO = "foo";
|
||||||
|
static final File FILE_FOO = new File(FOO);
|
||||||
|
static final Path PATH_BAR = Path.of(BAR);
|
||||||
|
static final Path PATH_FOO = Path.of(FOO);
|
||||||
static final String PERFORMANCE_XML = "category/java/performance.xml";
|
static final String PERFORMANCE_XML = "category/java/performance.xml";
|
||||||
static final String SECURITY_XML = "category/java/security.xml";
|
static final String SECURITY_XML = "category/java/security.xml";
|
||||||
static final String TEST = "test";
|
static final String TEST = "test";
|
||||||
|
@ -60,13 +68,46 @@ class PmdOperationTest {
|
||||||
PmdOperation newPmdOperation() {
|
PmdOperation newPmdOperation() {
|
||||||
return new PmdOperation()
|
return new PmdOperation()
|
||||||
.inputPaths(Path.of("src/main"), Path.of("src/test"))
|
.inputPaths(Path.of("src/main"), Path.of("src/test"))
|
||||||
.cache(Paths.get("build", COMMAND_NAME, "pmd-cache"))
|
.cache("build/" + COMMAND_NAME + "/pmd-cache")
|
||||||
.failOnViolation(false)
|
.failOnViolation(false)
|
||||||
.reportFile(Paths.get("build", COMMAND_NAME, "pmd-test-report.txt"));
|
.reportFile(Paths.get("build", COMMAND_NAME, "pmd-test-report.txt"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAddInputPath() {
|
void testAddExcludes() {
|
||||||
|
var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).addExcludes(PATH_FOO);
|
||||||
|
var config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
|
assertThat(config.getExcludes()).containsExactly(PATH_FOO);
|
||||||
|
|
||||||
|
pmd = pmd.addExcludes(PATH_BAR);
|
||||||
|
config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
|
assertThat(config.getExcludes()).containsExactly(PATH_FOO, PATH_BAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAddExcludesFiles() {
|
||||||
|
var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).addExcludesFiles(FILE_FOO);
|
||||||
|
var config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
|
assertThat(config.getExcludes()).containsExactly(FILE_FOO.toPath());
|
||||||
|
|
||||||
|
pmd = pmd.addExcludesFiles(FILE_BAR);
|
||||||
|
config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
|
assertThat(config.getExcludes()).containsExactly(FILE_FOO.toPath(), FILE_BAR.toPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAddExcludesStrings() {
|
||||||
|
var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).addExcludesStrings(FOO);
|
||||||
|
var config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
|
assertThat(config.getExcludes()).containsExactly(PATH_FOO);
|
||||||
|
|
||||||
|
pmd = pmd.addExcludesStrings(BAR);
|
||||||
|
config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
|
assertThat(config.getExcludes()).containsExactly(PATH_FOO, PATH_BAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testAddInputPaths() throws ExitStatusException {
|
||||||
var project = new BaseProject();
|
var project = new BaseProject();
|
||||||
var pmd = new PmdOperation().fromProject(project);
|
var pmd = new PmdOperation().fromProject(project);
|
||||||
|
|
||||||
|
@ -76,30 +117,49 @@ class PmdOperationTest {
|
||||||
var err = pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME));
|
var err = pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME));
|
||||||
|
|
||||||
pmd.inputPaths().clear();
|
pmd.inputPaths().clear();
|
||||||
pmd.addInputPaths(project.srcMainDirectory());
|
pmd = pmd.addInputPaths(project.srcMainDirectory(), project.srcTestDirectory());
|
||||||
|
|
||||||
assertThat(pmd.inputPaths()).as("main").containsExactly(project.srcMainDirectory().toPath());
|
assertThat(pmd.inputPaths()).as("File...").containsExactly(project.srcMainDirectory().toPath(),
|
||||||
|
|
||||||
pmd.inputPaths().clear();
|
|
||||||
pmd.addInputPaths(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath());
|
|
||||||
|
|
||||||
assertThat(pmd.inputPaths()).as("toPath(main, test)").containsExactly(project.srcMainDirectory().toPath(),
|
|
||||||
project.srcTestDirectory().toPath());
|
project.srcTestDirectory().toPath());
|
||||||
|
|
||||||
pmd.inputPaths().clear();
|
pmd.inputPaths().clear();
|
||||||
pmd.addInputPaths(List.of(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath()));
|
pmd = pmd.addInputPathsFiles(List.of(project.srcMainDirectory(), project.srcTestDirectory()));
|
||||||
|
|
||||||
assertThat(pmd.inputPaths()).as("List(main, test)").containsExactly(
|
assertThat(pmd.inputPaths()).as("List(File...)")
|
||||||
project.srcMainDirectory().toPath(),
|
.containsExactly(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath());
|
||||||
project.srcTestDirectory().toPath());
|
|
||||||
|
|
||||||
|
pmd.inputPaths().clear();
|
||||||
|
pmd = pmd.addInputPaths(project.srcMainDirectory().getAbsolutePath(),
|
||||||
|
project.srcTestDirectory().getAbsolutePath());
|
||||||
|
|
||||||
|
assertThat(pmd.inputPaths()).as("String...")
|
||||||
|
.containsExactly(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath());
|
||||||
|
|
||||||
|
pmd.inputPaths().clear();
|
||||||
|
pmd = pmd.addInputPathsStrings(
|
||||||
|
List.of(project.srcMainDirectory().getAbsolutePath(), project.srcTestDirectory().getAbsolutePath()));
|
||||||
|
|
||||||
|
assertThat(pmd.inputPaths()).as("List(String...)")
|
||||||
|
.containsExactly(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath());
|
||||||
|
|
||||||
|
pmd.inputPaths().clear();
|
||||||
|
pmd = pmd.addInputPaths(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath());
|
||||||
|
|
||||||
|
assertThat(pmd.inputPaths()).as("Path...")
|
||||||
|
.containsExactly(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath());
|
||||||
|
|
||||||
|
pmd.inputPaths().clear();
|
||||||
|
pmd = pmd.addInputPaths(List.of(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath()));
|
||||||
|
|
||||||
|
assertThat(pmd.inputPaths()).as("List(Path)")
|
||||||
|
.containsExactly(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath());
|
||||||
|
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
||||||
.isGreaterThan(0).isEqualTo(err);
|
.isGreaterThan(0).isEqualTo(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAddRuleSets() {
|
void testAddRuleSets() throws ExitStatusException {
|
||||||
var pmd = new PmdOperation().fromProject(new BaseProject());
|
var pmd = new PmdOperation().fromProject(new BaseProject());
|
||||||
|
|
||||||
assertThat(pmd.ruleSets()).containsExactly(PmdOperation.RULE_SET_DEFAULT);
|
assertThat(pmd.ruleSets()).containsExactly(PmdOperation.RULE_SET_DEFAULT);
|
||||||
|
@ -122,9 +182,12 @@ class PmdOperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCache() {
|
void testCache() throws ExitStatusException {
|
||||||
var cache = Path.of("build/pmd/temp-cache");
|
var cache = Path.of("build/pmd/temp-cache");
|
||||||
var pmd = newPmdOperation().ruleSets(CODE_STYLE_XML).inputPaths(List.of(CODE_STYLE_SAMPLE)).cache(cache);
|
var pmd = newPmdOperation()
|
||||||
|
.ruleSets(CODE_STYLE_XML)
|
||||||
|
.inputPaths(List.of(CODE_STYLE_SAMPLE))
|
||||||
|
.cache(cache);
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
var f = cache.toFile();
|
var f = cache.toFile();
|
||||||
assertThat(f.exists()).as("file exits").isTrue();
|
assertThat(f.exists()).as("file exits").isTrue();
|
||||||
|
@ -143,7 +206,60 @@ class PmdOperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testExecute() {
|
void testExcludes() {
|
||||||
|
var foz = Path.of("foz/baz");
|
||||||
|
var baz = Path.of("baz/foz");
|
||||||
|
|
||||||
|
var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).excludes(PATH_FOO, PATH_BAR);
|
||||||
|
var config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
|
assertThat(pmd.excludes()).containsExactly(List.of(PATH_FOO, PATH_BAR).toArray(new Path[0]));
|
||||||
|
assertThat(config.getExcludes()).containsExactly(List.of(PATH_FOO, PATH_BAR).toArray(new Path[0]));
|
||||||
|
|
||||||
|
var excludes = List.of(List.of(PATH_FOO, PATH_BAR), List.of(foz, baz));
|
||||||
|
for (var exclude : excludes) {
|
||||||
|
pmd = newPmdOperation().ruleSets(CATEGORY_FOO).excludes(exclude);
|
||||||
|
config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
|
assertThat(config.getExcludes()).containsExactly(exclude.toArray(new Path[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testExcludesFiles() {
|
||||||
|
var foz = new File("foz");
|
||||||
|
var baz = new File("baz");
|
||||||
|
|
||||||
|
var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).excludesFiles(FILE_FOO, FILE_BAR);
|
||||||
|
var config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
|
assertThat(config.getExcludes()).containsExactly(FILE_FOO.toPath(), FILE_BAR.toPath());
|
||||||
|
|
||||||
|
var excludes = List.of(List.of(FILE_FOO, FILE_BAR), List.of(foz, baz));
|
||||||
|
for (var exclude : excludes) {
|
||||||
|
pmd = newPmdOperation().ruleSets(CATEGORY_FOO).excludesFiles(exclude);
|
||||||
|
config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
|
assertThat(config.getExcludes()).containsExactly(exclude.stream().map(File::toPath).toArray(Path[]::new));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testExcludesStrings() {
|
||||||
|
var foz = "foz";
|
||||||
|
var baz = "baz";
|
||||||
|
|
||||||
|
var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).excludesStrings(FOO, BAR);
|
||||||
|
var config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
|
assertThat(pmd.excludes()).containsExactly(PATH_FOO, PATH_BAR);
|
||||||
|
assertThat(config.getExcludes()).containsExactly(PATH_FOO, PATH_BAR);
|
||||||
|
|
||||||
|
var excludes = List.of(List.of(FOO, BAR), List.of(foz, baz));
|
||||||
|
for (var exclude : excludes) {
|
||||||
|
pmd = newPmdOperation().ruleSets(CATEGORY_FOO).excludesStrings(exclude);
|
||||||
|
config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
|
assertThat(config.getExcludes()).containsExactly(exclude.stream().map(Paths::get).toArray(Path[]::new));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testExecute() throws ExitStatusException {
|
||||||
var pmd = new PmdOperation().fromProject(new BaseProject());
|
var pmd = new PmdOperation().fromProject(new BaseProject());
|
||||||
|
|
||||||
assertThat(pmd.inputPaths()).containsExactly(Paths.get("src/main").toAbsolutePath(),
|
assertThat(pmd.inputPaths()).containsExactly(Paths.get("src/main").toAbsolutePath(),
|
||||||
|
@ -157,16 +273,34 @@ class PmdOperationTest {
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isEqualTo(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testExecuteNoProject() {
|
||||||
|
var pmd = new PmdOperation();
|
||||||
|
assertThatCode(pmd::execute).isInstanceOf(ExitStatusException.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testFailOnError() {
|
||||||
|
var pmd = newPmdOperation().ruleSets("src/test/resources/xml/old.xml")
|
||||||
|
.inputPaths(Path.of("src/test/resources/java/Documentation.java"));
|
||||||
|
assertThatCode(() -> pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
||||||
|
.isInstanceOf(ExitStatusException.class);
|
||||||
|
assertThatCode(() -> pmd.failOnError(false).performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
||||||
|
.doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFailOnValidation() {
|
void testFailOnValidation() {
|
||||||
var pmd = newPmdOperation().ruleSets(DOCUMENTATION_XML)
|
var pmd = newPmdOperation().ruleSets(DOCUMENTATION_XML)
|
||||||
.inputPaths(Path.of("src/test/resources/java/Documentation.java"));
|
.inputPaths(Path.of("src/test/resources/java/Documentation.java"));
|
||||||
assertThatCode(() -> pmd.failOnViolation(true).performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
assertThatCode(() -> pmd.failOnViolation(true).performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
||||||
.isInstanceOf(RuntimeException.class).hasMessageContaining('[' + TEST + ']');
|
.isInstanceOf(ExitStatusException.class);
|
||||||
|
assertThatCode(() -> pmd.failOnViolation(false).performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
||||||
|
.doesNotThrowAnyException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testIgnoreFile() {
|
void testIgnoreFile() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation()
|
var pmd = newPmdOperation()
|
||||||
.ruleSets(ERROR_PRONE_XML, CODE_STYLE_XML)
|
.ruleSets(ERROR_PRONE_XML, CODE_STYLE_XML)
|
||||||
.ignoreFile(Path.of("src/test/resources/ignore.txt"));
|
.ignoreFile(Path.of("src/test/resources/ignore.txt"));
|
||||||
|
@ -191,48 +325,73 @@ class PmdOperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testInputPaths() {
|
void testInputPaths() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation()
|
var pmd = newPmdOperation()
|
||||||
.ruleSets(PmdOperation.RULE_SET_DEFAULT, CODE_STYLE_XML)
|
.ruleSets(PmdOperation.RULE_SET_DEFAULT, CODE_STYLE_XML)
|
||||||
.inputPaths(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
|
.inputPaths(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
|
||||||
assertThat(pmd.inputPaths()).contains(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
|
assertThat(pmd.inputPaths()).as("Path....").containsExactly(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
|
||||||
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
|
|
||||||
|
pmd = newPmdOperation()
|
||||||
|
.ruleSets(PmdOperation.RULE_SET_DEFAULT, CODE_STYLE_XML)
|
||||||
|
.inputPaths(ERROR_PRONE_SAMPLE.toFile(), CODE_STYLE_SAMPLE.toFile());
|
||||||
|
assertThat(pmd.inputPaths()).as("File...").containsExactly(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
|
||||||
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
|
|
||||||
|
pmd = newPmdOperation()
|
||||||
|
.ruleSets(PmdOperation.RULE_SET_DEFAULT, CODE_STYLE_XML)
|
||||||
|
.inputPaths(ERROR_PRONE_SAMPLE.toString(), CODE_STYLE_SAMPLE.toString());
|
||||||
|
assertThat(pmd.inputPaths()).as("String...").containsExactly(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
|
||||||
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
|
|
||||||
|
pmd = newPmdOperation()
|
||||||
|
.ruleSets(PmdOperation.RULE_SET_DEFAULT, CODE_STYLE_XML)
|
||||||
|
.inputPathsFiles(List.of(ERROR_PRONE_SAMPLE.toFile(), CODE_STYLE_SAMPLE.toFile()));
|
||||||
|
assertThat(pmd.inputPaths()).as("List(Path...)").containsExactly(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
|
||||||
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
|
|
||||||
|
pmd = newPmdOperation()
|
||||||
|
.ruleSets(PmdOperation.RULE_SET_DEFAULT, CODE_STYLE_XML)
|
||||||
|
.inputPathsStrings(List.of(ERROR_PRONE_SAMPLE.toString(), CODE_STYLE_SAMPLE.toString()));
|
||||||
|
assertThat(pmd.inputPaths()).as("List(String...)").containsExactly(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJavaBestPractices() {
|
void testJavaBestPractices() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation().ruleSets("category/java/bestpractices.xml")
|
var pmd = newPmdOperation().ruleSets("category/java/bestpractices.xml")
|
||||||
.inputPaths(Path.of("src/test/resources/java/BestPractices.java"));
|
.inputPaths(Path.of("src/test/resources/java/BestPractices.java"));
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJavaCodeStyle() {
|
void testJavaCodeStyle() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation().ruleSets(CODE_STYLE_XML).inputPaths(CODE_STYLE_SAMPLE);
|
var pmd = newPmdOperation().ruleSets(CODE_STYLE_XML).inputPaths(CODE_STYLE_SAMPLE);
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJavaCodeStyleAndErrorProne() {
|
void testJavaCodeStyleAndErrorProne() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation().ruleSets(CODE_STYLE_XML).inputPaths(CODE_STYLE_SAMPLE);
|
var pmd = newPmdOperation().ruleSets(CODE_STYLE_XML).inputPaths(CODE_STYLE_SAMPLE);
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
||||||
.as("code style").isGreaterThan(0);
|
.as("code style").isGreaterThan(0);
|
||||||
|
|
||||||
pmd = pmd.ruleSets(ERROR_PRONE_XML).inputPaths(ERROR_PRONE_SAMPLE);
|
pmd = pmd.ruleSets(ERROR_PRONE_XML).inputPaths(ERROR_PRONE_SAMPLE);
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
||||||
.as("code style + error prone").isGreaterThan(0);
|
.as("code style + error prone").isGreaterThan(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJavaDesign() {
|
void testJavaDesign() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation()
|
var pmd = newPmdOperation()
|
||||||
.ruleSets(DESIGN_XML)
|
.ruleSets(DESIGN_XML)
|
||||||
.inputPaths("src/test/resources/java/Design.java")
|
.inputPaths("src/test/resources/java/Design.java")
|
||||||
.cache(Path.of("build/pmd/design-cache"));
|
.cache(new File("build/pmd/design-cache"));
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJavaDocumentation() {
|
void testJavaDocumentation() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation()
|
var pmd = newPmdOperation()
|
||||||
.ruleSets(DOCUMENTATION_XML)
|
.ruleSets(DOCUMENTATION_XML)
|
||||||
.inputPaths(Path.of("src/test/resources/java/Documentation.java"));
|
.inputPaths(Path.of("src/test/resources/java/Documentation.java"));
|
||||||
|
@ -240,20 +399,20 @@ class PmdOperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJavaErrorProne() {
|
void testJavaErrorProne() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation().ruleSets(ERROR_PRONE_XML).inputPaths(ERROR_PRONE_SAMPLE);
|
var pmd = newPmdOperation().ruleSets(ERROR_PRONE_XML).inputPaths(ERROR_PRONE_SAMPLE);
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJavaMultiThreading() {
|
void testJavaMultiThreading() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation().ruleSets("category/java/multithreading.xml")
|
var pmd = newPmdOperation().ruleSets("category/java/multithreading.xml")
|
||||||
.inputPaths(Path.of("src/test/resources/java/MultiThreading.java"));
|
.inputPaths(Path.of("src/test/resources/java/MultiThreading.java"));
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJavaPerformance() {
|
void testJavaPerformance() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation()
|
var pmd = newPmdOperation()
|
||||||
.ruleSets(PERFORMANCE_XML)
|
.ruleSets(PERFORMANCE_XML)
|
||||||
.inputPaths(Path.of("src/test/resources/java/Performance.java"));
|
.inputPaths(Path.of("src/test/resources/java/Performance.java"));
|
||||||
|
@ -261,7 +420,7 @@ class PmdOperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJavaQuickStart() {
|
void testJavaQuickStart() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation().ruleSets(PmdOperation.RULE_SET_DEFAULT)
|
var pmd = newPmdOperation().ruleSets(PmdOperation.RULE_SET_DEFAULT)
|
||||||
.inputPaths(new File("src/test/resources/java/"));
|
.inputPaths(new File("src/test/resources/java/"));
|
||||||
assertThat(pmd.ruleSets()).containsExactly(PmdOperation.RULE_SET_DEFAULT);
|
assertThat(pmd.ruleSets()).containsExactly(PmdOperation.RULE_SET_DEFAULT);
|
||||||
|
@ -269,21 +428,21 @@ class PmdOperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJavaSecurity() {
|
void testJavaSecurity() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation().ruleSets(SECURITY_XML)
|
var pmd = newPmdOperation().ruleSets(SECURITY_XML)
|
||||||
.inputPaths(Path.of("src/test/resources/java/Security.java"));
|
.inputPaths(Path.of("src/test/resources/java/Security.java"));
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testLanguageVersions() {
|
void testLanguageVersions() throws ExitStatusException {
|
||||||
var language = LanguageRegistry.PMD.getLanguageById("java");
|
var language = LanguageRegistry.PMD.getLanguageById("java");
|
||||||
assertThat(language).isNotNull();
|
assertThat(language).isNotNull();
|
||||||
|
|
||||||
var pmd = newPmdOperation()
|
var pmd = newPmdOperation()
|
||||||
.forceLanguageVersion(language.getLatestVersion())
|
.forceLanguageVersion(language.getLatestVersion())
|
||||||
.defaultLanguageVersions(language.getVersions())
|
.defaultLanguageVersions(language.getVersions())
|
||||||
.languageVersions(language.getVersion("22"))
|
.languageVersions(language.getDefaultVersion())
|
||||||
.ruleSets(PmdOperation.RULE_SET_DEFAULT);
|
.ruleSets(PmdOperation.RULE_SET_DEFAULT);
|
||||||
assertThat(pmd.languageVersions()).contains(language.getDefaultVersion());
|
assertThat(pmd.languageVersions()).contains(language.getDefaultVersion());
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
|
@ -295,33 +454,50 @@ class PmdOperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMainOperation() {
|
void testMainOperation() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation().inputPaths(new File("src/main"))
|
var pmd = newPmdOperation().inputPaths(new File("src/main"))
|
||||||
.performPmdAnalysis(TEST, newPmdOperation().initConfiguration(COMMAND_NAME));
|
.performPmdAnalysis(TEST, newPmdOperation().initConfiguration(COMMAND_NAME));
|
||||||
assertThat(pmd).isEqualTo(0);
|
assertThat(pmd).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testPriority() {
|
void testPrependAuxClasspath() {
|
||||||
|
var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).prependAuxClasspath(FOO, BAR);
|
||||||
|
assertThat(pmd.prependAuxClasspath()).isEqualTo(FOO + File.pathSeparator + BAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testPriority() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation().inputPaths(CODE_STYLE_SAMPLE).minimumPriority(RulePriority.HIGH);
|
var pmd = newPmdOperation().inputPaths(CODE_STYLE_SAMPLE).minimumPriority(RulePriority.HIGH);
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isEqualTo(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRelativizeRoots() {
|
void testRelativizeRoots() {
|
||||||
var foo = Path.of("foo/bar");
|
|
||||||
var bar = Path.of("bar/foo");
|
|
||||||
var baz = Path.of("baz/foz");
|
var baz = Path.of("baz/foz");
|
||||||
|
|
||||||
var pmd = newPmdOperation().ruleSets(List.of(CATEGORY_FOO)).relativizeRoots(foo).relativizeRoots(bar.toFile())
|
var pmd = newPmdOperation().ruleSets(List.of(CATEGORY_FOO)).relativizeRoots(PATH_FOO).
|
||||||
.relativizeRoots(baz.toString()).relativizeRoots(List.of(foo, bar, baz));
|
relativizeRoots(PATH_BAR.toFile()).relativizeRoots(baz.toString())
|
||||||
|
.relativizeRoots(List.of(PATH_FOO, PATH_BAR, baz));
|
||||||
var config = pmd.initConfiguration(COMMAND_NAME);
|
var config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
assertThat(config.getRelativizeRoots()).isEqualTo(pmd.relativizeRoots());
|
assertThat(config.getRelativizeRoots()).isEqualTo(pmd.relativizeRoots())
|
||||||
assertThat(config.getRelativizeRoots()).containsExactly(foo, bar, baz, foo, bar, baz);
|
.containsExactly(PATH_FOO, PATH_BAR, baz, PATH_FOO, PATH_BAR, baz);
|
||||||
|
|
||||||
|
pmd = newPmdOperation().ruleSets(List.of(CATEGORY_FOO))
|
||||||
|
.relativizeRootsFiles(List.of(PATH_FOO.toFile(), PATH_BAR.toFile(), baz.toFile()));
|
||||||
|
config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
|
assertThat(config.getRelativizeRoots()).as("List(File...)").isEqualTo(pmd.relativizeRoots())
|
||||||
|
.containsExactly(PATH_FOO, PATH_BAR, baz);
|
||||||
|
|
||||||
|
pmd = newPmdOperation().ruleSets(List.of(CATEGORY_FOO))
|
||||||
|
.relativizeRootsStrings(List.of(PATH_FOO.toString(), PATH_BAR.toString(), baz.toString()));
|
||||||
|
config = pmd.initConfiguration(COMMAND_NAME);
|
||||||
|
assertThat(config.getRelativizeRoots()).as("List(String....)").isEqualTo(pmd.relativizeRoots())
|
||||||
|
.containsExactly(PATH_FOO, PATH_BAR, baz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testReportFile() throws FileNotFoundException {
|
void testReportFile() throws FileNotFoundException, ExitStatusException {
|
||||||
var report = new File("build", "pmd-report-file");
|
var report = new File("build", "pmd-report-file");
|
||||||
report.deleteOnExit();
|
report.deleteOnExit();
|
||||||
var pmd = newPmdOperation().ruleSets(List.of(ERROR_PRONE_XML, DESIGN_XML)).reportFile(report);
|
var pmd = newPmdOperation().ruleSets(List.of(ERROR_PRONE_XML, DESIGN_XML)).reportFile(report);
|
||||||
|
@ -338,16 +514,19 @@ class PmdOperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testReportFormat() throws IOException {
|
void testReportFormat() throws IOException, ExitStatusException {
|
||||||
var pmd = newPmdOperation().ruleSets(ERROR_PRONE_XML).reportFormat("xml").inputPaths(ERROR_PRONE_SAMPLE);
|
var pmd = newPmdOperation().ruleSets(ERROR_PRONE_XML).reportFormat("xml").inputPaths(ERROR_PRONE_SAMPLE);
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
try (var br = Files.newBufferedReader(pmd.reportFile())) {
|
try (var softly = new AutoCloseableSoftAssertions()) {
|
||||||
assertThat(br.readLine()).as("xml report").startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
try (var br = Files.newBufferedReader(pmd.reportFile())) {
|
||||||
|
softly.assertThat(br.readLine()).as("xml report")
|
||||||
|
.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testReportProperties() {
|
void testReportProperties() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation().ruleSets(CODE_STYLE_XML, ERROR_PRONE_XML)
|
var pmd = newPmdOperation().ruleSets(CODE_STYLE_XML, ERROR_PRONE_XML)
|
||||||
.includeLineNumber(true)
|
.includeLineNumber(true)
|
||||||
.reportProperties(new Properties());
|
.reportProperties(new Properties());
|
||||||
|
@ -355,15 +534,15 @@ class PmdOperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRuleSetsConfigFile() {
|
void testRuleSetsConfigFile() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation().ruleSets("src/test/resources/pmd.xml")
|
var pmd = newPmdOperation().ruleSets("src/test/resources/pmd.xml")
|
||||||
.ignoreFile("src/test/resources/ignore-all.txt");
|
.ignoreFile("src/test/resources/ignore-all.txt");
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isEqualTo(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRuleSetsEmpty() {
|
void testRuleSetsEmpty() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation().ruleSets("");
|
var pmd = newPmdOperation().ruleSets("").failOnError(false);
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isEqualTo(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +576,7 @@ class PmdOperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testXml() {
|
void testXml() throws ExitStatusException {
|
||||||
var pmd = newPmdOperation().addInputPaths("src/test/resources/pmd.xml")
|
var pmd = newPmdOperation().addInputPaths("src/test/resources/pmd.xml")
|
||||||
.ruleSets("src/test/resources/xml/basic.xml");
|
.ruleSets("src/test/resources/xml/basic.xml");
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<ruleset name="test"
|
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
name="test"
|
||||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
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 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||||
<description>Erik's Ruleset</description>
|
<description>Erik's Ruleset</description>
|
||||||
<!-- BEST PRACTICES -->
|
<!-- BEST PRACTICES -->
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
<ruleset name="Basic"
|
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
name="Basic"
|
||||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
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 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||||
<description>
|
<description>
|
||||||
The Basic ruleset contains a collection of good practices which should be followed.
|
The Basic ruleset contains a collection of good practices which should be followed.
|
||||||
|
|
8
src/test/resources/xml/old.xml
Normal file
8
src/test/resources/xml/old.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
name="old"
|
||||||
|
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||||
|
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||||
|
<description>Deprecated (old) rule</description>
|
||||||
|
<rule ref="category/java/performance.xml/UnnecessaryWrapperObjectCreation"/>
|
||||||
|
</ruleset>
|
Loading…
Add table
Add a link
Reference in a new issue