Skip to content

Commit

Permalink
Added support for PMD 7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Mar 22, 2024
1 parent 9bc04a4 commit 3f33710
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/bld/java/rife/bld/extension/PmdOperationBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public class PmdOperationBuild extends Project {
public PmdOperationBuild() {
pkg = "rife.bld.extension";
name = "bld-pmd";
version = version(0, 9, 7);
version = version(0, 9, 8);

javaRelease = 17;
downloadSources = true;
autoDownloadPurge = true;
repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);

var pmd = version(7, 0, 0, "rc4");
var pmd = version(7, 0, 0);
scope(compile)
.include(dependency("com.uwyn.rife2", "bld", version(1, 9, 0)))
.include(dependency("net.sourceforge.pmd", "pmd-java", pmd));
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/rife/bld/extension/PmdOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import net.sourceforge.pmd.PMDConfiguration;
import net.sourceforge.pmd.PmdAnalysis;
import net.sourceforge.pmd.RulePriority;
import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.rule.RulePriority;
import rife.bld.BaseProject;
import rife.bld.operations.AbstractOperation;

Expand Down Expand Up @@ -105,6 +105,10 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
* The report format.
*/
String reportFormat_ = "text";
/**
* The report properties.
*/
Properties reportProperties_ = null;
/**
* The show suppressed flag.
*/
Expand Down Expand Up @@ -359,6 +363,10 @@ public PMDConfiguration initConfiguration(String commandName) {
config.setInputPathList(inputPaths_);
}

if (reportProperties_ != null) {
config.setReportProperties(reportProperties_);
}

if (inputUri_ != null) {
config.setInputUri(inputUri_);
}
Expand All @@ -367,7 +375,8 @@ public PMDConfiguration initConfiguration(String commandName) {

if (project_ != null) {
config.setReportFile(Objects.requireNonNullElseGet(reportFile_,
() -> Paths.get(project_.buildDirectory().getPath(), PMD_DIR, PMD_DIR + "-report." + reportFormat_)));
() -> Paths.get(project_.buildDirectory().getPath(),
PMD_DIR, PMD_DIR + "-report." + reportFormat_)));
} else {
config.setReportFile(reportFile_);
}
Expand Down Expand Up @@ -430,7 +439,7 @@ public int performPmdAnalysis(String commandName, PMDConfiguration config) throw
v.getRule().getName(),
v.getRule().getExternalInfoUrl() //TODO bug in PMD?
.replace("${pmd.website.baseurl}",
"https://docs.pmd-code.org/pmd-doc-7.0.0-rc4"),
"https://docs.pmd-code.org/latest"),
v.getDescription()});
}
}
Expand Down Expand Up @@ -486,6 +495,14 @@ public PmdOperation reportFormat(String reportFormat) {
return this;
}

/**
* Set the Report properties. These are used to create the Renderer.
*/
public PmdOperation reportProperties(Properties reportProperties) {
reportProperties_ = reportProperties;
return this;
}

/**
* Sets the rule set path(s), disregarding any previously set paths.
* <p>
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/rife/bld/extension/PmdOperationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PmdOperationTest {
static final int CODING_STYLE_ERRORS = 13;
static final String COMMAND_NAME = "pmd";
static final String ERROR_PRONE = "category/java/errorprone.xml";
static final int ERROR_PRONE_ERRORS = 8;
static final int ERROR_PRONE_ERRORS = 6;
static final Path ERROR_PRONE_SAMPLE = Path.of("src/test/resources/java/ErrorProne.java");
static final String TEST = "test";

Expand Down Expand Up @@ -126,7 +126,7 @@ void testJavaCodeStyleAndErrorProne() {
.as("code style").isEqualTo(CODING_STYLE_ERRORS);
pmd = pmd.addRuleSet(ERROR_PRONE).addInputPath(ERROR_PRONE_SAMPLE);
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
.as("code style + error prone").isEqualTo(34);
.as("code style + error prone").isEqualTo(29);
}

@Test
Expand Down

0 comments on commit 3f33710

Please sign in to comment.