Compare commits
No commits in common. "c9902c88efd696247d8b23a2f65feb682f5c5597" and "39abc2e7199482b7342c786d1e2f4359575db255" have entirely different histories.
c9902c88ef
...
39abc2e719
3 changed files with 12 additions and 57 deletions
37
README.md
37
README.md
|
@ -1,37 +0,0 @@
|
||||||
# [Bld](https://rife2.com/bld) Extension to Perform Static Code Analysis with [PMD](https://pmd.github.io/)
|
|
||||||
|
|
||||||
|
|
||||||
[](http://opensource.org/licenses/BSD-3-Clause)
|
|
||||||
[](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html)
|
|
||||||
[](https://github.com/rife2/bld-pmd/actions/workflows/bld.yml)
|
|
||||||
|
|
||||||
To check all source code using the [java quickstart rule](https://pmd.github.io/pmd/pmd_rules_java.html).
|
|
||||||
|
|
||||||
```java
|
|
||||||
@BuildCommand
|
|
||||||
public void pmd() throws Exception {
|
|
||||||
new PmdOperation(this).execute();
|
|
||||||
}
|
|
||||||
```
|
|
||||||
```text
|
|
||||||
./bld pmd test
|
|
||||||
```
|
|
||||||
|
|
||||||
To check the main source code using a custom rule, [java error prone rule](https://pmd.github.io/pmd/pmd_rules_java.html) and failing on any violation.
|
|
||||||
|
|
||||||
```java
|
|
||||||
@BuildCommand
|
|
||||||
public void pmdMain() throws Exception {
|
|
||||||
new PmdOperation(this)
|
|
||||||
.failOnValidation(true)
|
|
||||||
.addInputPath(project.srcMainDirectory().toPath())
|
|
||||||
.addRuletSet("config/pmd.xml", "category/java/errorprone.xml");
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
```text
|
|
||||||
./dld compile pmdMain
|
|
||||||
```
|
|
||||||
|
|
||||||
Please check the [PmdOperation documentation](https://rife2.github.io/bld-pmd/rife/bld/extension/PmdOperation.html#method-summary) for all available configuration options.
|
|
|
@ -43,13 +43,12 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
/**
|
/**
|
||||||
* The default rule set.
|
* The default rule set.
|
||||||
*/
|
*/
|
||||||
public static final String RULE_SET_DEFAULT = "rulesets/java/quickstart.xml";
|
public static final String RULESET_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 cache location.
|
* The cache location.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
Path cache;
|
Path cache;
|
||||||
/**
|
/**
|
||||||
|
@ -155,21 +154,21 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
||||||
|
|
||||||
inputPaths.add(project.srcMainDirectory().toPath());
|
inputPaths.add(project.srcMainDirectory().toPath());
|
||||||
inputPaths.add(project.srcTestDirectory().toPath());
|
inputPaths.add(project.srcTestDirectory().toPath());
|
||||||
ruleSets.add(RULE_SET_DEFAULT);
|
ruleSets.add(RULESET_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds paths to source files, or directories containing source files to analyze.
|
* Adds the path to a source file, or directory containing source files to analyze.
|
||||||
*
|
*
|
||||||
* @see #inputPaths(Path...)
|
* @see #inputPaths(Path...)
|
||||||
*/
|
*/
|
||||||
public PmdOperation addInputPath(Path... inputPath) {
|
public PmdOperation addInputPath(Path inputPath) {
|
||||||
inputPaths.addAll(List.of(inputPath));
|
inputPaths.add(inputPath);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds new rule set paths.
|
* Adds a new rule set path.
|
||||||
* <p>
|
* <p>
|
||||||
* The built-in rule set paths are:
|
* The built-in rule set paths are:
|
||||||
* <ul>
|
* <ul>
|
||||||
|
@ -186,8 +185,8 @@ 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));
|
ruleSets.add(ruleSet);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,35 +69,28 @@ public class PmdOperationTest {
|
||||||
void testJavaErrorProne() {
|
void testJavaErrorProne() {
|
||||||
var pmd = pmdOperation.ruleSets("category/java/errorprone.xml");
|
var pmd = pmdOperation.ruleSets("category/java/errorprone.xml");
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
||||||
.as("many errors").isGreaterThan(0);
|
.as("no errors").isGreaterThan(0);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testJavaCodeStyleAndErrorProne() {
|
|
||||||
var pmd = pmdOperation.addRuleSet("category/java/codestyle.xml", "category/java/errorprone.xml");
|
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
|
||||||
.as("many errors").isGreaterThan(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJavaCodeStyle() {
|
void testJavaCodeStyle() {
|
||||||
var pmd = pmdOperation.ruleSets("category/java/codestyle.xml");
|
var pmd = pmdOperation.ruleSets("category/java/codestyle.xml");
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
||||||
.as("many errors").isGreaterThan(0);
|
.as("no errors").isGreaterThan(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJavaDesign() {
|
void testJavaDesign() {
|
||||||
var pmd = pmdOperation.ruleSets("category/java/design.xml");
|
var pmd = pmdOperation.ruleSets("category/java/design.xml");
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
||||||
.as("many errors").isGreaterThan(0);
|
.as("no errors").isGreaterThan(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJavaDocumentation() {
|
void testJavaDocumentation() {
|
||||||
var pmd = pmdOperation.ruleSets("category/java/documentation.xml");
|
var pmd = pmdOperation.ruleSets("category/java/documentation.xml");
|
||||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
||||||
.as("many errors").isGreaterThan(0);
|
.as("no errors").isGreaterThan(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue