From 848cdce8f6c2c4acd809a0dc78798ddc80f4046d Mon Sep 17 00:00:00 2001 From: KolesnikovMS Date: Wed, 20 Mar 2024 01:24:59 +0300 Subject: [PATCH 01/13] MPMD-379 PMD 7.0.0 support --- pom.xml | 2 +- .../apache/maven/plugins/pmd/CpdReport.java | 11 +-- .../pmd/ExcludeDuplicationsFromFile.java | 2 +- .../pmd/ExcludeViolationsFromFile.java | 6 +- .../maven/plugins/pmd/exec/CpdExecutor.java | 98 +++++++++---------- .../maven/plugins/pmd/exec/PmdExecutor.java | 18 +--- 6 files changed, 63 insertions(+), 74 deletions(-) diff --git a/pom.xml b/pom.xml index 6a8c6994..73a3b604 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,7 @@ under the License. 3.2.5 8 - 6.55.0 + 7.0.0-rc4 1.7.36 1.0.0.v20140518 1.12.0 diff --git a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java index c01fdbc4..9ded7b35 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java @@ -23,8 +23,7 @@ import java.util.Locale; import java.util.Properties; -import net.sourceforge.pmd.cpd.JavaTokenizer; -import net.sourceforge.pmd.cpd.renderer.CPDRenderer; +import net.sourceforge.pmd.cpd.CPDReportRenderer; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -179,13 +178,13 @@ private void executeCpd() throws MavenReportException { Properties languageProperties = new Properties(); if (ignoreLiterals) { - languageProperties.setProperty(JavaTokenizer.IGNORE_LITERALS, "true"); + languageProperties.setProperty("ignore_literals", "true"); } if (ignoreIdentifiers) { - languageProperties.setProperty(JavaTokenizer.IGNORE_IDENTIFIERS, "true"); + languageProperties.setProperty("ignore_identifiers", "true"); } if (ignoreAnnotations) { - languageProperties.setProperty(JavaTokenizer.IGNORE_ANNOTATIONS, "true"); + languageProperties.setProperty("ignore_annotations", "true"); } try { filesToProcess = getFilesToProcess(); @@ -238,7 +237,7 @@ public String getOutputName() { * @deprecated Use {@link CpdExecutor#createRenderer(String, String)} instead. */ @Deprecated - public CPDRenderer createRenderer() throws MavenReportException { + public CPDReportRenderer createRenderer() throws MavenReportException { return CpdExecutor.createRenderer(format, getOutputEncoding()); } } diff --git a/src/main/java/org/apache/maven/plugins/pmd/ExcludeDuplicationsFromFile.java b/src/main/java/org/apache/maven/plugins/pmd/ExcludeDuplicationsFromFile.java index ea199a8c..87fff0a6 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/ExcludeDuplicationsFromFile.java +++ b/src/main/java/org/apache/maven/plugins/pmd/ExcludeDuplicationsFromFile.java @@ -64,7 +64,7 @@ public boolean isExcludedFromFailure(final Duplication errorDetail) { public boolean isExcludedFromFailure(final Match errorDetail) { final Set uniquePaths = new HashSet<>(); for (Mark mark : errorDetail.getMarkSet()) { - uniquePaths.add(mark.getFilename()); + uniquePaths.add(mark.getLocation().getFileId().getAbsolutePath()); } return isExcludedFromFailure(uniquePaths); } diff --git a/src/main/java/org/apache/maven/plugins/pmd/ExcludeViolationsFromFile.java b/src/main/java/org/apache/maven/plugins/pmd/ExcludeViolationsFromFile.java index 38919a48..b9381137 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/ExcludeViolationsFromFile.java +++ b/src/main/java/org/apache/maven/plugins/pmd/ExcludeViolationsFromFile.java @@ -84,8 +84,10 @@ public boolean isExcludedFromFailure(final Violation errorDetail) { * @return true if the violation should be excluded, false otherwise. */ public boolean isExcludedFromFailure(final RuleViolation errorDetail) { - final String className = - extractClassName(errorDetail.getPackageName(), errorDetail.getClassName(), errorDetail.getFilename()); + final String className = extractClassName( + errorDetail.getPackageName(), + errorDetail.getClassName(), + errorDetail.getFileId().getAbsolutePath()); return isExcludedFromFailure(className, errorDetail.getRule().getName()); } diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java index 43ba3c06..73abf358 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java +++ b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java @@ -26,23 +26,22 @@ import java.io.ObjectOutputStream; import java.io.OutputStreamWriter; import java.io.Writer; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; +import java.nio.charset.Charset; import java.util.Objects; +import java.util.function.Predicate; -import net.sourceforge.pmd.cpd.CPD; import net.sourceforge.pmd.cpd.CPDConfiguration; +import net.sourceforge.pmd.cpd.CPDReport; +import net.sourceforge.pmd.cpd.CPDReportRenderer; import net.sourceforge.pmd.cpd.CSVRenderer; -import net.sourceforge.pmd.cpd.EcmascriptLanguage; -import net.sourceforge.pmd.cpd.JSPLanguage; -import net.sourceforge.pmd.cpd.JavaLanguage; -import net.sourceforge.pmd.cpd.Language; -import net.sourceforge.pmd.cpd.LanguageFactory; +import net.sourceforge.pmd.cpd.CpdAnalysis; import net.sourceforge.pmd.cpd.Match; import net.sourceforge.pmd.cpd.SimpleRenderer; import net.sourceforge.pmd.cpd.XMLRenderer; -import net.sourceforge.pmd.cpd.renderer.CPDRenderer; +import net.sourceforge.pmd.lang.Language; +import net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule; +import net.sourceforge.pmd.lang.java.JavaLanguageModule; +import net.sourceforge.pmd.lang.jsp.JspLanguageModule; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.pmd.ExcludeDuplicationsFromFile; import org.apache.maven.reporting.MavenReportException; @@ -158,43 +157,44 @@ private CpdResult run() throws MavenReportException { Language cpdLanguage; if ("java".equals(request.getLanguage()) || null == request.getLanguage()) { - cpdLanguage = new JavaLanguage(request.getLanguageProperties()); + cpdLanguage = new JavaLanguageModule(); } else if ("javascript".equals(request.getLanguage())) { - cpdLanguage = new EcmascriptLanguage(); + cpdLanguage = new EcmascriptLanguageModule(); } else if ("jsp".equals(request.getLanguage())) { - cpdLanguage = new JSPLanguage(); + cpdLanguage = new JspLanguageModule(); } else { - cpdLanguage = LanguageFactory.createLanguage(request.getLanguage(), request.getLanguageProperties()); + cpdLanguage = cpdConfiguration.getLanguageRegistry().getLanguageById(request.getLanguage()); } - cpdConfiguration.setLanguage(cpdLanguage); - cpdConfiguration.setSourceEncoding(request.getSourceEncoding()); + cpdConfiguration.setOnlyRecognizeLanguage(cpdLanguage); + cpdConfiguration.setSourceEncoding(Charset.forName(request.getSourceEncoding())); - CPD cpd = new CPD(cpdConfiguration); - try { - cpd.add(request.getFiles()); - } catch (IOException e) { - throw new MavenReportException(e.getMessage(), e); - } + request.getFiles().forEach(f -> cpdConfiguration.addInputPath(f.toPath())); LOG.debug("Executing CPD..."); - cpd.go(); - LOG.debug("CPD finished."); // always create XML format. we need to output it even if the file list is empty or we have no duplications // so the "check" goals can check for violations - writeXmlReport(cpd); + CpdAnalysis cpd = CpdAnalysis.create(cpdConfiguration); + cpd.performAnalysis(report -> { + try { + writeXmlReport(report); - // html format is handled by maven site report, xml format has already been rendered - String format = request.getFormat(); - if (!"html".equals(format) && !"xml".equals(format)) { - writeFormattedReport(cpd); - } + // html format is handled by maven site report, xml format has already been rendered + String format = request.getFormat(); + if (!"html".equals(format) && !"xml".equals(format)) { + writeFormattedReport(report); + } + } catch (MavenReportException e) { + LOG.error(e.getMessage(), e); + } + }); + LOG.debug("CPD finished."); return new CpdResult(new File(request.getTargetDirectory(), "cpd.xml"), request.getOutputEncoding()); } - private void writeXmlReport(CPD cpd) throws MavenReportException { + private void writeXmlReport(CPDReport cpd) throws MavenReportException { File targetFile = writeReport(cpd, new XMLRenderer(request.getOutputEncoding()), "xml"); if (request.isIncludeXmlInSite()) { File siteDir = new File(request.getReportOutputDirectory()); @@ -207,7 +207,7 @@ private void writeXmlReport(CPD cpd) throws MavenReportException { } } - private File writeReport(CPD cpd, CPDRenderer r, String extension) throws MavenReportException { + private File writeReport(CPDReport cpd, CPDReportRenderer r, String extension) throws MavenReportException { if (r == null) { return null; } @@ -216,7 +216,7 @@ private File writeReport(CPD cpd, CPDRenderer r, String extension) throws MavenR targetDir.mkdirs(); File targetFile = new File(targetDir, "cpd." + extension); try (Writer writer = new OutputStreamWriter(new FileOutputStream(targetFile), request.getOutputEncoding())) { - r.render(filterMatches(cpd.getMatches()), writer); + r.render(cpd.filterMatches(filterMatches()), writer); writer.flush(); } catch (IOException ioe) { throw new MavenReportException(ioe.getMessage(), ioe); @@ -224,8 +224,8 @@ private File writeReport(CPD cpd, CPDRenderer r, String extension) throws MavenR return targetFile; } - private void writeFormattedReport(CPD cpd) throws MavenReportException { - CPDRenderer r = createRenderer(request.getFormat(), request.getOutputEncoding()); + private void writeFormattedReport(CPDReport cpd) throws MavenReportException { + CPDReportRenderer r = createRenderer(request.getFormat(), request.getOutputEncoding()); writeReport(cpd, r, request.getFormat()); } @@ -235,8 +235,8 @@ private void writeFormattedReport(CPD cpd) throws MavenReportException { * @return the renderer based on the configured output * @throws org.apache.maven.reporting.MavenReportException if no renderer found for the output type */ - public static CPDRenderer createRenderer(String format, String outputEncoding) throws MavenReportException { - CPDRenderer renderer = null; + public static CPDReportRenderer createRenderer(String format, String outputEncoding) throws MavenReportException { + CPDReportRenderer renderer = null; if ("xml".equals(format)) { renderer = new XMLRenderer(outputEncoding); } else if ("csv".equals(format)) { @@ -245,7 +245,8 @@ public static CPDRenderer createRenderer(String format, String outputEncoding) t renderer = new SimpleRenderer(); } else if (!"".equals(format) && !"none".equals(format)) { try { - renderer = (CPDRenderer) Class.forName(format).getConstructor().newInstance(); + renderer = (CPDReportRenderer) + Class.forName(format).getConstructor().newInstance(); } catch (Exception e) { throw new MavenReportException( "Can't find CPD custom format " + format + ": " @@ -257,22 +258,17 @@ public static CPDRenderer createRenderer(String format, String outputEncoding) t return renderer; } - private Iterator filterMatches(Iterator matches) { - LOG.debug("Filtering duplications. Using " + excludeDuplicationsFromFile.countExclusions() - + " configured exclusions."); + private Predicate filterMatches() { + return (Match match) -> { + LOG.debug("Filtering duplications. Using " + excludeDuplicationsFromFile.countExclusions() + + " configured exclusions."); - List filteredMatches = new ArrayList<>(); - int excludedDuplications = 0; - while (matches.hasNext()) { - Match match = matches.next(); if (excludeDuplicationsFromFile.isExcludedFromFailure(match)) { - excludedDuplications++; + LOG.debug("Excluded " + match + " duplications."); + return false; } else { - filteredMatches.add(match); + return true; } - } - - LOG.debug("Excluded " + excludedDuplications + " duplications."); - return filteredMatches.iterator(); + }; } } diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java index 8e96bf41..4e41255d 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java +++ b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java @@ -27,6 +27,7 @@ import java.io.ObjectOutputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -37,7 +38,6 @@ import net.sourceforge.pmd.RulePriority; import net.sourceforge.pmd.RuleSetLoadException; import net.sourceforge.pmd.RuleSetLoader; -import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.benchmark.TextTimingReportRenderer; import net.sourceforge.pmd.benchmark.TimeTracker; import net.sourceforge.pmd.benchmark.TimingReport; @@ -50,7 +50,6 @@ import net.sourceforge.pmd.renderers.Renderer; import net.sourceforge.pmd.renderers.TextRenderer; import net.sourceforge.pmd.renderers.XMLRenderer; -import net.sourceforge.pmd.util.Predicate; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.pmd.ExcludeViolationsFromFile; import org.apache.maven.reporting.MavenReportException; @@ -172,7 +171,7 @@ private PmdResult run() throws MavenReportException { configuration.setDefaultLanguageVersion(languageVersion); if (request.getSourceEncoding() != null) { - configuration.setSourceEncoding(request.getSourceEncoding()); + configuration.setSourceEncoding(Charset.forName(request.getSourceEncoding())); } configuration.prependAuxClasspath(request.getAuxClasspath()); @@ -189,9 +188,6 @@ private PmdResult run() throws MavenReportException { configuration.setRuleSets(request.getRulesets()); configuration.setMinimumPriority(RulePriority.valueOf(request.getMinimumPriority())); - if (request.getBenchmarkOutputLocation() != null) { - configuration.setBenchmark(true); - } List files = request.getFiles(); Report report = null; @@ -262,7 +258,7 @@ private PmdResult run() throws MavenReportException { private String getErrorsAsString(List errors, boolean withDetails) { List errorsAsString = new ArrayList<>(errors.size()); for (Report.ProcessingError error : errors) { - errorsAsString.add(error.getFile() + ": " + error.getMsg()); + errorsAsString.add(error.getFileId().getAbsolutePath() + ": " + error.getMsg()); if (withDetails) { errorsAsString.add(error.getDetail()); } @@ -413,12 +409,8 @@ private Report removeExcludedViolations(Report report) throws MavenReportExcepti LOG.debug("Removing excluded violations. Using {} configured exclusions.", excludeFromFile.countExclusions()); int violationsBefore = report.getViolations().size(); - Report filtered = report.filterViolations(new Predicate() { - @Override - public boolean test(RuleViolation ruleViolation) { - return !excludeFromFile.isExcludedFromFailure(ruleViolation); - } - }); + Report filtered = + report.filterViolations(ruleViolation -> !excludeFromFile.isExcludedFromFailure(ruleViolation)); int numberOfExcludedViolations = violationsBefore - filtered.getViolations().size(); From c1b357fcb0d4bbc0d835d57d6f31ff41e652b39f Mon Sep 17 00:00:00 2001 From: KolesnikovMS Date: Wed, 20 Mar 2024 03:45:48 +0300 Subject: [PATCH 02/13] MPMD-379 fixed unit and integration tests --- .../verify.groovy | 2 +- src/it/MPMD-244-logging/verify.groovy | 7 ++++--- .../invoker.properties | 1 + src/it/MPMD-268-deprecated-rules/verify.groovy | 2 +- src/it/mpmd-138/verify.groovy | 6 +++--- .../maven/plugins/pmd/exec/PmdExecutor.java | 3 +++ .../maven/plugins/pmd/CpdReportTest.java | 4 ++-- .../maven/plugins/pmd/PmdReportTest.java | 18 ++++++++++-------- .../def/configuration/App.java | 4 ++-- .../def/configuration/AppSample.java | 2 +- 10 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/it/MPMD-219-pmd-processing-error/verify.groovy b/src/it/MPMD-219-pmd-processing-error/verify.groovy index 0656c50b..87f701ce 100644 --- a/src/it/MPMD-219-pmd-processing-error/verify.groovy +++ b/src/it/MPMD-219-pmd-processing-error/verify.groovy @@ -20,5 +20,5 @@ File buildLog = new File( basedir, 'build.log' ) assert buildLog.exists() assert buildLog.text.contains( "PMD processing errors" ) -assert buildLog.text.contains( "Error while parsing" ) +assert buildLog.text.contains( "Parse exception in file" ) assert buildLog.text.contains( "BrokenFile.java" ) diff --git a/src/it/MPMD-244-logging/verify.groovy b/src/it/MPMD-244-logging/verify.groovy index 459b2b9d..5ceb3d03 100644 --- a/src/it/MPMD-244-logging/verify.groovy +++ b/src/it/MPMD-244-logging/verify.groovy @@ -20,12 +20,13 @@ File buildLog = new File( basedir, 'build.log' ) assert buildLog.exists() assert buildLog.text.contains( "PMD processing errors" ) -assert buildLog.text.contains( "Error while parsing" ) +assert buildLog.text.contains( "Parse exception in file" ) String disabledPath = new File( basedir, 'logging-disabled/src/main/java/BrokenFile.java' ).getCanonicalPath() String enabledPath = new File( basedir, 'logging-enabled/src/main/java/BrokenFile.java' ).getCanonicalPath() // logging disabled: the pmd exception is only output through the processing error reporting (since MPMD-246) -assert 1 == buildLog.text.count( "net.sourceforge.pmd.PMDException: Error while parsing ${disabledPath}" ) +assert 1 == buildLog.text.count( "net.sourceforge.pmd.lang.ast.ParseException: Parse exception in file \'${disabledPath}\'" ) // logging enabled: the pmd exception is output twice: through the processing error reporting (since MPMD-246) and through PMD's own logging -assert 2 == buildLog.text.count( "net.sourceforge.pmd.PMDException: Error while parsing ${enabledPath}" ) +// not true anymore, logged always once +assert 1 == buildLog.text.count( "net.sourceforge.pmd.lang.ast.ParseException: Parse exception in file \'${enabledPath}\'" ) diff --git a/src/it/MPMD-258-multiple-executions/invoker.properties b/src/it/MPMD-258-multiple-executions/invoker.properties index 02b72c7d..72ceb8f0 100644 --- a/src/it/MPMD-258-multiple-executions/invoker.properties +++ b/src/it/MPMD-258-multiple-executions/invoker.properties @@ -15,5 +15,6 @@ # specific language governing permissions and limitations # under the License. +invoker.debug = true invoker.goals = clean compile pmd:pmd invoker.maven.version = 3.1.0+ diff --git a/src/it/MPMD-268-deprecated-rules/verify.groovy b/src/it/MPMD-268-deprecated-rules/verify.groovy index 009a5dd8..71e9b409 100644 --- a/src/it/MPMD-268-deprecated-rules/verify.groovy +++ b/src/it/MPMD-268-deprecated-rules/verify.groovy @@ -19,4 +19,4 @@ File buildLog = new File( basedir, 'build.log' ) assert buildLog.exists() -assert buildLog.text.contains( "[WARNING] Use Rule name category/java/codestyle.xml/ControlStatementBraces instead of the deprecated" ) +assert buildLog.text.contains( "Use Rule name category/java/codestyle.xml/ControlStatementBraces instead of the deprecated Rule name" ) diff --git a/src/it/mpmd-138/verify.groovy b/src/it/mpmd-138/verify.groovy index 0a3a32bd..a1d9cc77 100644 --- a/src/it/mpmd-138/verify.groovy +++ b/src/it/mpmd-138/verify.groovy @@ -22,12 +22,12 @@ File buildLog = new File( basedir, 'build.log' ) assert buildLog.exists() // Module 1 -assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:27 Rule:UnnecessarySemicolon Priority:3 Unnecessary semicolon') -assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:28 Rule:UnnecessaryReturn Priority:3 Avoid unnecessary return statements') +assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:27 Rule:UnnecessarySemicolon Priority:3 Unnecessary semicolon.') +assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:28 Rule:UnnecessaryReturn Priority:3 Unnecessary return statement.') assert 1 == buildLog.getText().count('[INFO] You have 2 PMD violations. For more details see:') // Module 2 -assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:24 Rule:UnusedPrivateField Priority:3 Avoid unused private fields such as \'x\'') +assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:24 Rule:UnusedPrivateField Priority:3 Avoid unused private fields such as \'x\'..') assert 1 == buildLog.getText().count('[INFO] You have 1 PMD violation. For more details see:') // Module 3 diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java index 4e41255d..c4c7191d 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java +++ b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java @@ -188,6 +188,9 @@ private PmdResult run() throws MavenReportException { configuration.setRuleSets(request.getRulesets()); configuration.setMinimumPriority(RulePriority.valueOf(request.getMinimumPriority())); + if (request.getBenchmarkOutputLocation() != null) { + TimeTracker.startGlobalTracking(); + } List files = request.getFiles(); Report report = null; diff --git a/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java b/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java index b7657bf1..633ab327 100644 --- a/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java +++ b/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java @@ -62,7 +62,7 @@ public void testDefaultConfiguration() throws Exception { assertTrue(lowerCaseContains(str, "AppSample.java")); assertTrue(lowerCaseContains(str, "App.java")); assertTrue(lowerCaseContains(str, "public String dup( String str )")); - assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring( i, i + 1);")); + assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring( i, (i + 1));")); // the version should be logged String output = CapturingPrintStream.getOutput(); @@ -149,7 +149,7 @@ public void testWriteNonHtml() throws Exception { assertTrue(lowerCaseContains(str, "AppSample.java")); assertTrue(lowerCaseContains(str, "App.java")); assertTrue(lowerCaseContains(str, "public String dup( String str )")); - assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring( i, i + 1);")); + assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring( i, (i + 1));")); } /** diff --git a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java index b8ec9c33..4042423b 100644 --- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java +++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java @@ -424,7 +424,8 @@ public void testSuppressMarkerConfiguration() throws Exception { // check that there is no violation reported for "unusedVar2" - as it is suppressed assertFalse(str.contains("Avoid unused private fields such as 'unusedVar2'.\n ")); // but it appears as suppressed - assertTrue(str.contains("suppressiontype=\"nopmd\" msg=\"Avoid unused private fields such as 'unusedVar2'.\"")); + assertTrue( + str.contains("suppressiontype=\"//nopmd\" msg=\"Avoid unused private fields such as 'unusedVar2'.\"")); // check if there's a link to the JXR files str = readFile(generatedReport); @@ -448,7 +449,8 @@ public void testSuppressMarkerConfigurationWithoutRendering() throws Exception { // check that there is no violation reported for "unusedVar2" - as it is suppressed assertFalse(str.contains("Avoid unused private fields such as 'unusedVar2'.\n ")); // but it appears as suppressed - assertTrue(str.contains("suppressiontype=\"nopmd\" msg=\"Avoid unused private fields such as 'unusedVar2'.\"")); + assertTrue( + str.contains("suppressiontype=\"//nopmd\" msg=\"Avoid unused private fields such as 'unusedVar2'.\"")); // check if there's a link to the JXR files str = readFile(generatedReport); @@ -512,13 +514,13 @@ public void testPMDProcessingErrorWithDetailsSkipped() throws Exception { File generatedFile = new File(getBasedir(), "target/test/unit/parse-error/target/pmd.xml"); assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath())); String str = readFile(generatedFile); - assertTrue(str.contains("Error while parsing")); + assertTrue(str.contains("Parse exception in file")); // The parse exception must be in the XML report - assertTrue(str.contains("ParseException: Encountered \"\" at line 23, column 5.")); + assertTrue(str.contains("\' at line 23, column 5: Encountered .")); str = readFile(generatedReport); // The parse exception must also be in the HTML report - assertTrue(str.contains("ParseException: Encountered \"\" at line 23, column 5.")); + assertTrue(str.contains("\' at line 23, column 5: Encountered .")); } public void testPMDProcessingErrorWithDetailsNoReport() throws Exception { @@ -532,13 +534,13 @@ public void testPMDProcessingErrorWithDetailsNoReport() throws Exception { File generatedFile = new File(getBasedir(), "target/test/unit/parse-error/target/pmd.xml"); assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath())); String str = readFile(generatedFile); - assertTrue(str.contains("Error while parsing")); + assertTrue(str.contains("Parse exception in file")); // The parse exception must be in the XML report - assertTrue(str.contains("ParseException: Encountered \"\" at line 23, column 5.")); + assertTrue(str.contains("\' at line 23, column 5: Encountered .")); str = readFile(generatedReport); // The parse exception must NOT be in the HTML report, since reportProcessingErrors is false - assertFalse(str.contains("ParseException: Encountered \"\" at line 23, column 5.")); + assertFalse(str.contains("\' at line 23, column 5: Encountered .")); } public void testPMDExcludeRootsShouldExcludeSubdirectories() throws Exception { diff --git a/src/test/resources/unit/default-configuration/def/configuration/App.java b/src/test/resources/unit/default-configuration/def/configuration/App.java index da53df01..4884d1e3 100644 --- a/src/test/resources/unit/default-configuration/def/configuration/App.java +++ b/src/test/resources/unit/default-configuration/def/configuration/App.java @@ -77,9 +77,9 @@ public String dup( String str ) for( int i = 0; i < str.length(); i++ ) { - if ( i != ( str.length() -1 ) ) + if ( i != ( str.length() -1 ) ) // not reported with PMD7 { - tmp = tmp + str.substring( i, i + 1); + tmp = tmp + str.substring( i, (i + 1)); // UselessParentheses } else { diff --git a/src/test/resources/unit/default-configuration/def/configuration/AppSample.java b/src/test/resources/unit/default-configuration/def/configuration/AppSample.java index 201bf191..6fcc8d09 100644 --- a/src/test/resources/unit/default-configuration/def/configuration/AppSample.java +++ b/src/test/resources/unit/default-configuration/def/configuration/AppSample.java @@ -57,7 +57,7 @@ public String dup( String str ) { if ( i != ( str.length() -1 ) ) { - tmp = tmp + str.substring( i, i + 1); + tmp = tmp + str.substring( i, (i + 1)); } else { From 53d907bb5cd16f9686628545db7cc0764cec1cb7 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 17 Feb 2024 20:45:48 +0300 Subject: [PATCH 03/13] Fix tests for PMD 7 compatibility --- pom.xml | 2 +- .../verify.groovy | 2 +- .../config/ruleset.xml | 2 +- src/it/MPMD-244-logging/verify.groovy | 15 ++++++--- .../verify.groovy | 2 ++ .../MPMD-304-toolchain-support/verify.groovy | 4 +-- .../src/main/pmd/ruleset.xml | 2 +- src/it/mpmd-138/verify.groovy | 8 ++--- .../maven/plugins/pmd/PmdReportTest.java | 32 ++++++++++--------- .../def/configuration/App.java | 6 ++-- .../def/configuration/AppSample.java | 4 +-- .../pmd-report-resolve-rulesets.xml | 2 +- .../rulesets/custom-rules.xml | 2 +- 13 files changed, 46 insertions(+), 37 deletions(-) diff --git a/pom.xml b/pom.xml index 73a3b604..c1345e84 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,7 @@ under the License. 3.2.5 8 - 7.0.0-rc4 + 7.0.0 1.7.36 1.0.0.v20140518 1.12.0 diff --git a/src/it/MPMD-219-pmd-processing-error/verify.groovy b/src/it/MPMD-219-pmd-processing-error/verify.groovy index 87f701ce..ea9d8028 100644 --- a/src/it/MPMD-219-pmd-processing-error/verify.groovy +++ b/src/it/MPMD-219-pmd-processing-error/verify.groovy @@ -20,5 +20,5 @@ File buildLog = new File( basedir, 'build.log' ) assert buildLog.exists() assert buildLog.text.contains( "PMD processing errors" ) -assert buildLog.text.contains( "Parse exception in file" ) +assert buildLog.text.contains( "ParseException: Parse exception in file" ) assert buildLog.text.contains( "BrokenFile.java" ) diff --git a/src/it/MPMD-243-excludeFromFailureFile/config/ruleset.xml b/src/it/MPMD-243-excludeFromFailureFile/config/ruleset.xml index c337933e..47daac15 100644 --- a/src/it/MPMD-243-excludeFromFailureFile/config/ruleset.xml +++ b/src/it/MPMD-243-excludeFromFailureFile/config/ruleset.xml @@ -26,5 +26,5 @@ under the License. MPMD-243 - + diff --git a/src/it/MPMD-244-logging/verify.groovy b/src/it/MPMD-244-logging/verify.groovy index 5ceb3d03..dfdc8d9e 100644 --- a/src/it/MPMD-244-logging/verify.groovy +++ b/src/it/MPMD-244-logging/verify.groovy @@ -20,13 +20,18 @@ File buildLog = new File( basedir, 'build.log' ) assert buildLog.exists() assert buildLog.text.contains( "PMD processing errors" ) -assert buildLog.text.contains( "Parse exception in file" ) +assert buildLog.text.contains( "ParseException: Parse exception" ) +assert buildLog.text.contains( "at line 24, column 5: Encountered" ) String disabledPath = new File( basedir, 'logging-disabled/src/main/java/BrokenFile.java' ).getCanonicalPath() String enabledPath = new File( basedir, 'logging-enabled/src/main/java/BrokenFile.java' ).getCanonicalPath() // logging disabled: the pmd exception is only output through the processing error reporting (since MPMD-246) -assert 1 == buildLog.text.count( "net.sourceforge.pmd.lang.ast.ParseException: Parse exception in file \'${disabledPath}\'" ) -// logging enabled: the pmd exception is output twice: through the processing error reporting (since MPMD-246) and through PMD's own logging -// not true anymore, logged always once -assert 1 == buildLog.text.count( "net.sourceforge.pmd.lang.ast.ParseException: Parse exception in file \'${enabledPath}\'" ) +assert 1 == buildLog.text.count( "${disabledPath}: ParseException: Parse exception in" ) +// logging enabled: the pmd exception is still output only once: through the processing error reporting (since MPMD-246) - PMD 7 doesn't log the processing error additionally +assert 1 == buildLog.text.count( "${enabledPath}: ParseException: Parse exception in" ) + +// build.log contains the logging from the two PMD executions +// only one execution has logging enabled, so we expect only one log output +// TODO assert 1 == buildLog.text.count( "[DEBUG] Rules loaded from" ) +// TODO logging is always enabled and can't be disabled, because PMD 7 switched to slf4j diff --git a/src/it/MPMD-258-multiple-executions/verify.groovy b/src/it/MPMD-258-multiple-executions/verify.groovy index b6622b1b..1925c675 100644 --- a/src/it/MPMD-258-multiple-executions/verify.groovy +++ b/src/it/MPMD-258-multiple-executions/verify.groovy @@ -21,7 +21,9 @@ File buildLog = new File( basedir, 'build.log' ) assert buildLog.exists() // we have 2 modules and for each module this should be output once +// note: this is only logged in debug mode by net.sourceforge.pmd.cache.FileAnalysisCache assert 2 == buildLog.text.count( "Analysis cache created" ) // since we are running clean pmd:pmd, the cache is always created, never updated +// note: this is only logged in debug mode by net.sourceforge.pmd.cache.FileAnalysisCache assert 0 == buildLog.text.count( "Analysis cache updated" ) diff --git a/src/it/MPMD-304-toolchain-support/verify.groovy b/src/it/MPMD-304-toolchain-support/verify.groovy index 73702257..21aa3491 100644 --- a/src/it/MPMD-304-toolchain-support/verify.groovy +++ b/src/it/MPMD-304-toolchain-support/verify.groovy @@ -29,8 +29,8 @@ assert buildLog.text.contains( '[INFO] You have 1 CPD duplication' ) File pmdReport = new File( basedir, 'target/pmd.xml' ) assert pmdReport.exists() -assert pmdReport.text.contains( ' Custom Ruleset for test case MPMD-89 and MPMP-232 - + diff --git a/src/it/mpmd-138/verify.groovy b/src/it/mpmd-138/verify.groovy index a1d9cc77..b9dc0f75 100644 --- a/src/it/mpmd-138/verify.groovy +++ b/src/it/mpmd-138/verify.groovy @@ -22,16 +22,16 @@ File buildLog = new File( basedir, 'build.log' ) assert buildLog.exists() // Module 1 -assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:27 Rule:UnnecessarySemicolon Priority:3 Unnecessary semicolon.') -assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:28 Rule:UnnecessaryReturn Priority:3 Unnecessary return statement.') +assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:27 Rule:UnnecessarySemicolon Priority:3 Unnecessary semicolon') +assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:28 Rule:UnnecessaryReturn Priority:3 Unnecessary return statement') assert 1 == buildLog.getText().count('[INFO] You have 2 PMD violations. For more details see:') // Module 2 -assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:24 Rule:UnusedPrivateField Priority:3 Avoid unused private fields such as \'x\'..') +assert 1 == buildLog.getText().count('[INFO] PMD Failure: test.MyClass:24 Rule:UnusedPrivateField Priority:3 Avoid unused private fields such as \'x\'') assert 1 == buildLog.getText().count('[INFO] You have 1 PMD violation. For more details see:') // Module 3 assert 1 == buildLog.getText().count('[INFO] You have 1 CPD duplication. For more details see:') // Module 4 -assert 1 == buildLog.getText().count('[INFO] You have 2 CPD duplications. For more details see:') \ No newline at end of file +assert 1 == buildLog.getText().count('[INFO] You have 2 CPD duplications. For more details see:') diff --git a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java index 4042423b..bd6dc24d 100644 --- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java +++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java @@ -216,9 +216,9 @@ public void testFileURL() throws Exception { .withHeader("Content-Type", "text/xml") .withBody(sonarRuleset))); - URL url = getClass().getClassLoader().getResource("rulesets/java/basic.xml"); - URL url2 = getClass().getClassLoader().getResource("rulesets/java/unusedcode.xml"); - URL url3 = getClass().getClassLoader().getResource("rulesets/java/imports.xml"); + URL url = getClass().getClassLoader().getResource("category/java/bestpractices.xml"); + URL url2 = getClass().getClassLoader().getResource("category/java/codestyle.xml"); + URL url3 = getClass().getClassLoader().getResource("category/java/errorprone.xml"); mojo.setRulesets(new String[] {url.toString(), url2.toString(), url3.toString(), sonarExportRulesetUrl}); File generatedReport = generateReport(mojo, testPom); @@ -229,16 +229,16 @@ public void testFileURL() throws Exception { assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath())); // the resolved and extracted rulesets - generatedFile = - new File(getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/001-basic.xml"); + generatedFile = new File( + getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/001-bestpractices.xml"); assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath())); generatedFile = - new File(getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/002-unusedcode.xml"); + new File(getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/002-codestyle.xml"); assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath())); generatedFile = - new File(getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/003-imports.xml"); + new File(getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/003-errorprone.xml"); assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath())); generatedFile = new File( @@ -514,13 +514,14 @@ public void testPMDProcessingErrorWithDetailsSkipped() throws Exception { File generatedFile = new File(getBasedir(), "target/test/unit/parse-error/target/pmd.xml"); assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath())); String str = readFile(generatedFile); - assertTrue(str.contains("Parse exception in file")); + assertTrue(str.contains("ParseException: Parse exception in file")); // The parse exception must be in the XML report - assertTrue(str.contains("\' at line 23, column 5: Encountered .")); + assertTrue(str.contains("at line 23, column 5: Encountered")); str = readFile(generatedReport); // The parse exception must also be in the HTML report - assertTrue(str.contains("\' at line 23, column 5: Encountered .")); + assertTrue(str.contains("ParseException:")); + assertTrue(str.contains("at line 23, column 5: Encountered")); } public void testPMDProcessingErrorWithDetailsNoReport() throws Exception { @@ -534,13 +535,14 @@ public void testPMDProcessingErrorWithDetailsNoReport() throws Exception { File generatedFile = new File(getBasedir(), "target/test/unit/parse-error/target/pmd.xml"); assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath())); String str = readFile(generatedFile); - assertTrue(str.contains("Parse exception in file")); // The parse exception must be in the XML report - assertTrue(str.contains("\' at line 23, column 5: Encountered .")); + assertTrue(str.contains("ParseException: Parse exception in file")); + assertTrue(str.contains("at line 23, column 5: Encountered")); str = readFile(generatedReport); // The parse exception must NOT be in the HTML report, since reportProcessingErrors is false - assertFalse(str.contains("\' at line 23, column 5: Encountered .")); + assertFalse(str.contains("ParseException:")); + assertFalse(str.contains("at line 23, column 5: Encountered")); } public void testPMDExcludeRootsShouldExcludeSubdirectories() throws Exception { @@ -652,8 +654,8 @@ public void testPmdReportResolveRulesets() throws Exception { getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/002-bestpractices.xml"); assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath())); - generatedFile = new File( - getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/003-java-design.xml"); + generatedFile = + new File(getBasedir(), "target/test/unit/default-configuration/target/pmd/rulesets/003-design.xml"); assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath())); generatedFile = new File( diff --git a/src/test/resources/unit/default-configuration/def/configuration/App.java b/src/test/resources/unit/default-configuration/def/configuration/App.java index 4884d1e3..cb251eac 100644 --- a/src/test/resources/unit/default-configuration/def/configuration/App.java +++ b/src/test/resources/unit/default-configuration/def/configuration/App.java @@ -77,9 +77,9 @@ public String dup( String str ) for( int i = 0; i < str.length(); i++ ) { - if ( i != ( str.length() -1 ) ) // not reported with PMD7 + if ( i != ( ( str.length() -1 ) ) ) { - tmp = tmp + str.substring( i, (i + 1)); // UselessParentheses + tmp = tmp + str.substring( i, i + 1); } else { @@ -96,4 +96,4 @@ public String dup( String str ) return tmp; } -} \ No newline at end of file +} diff --git a/src/test/resources/unit/default-configuration/def/configuration/AppSample.java b/src/test/resources/unit/default-configuration/def/configuration/AppSample.java index 6fcc8d09..bc9cac02 100644 --- a/src/test/resources/unit/default-configuration/def/configuration/AppSample.java +++ b/src/test/resources/unit/default-configuration/def/configuration/AppSample.java @@ -55,7 +55,7 @@ public String dup( String str ) for( int i = 0; i < str.length(); i++ ) { - if ( i != ( str.length() -1 ) ) + if ( i != ( ( str.length() -1 ) ) ) { tmp = tmp + str.substring( i, (i + 1)); } @@ -74,4 +74,4 @@ public String dup( String str ) return tmp; } -} \ No newline at end of file +} diff --git a/src/test/resources/unit/default-configuration/pmd-report-resolve-rulesets.xml b/src/test/resources/unit/default-configuration/pmd-report-resolve-rulesets.xml index a36a855f..ba37dd30 100644 --- a/src/test/resources/unit/default-configuration/pmd-report-resolve-rulesets.xml +++ b/src/test/resources/unit/default-configuration/pmd-report-resolve-rulesets.xml @@ -41,7 +41,7 @@ under the License. ${basedir}/src/test/resources/unit/default-configuration/rulesets/custom-rules.xml category/java/bestpractices.xml - java-design + category/java/design.xml http://localhost:12345/profiles/export?format=pmd&language=java&name=Sonar%2520way http://localhost:12345/config/my-ruleset.xml diff --git a/src/test/resources/unit/default-configuration/rulesets/custom-rules.xml b/src/test/resources/unit/default-configuration/rulesets/custom-rules.xml index 4946c530..bb38c911 100644 --- a/src/test/resources/unit/default-configuration/rulesets/custom-rules.xml +++ b/src/test/resources/unit/default-configuration/rulesets/custom-rules.xml @@ -36,7 +36,7 @@ under the License. From 6b7a3e83c10d8fd64002050c714fd0ea61dde76b Mon Sep 17 00:00:00 2001 From: KolesnikovMS Date: Fri, 22 Mar 2024 14:12:30 +0300 Subject: [PATCH 04/13] [MPMD-379] Updated PMD to 7.0.0 --- pom.xml | 2 +- .../mod-1/src/main/config/pmd/utf-8.xml | 2 +- .../mod-2/rulesets/java/basic.xml | 2 +- .../mod-3/src/main/config/pmd/rel.xml | 2 +- .../apache/maven/plugins/pmd/CpdReport.java | 15 ++-------- .../pmd/ExcludeViolationsFromFile.java | 7 +++-- .../maven/plugins/pmd/PmdReportRenderer.java | 2 +- .../maven/plugins/pmd/exec/CpdExecutor.java | 30 +++++++++++-------- .../maven/plugins/pmd/exec/CpdRequest.java | 27 +++++++++++++++++ .../maven/plugins/pmd/exec/PmdExecutor.java | 14 ++++----- .../examples/upgrading-PMD-at-runtime.apt.vm | 2 ++ .../maven/plugins/pmd/CpdReportTest.java | 4 +-- .../maven/plugins/pmd/PmdReportTest.java | 4 +-- .../def/configuration/AppSample.java | 2 +- .../rulesets/custom-rules.xml | 2 +- 15 files changed, 72 insertions(+), 45 deletions(-) diff --git a/pom.xml b/pom.xml index c1345e84..93d42df0 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ under the License. maven-pmd-plugin - 3.21.3-SNAPSHOT + 3.22.0-SNAPSHOT maven-plugin Apache Maven PMD Plugin diff --git a/src/it/multi-module/mod-1/src/main/config/pmd/utf-8.xml b/src/it/multi-module/mod-1/src/main/config/pmd/utf-8.xml index 32ad7868..8e4fc166 100644 --- a/src/it/multi-module/mod-1/src/main/config/pmd/utf-8.xml +++ b/src/it/multi-module/mod-1/src/main/config/pmd/utf-8.xml @@ -23,5 +23,5 @@ under the License. This ruleset is encoded with UTF-8 to check proper encoding handling. - + diff --git a/src/it/multi-module/mod-2/rulesets/java/basic.xml b/src/it/multi-module/mod-2/rulesets/java/basic.xml index 1bf26926..8274fe41 100644 --- a/src/it/multi-module/mod-2/rulesets/java/basic.xml +++ b/src/it/multi-module/mod-2/rulesets/java/basic.xml @@ -23,5 +23,5 @@ under the License. The relative path of this ruleset matches the built-in ruleset "basic". - + diff --git a/src/it/multi-module/mod-3/src/main/config/pmd/rel.xml b/src/it/multi-module/mod-3/src/main/config/pmd/rel.xml index 05fa23cb..08b4a638 100644 --- a/src/it/multi-module/mod-3/src/main/config/pmd/rel.xml +++ b/src/it/multi-module/mod-3/src/main/config/pmd/rel.xml @@ -23,5 +23,5 @@ under the License. This ruleset is specified via a relative filesystem path. - + diff --git a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java index 9ded7b35..3b424de6 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.Locale; -import java.util.Properties; import net.sourceforge.pmd.cpd.CPDReportRenderer; import org.apache.maven.plugins.annotations.Component; @@ -176,23 +175,15 @@ private void executeCpd() throws MavenReportException { return; } - Properties languageProperties = new Properties(); - if (ignoreLiterals) { - languageProperties.setProperty("ignore_literals", "true"); - } - if (ignoreIdentifiers) { - languageProperties.setProperty("ignore_identifiers", "true"); - } - if (ignoreAnnotations) { - languageProperties.setProperty("ignore_annotations", "true"); - } try { filesToProcess = getFilesToProcess(); CpdRequest request = new CpdRequest(); request.setMinimumTokens(minimumTokens); request.setLanguage(language); - request.setLanguageProperties(languageProperties); + request.setIgnoreAnnotations(ignoreAnnotations); + request.setIgnoreIdentifiers(ignoreIdentifiers); + request.setIgnoreLiterals(ignoreLiterals); request.setSourceEncoding(getInputEncoding()); request.addFiles(filesToProcess.keySet()); diff --git a/src/main/java/org/apache/maven/plugins/pmd/ExcludeViolationsFromFile.java b/src/main/java/org/apache/maven/plugins/pmd/ExcludeViolationsFromFile.java index b9381137..da5a7db5 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/ExcludeViolationsFromFile.java +++ b/src/main/java/org/apache/maven/plugins/pmd/ExcludeViolationsFromFile.java @@ -28,7 +28,7 @@ import java.util.Properties; import java.util.Set; -import net.sourceforge.pmd.RuleViolation; +import net.sourceforge.pmd.reporting.RuleViolation; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.pmd.model.Violation; @@ -84,9 +84,10 @@ public boolean isExcludedFromFailure(final Violation errorDetail) { * @return true if the violation should be excluded, false otherwise. */ public boolean isExcludedFromFailure(final RuleViolation errorDetail) { + final Map additionalInfo = errorDetail.getAdditionalInfo(); final String className = extractClassName( - errorDetail.getPackageName(), - errorDetail.getClassName(), + additionalInfo.get(RuleViolation.PACKAGE_NAME), + additionalInfo.get(RuleViolation.CLASS_NAME), errorDetail.getFileId().getAbsolutePath()); return isExcludedFromFailure(className, errorDetail.getRule().getName()); } diff --git a/src/main/java/org/apache/maven/plugins/pmd/PmdReportRenderer.java b/src/main/java/org/apache/maven/plugins/pmd/PmdReportRenderer.java index 1665f2c9..d961eebb 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/PmdReportRenderer.java +++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReportRenderer.java @@ -30,7 +30,7 @@ import java.util.Locale; import java.util.Map; -import net.sourceforge.pmd.RulePriority; +import net.sourceforge.pmd.lang.rule.RulePriority; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.pmd.model.ProcessingError; diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java index 73abf358..cacf0bf7 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java +++ b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java @@ -154,6 +154,9 @@ private CpdResult run() throws MavenReportException { CPDConfiguration cpdConfiguration = new CPDConfiguration(); cpdConfiguration.setMinimumTileSize(request.getMinimumTokens()); + cpdConfiguration.setIgnoreAnnotations(request.isIgnoreAnnotations()); + cpdConfiguration.setIgnoreLiterals(request.isIgnoreLiterals()); + cpdConfiguration.setIgnoreIdentifiers(request.isIgnoreIdentifiers()); Language cpdLanguage; if ("java".equals(request.getLanguage()) || null == request.getLanguage()) { @@ -175,20 +178,23 @@ private CpdResult run() throws MavenReportException { // always create XML format. we need to output it even if the file list is empty or we have no duplications // so the "check" goals can check for violations - CpdAnalysis cpd = CpdAnalysis.create(cpdConfiguration); - cpd.performAnalysis(report -> { - try { - writeXmlReport(report); + try (CpdAnalysis cpd = CpdAnalysis.create(cpdConfiguration)) { + cpd.performAnalysis(report -> { + try { + writeXmlReport(report); - // html format is handled by maven site report, xml format has already been rendered - String format = request.getFormat(); - if (!"html".equals(format) && !"xml".equals(format)) { - writeFormattedReport(report); + // html format is handled by maven site report, xml format has already been rendered + String format = request.getFormat(); + if (!"html".equals(format) && !"xml".equals(format)) { + writeFormattedReport(report); + } + } catch (MavenReportException e) { + LOG.error(e.getMessage(), e); } - } catch (MavenReportException e) { - LOG.error(e.getMessage(), e); - } - }); + }); + } catch (IOException e) { + LOG.error(e.getMessage(), e); + } LOG.debug("CPD finished."); return new CpdResult(new File(request.getTargetDirectory(), "cpd.xml"), request.getOutputEncoding()); diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdRequest.java b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdRequest.java index ebbff049..96bc5557 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdRequest.java +++ b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdRequest.java @@ -53,6 +53,9 @@ public class CpdRequest implements Serializable { private String format; private boolean includeXmlInSite; private String reportOutputDirectory; + private boolean ignoreAnnotations; + private boolean ignoreIdentifiers; + private boolean ignoreLiterals; public void setJavaExecutable(String javaExecutable) { this.javaExecutable = javaExecutable; @@ -165,4 +168,28 @@ public boolean isShowPmdLog() { public String getLogLevel() { return logLevel; } + + public boolean isIgnoreAnnotations() { + return ignoreAnnotations; + } + + public void setIgnoreAnnotations(boolean ignoreAnnotations) { + this.ignoreAnnotations = ignoreAnnotations; + } + + public void setIgnoreIdentifiers(boolean ignoreIdentifiers) { + this.ignoreIdentifiers = ignoreIdentifiers; + } + + public boolean isIgnoreIdentifiers() { + return ignoreIdentifiers; + } + + public void setIgnoreLiterals(boolean ignoreLiterals) { + this.ignoreLiterals = ignoreLiterals; + } + + public boolean isIgnoreLiterals() { + return ignoreLiterals; + } } diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java index c4c7191d..d52331b5 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java +++ b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java @@ -34,22 +34,21 @@ import net.sourceforge.pmd.PMDConfiguration; import net.sourceforge.pmd.PmdAnalysis; -import net.sourceforge.pmd.Report; -import net.sourceforge.pmd.RulePriority; -import net.sourceforge.pmd.RuleSetLoadException; -import net.sourceforge.pmd.RuleSetLoader; import net.sourceforge.pmd.benchmark.TextTimingReportRenderer; import net.sourceforge.pmd.benchmark.TimeTracker; import net.sourceforge.pmd.benchmark.TimingReport; import net.sourceforge.pmd.benchmark.TimingReportRenderer; import net.sourceforge.pmd.lang.Language; -import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.LanguageVersion; +import net.sourceforge.pmd.lang.rule.RulePriority; +import net.sourceforge.pmd.lang.rule.RuleSetLoadException; +import net.sourceforge.pmd.lang.rule.RuleSetLoader; import net.sourceforge.pmd.renderers.CSVRenderer; import net.sourceforge.pmd.renderers.HTMLRenderer; import net.sourceforge.pmd.renderers.Renderer; import net.sourceforge.pmd.renderers.TextRenderer; import net.sourceforge.pmd.renderers.XMLRenderer; +import net.sourceforge.pmd.reporting.Report; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.pmd.ExcludeViolationsFromFile; import org.apache.maven.reporting.MavenReportException; @@ -154,8 +153,9 @@ private PmdResult run() throws MavenReportException { PMDConfiguration configuration = new PMDConfiguration(); LanguageVersion languageVersion = null; - Language language = LanguageRegistry.findLanguageByTerseName( - request.getLanguage() != null ? request.getLanguage() : "java"); + Language language = configuration + .getLanguageRegistry() + .getLanguageById(request.getLanguage() != null ? request.getLanguage() : "java"); if (language == null) { throw new MavenReportException("Unsupported language: " + request.getLanguage()); } diff --git a/src/site/apt/examples/upgrading-PMD-at-runtime.apt.vm b/src/site/apt/examples/upgrading-PMD-at-runtime.apt.vm index 32d8325a..3e1f627b 100644 --- a/src/site/apt/examples/upgrading-PMD-at-runtime.apt.vm +++ b/src/site/apt/examples/upgrading-PMD-at-runtime.apt.vm @@ -88,6 +88,8 @@ Upgrading PMD at Runtime *--------------------------------------------------------------------------------*--------------------------------------------------* | <> | <> | *--------------------------------------------------------------------------------*--------------------------------------------------* +| {{{https://maven.apache.org/plugins-archives/maven-pmd-plugin-3.22.0/}3.22.0}} | {{{https://pmd.github.io/pmd-7.0.0/}7.0.0}} | +*--------------------------------------------------------------------------------*--------------------------------------------------* | {{{https://maven.apache.org/plugins-archives/maven-pmd-plugin-3.21.0/}3.21.0}} | {{{https://pmd.github.io/pmd-6.55.0/}6.55.0}} | *--------------------------------------------------------------------------------*--------------------------------------------------* | {{{https://maven.apache.org/plugins-archives/maven-pmd-plugin-3.20.0/}3.20.0}} | {{{https://pmd.github.io/pmd-6.53.0/}6.53.0}} | diff --git a/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java b/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java index 633ab327..b7657bf1 100644 --- a/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java +++ b/src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java @@ -62,7 +62,7 @@ public void testDefaultConfiguration() throws Exception { assertTrue(lowerCaseContains(str, "AppSample.java")); assertTrue(lowerCaseContains(str, "App.java")); assertTrue(lowerCaseContains(str, "public String dup( String str )")); - assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring( i, (i + 1));")); + assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring( i, i + 1);")); // the version should be logged String output = CapturingPrintStream.getOutput(); @@ -149,7 +149,7 @@ public void testWriteNonHtml() throws Exception { assertTrue(lowerCaseContains(str, "AppSample.java")); assertTrue(lowerCaseContains(str, "App.java")); assertTrue(lowerCaseContains(str, "public String dup( String str )")); - assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring( i, (i + 1));")); + assertTrue(lowerCaseContains(str, "tmp = tmp + str.substring( i, i + 1);")); } /** diff --git a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java index bd6dc24d..478e5ea9 100644 --- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java +++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java @@ -514,7 +514,7 @@ public void testPMDProcessingErrorWithDetailsSkipped() throws Exception { File generatedFile = new File(getBasedir(), "target/test/unit/parse-error/target/pmd.xml"); assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath())); String str = readFile(generatedFile); - assertTrue(str.contains("ParseException: Parse exception in file")); + assertTrue(str.contains("ParseException:")); // The parse exception must be in the XML report assertTrue(str.contains("at line 23, column 5: Encountered")); @@ -536,7 +536,7 @@ public void testPMDProcessingErrorWithDetailsNoReport() throws Exception { assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath())); String str = readFile(generatedFile); // The parse exception must be in the XML report - assertTrue(str.contains("ParseException: Parse exception in file")); + assertTrue(str.contains("ParseException:")); assertTrue(str.contains("at line 23, column 5: Encountered")); str = readFile(generatedReport); diff --git a/src/test/resources/unit/default-configuration/def/configuration/AppSample.java b/src/test/resources/unit/default-configuration/def/configuration/AppSample.java index bc9cac02..21ada1b6 100644 --- a/src/test/resources/unit/default-configuration/def/configuration/AppSample.java +++ b/src/test/resources/unit/default-configuration/def/configuration/AppSample.java @@ -57,7 +57,7 @@ public String dup( String str ) { if ( i != ( ( str.length() -1 ) ) ) { - tmp = tmp + str.substring( i, (i + 1)); + tmp = tmp + str.substring( i, i + 1); } else { diff --git a/src/test/resources/unit/default-configuration/rulesets/custom-rules.xml b/src/test/resources/unit/default-configuration/rulesets/custom-rules.xml index bb38c911..43b8a4a8 100644 --- a/src/test/resources/unit/default-configuration/rulesets/custom-rules.xml +++ b/src/test/resources/unit/default-configuration/rulesets/custom-rules.xml @@ -29,7 +29,7 @@ under the License. + class="net.sourceforge.pmd.lang.rule.xpath.XPathRule"> custom xpath rule test 1 From 19fdcf01935b8f8cc1e01a4974eb0316767bd71a Mon Sep 17 00:00:00 2001 From: KolesnikovMS Date: Sat, 23 Mar 2024 12:27:18 +0300 Subject: [PATCH 05/13] [MPMD-379] Removed showPmdLog --- pom.xml | 6 -- .../MPMD-244-logging/logging-disabled/pom.xml | 61 ------------------- .../src/main/java/BrokenFile.java | 26 -------- .../MPMD-244-logging/logging-enabled/pom.xml | 1 - src/it/MPMD-244-logging/pom.xml | 1 - src/it/MPMD-244-logging/verify.groovy | 7 +-- .../maven/plugins/pmd/exec/CpdExecutor.java | 2 - .../maven/plugins/pmd/exec/Executor.java | 41 ------------- .../maven/plugins/pmd/exec/PmdExecutor.java | 2 - src/site/apt/index.apt.vm | 5 ++ 10 files changed, 7 insertions(+), 145 deletions(-) delete mode 100644 src/it/MPMD-244-logging/logging-disabled/pom.xml delete mode 100644 src/it/MPMD-244-logging/logging-disabled/src/main/java/BrokenFile.java diff --git a/pom.xml b/pom.xml index 93d42df0..af0a2d90 100644 --- a/pom.xml +++ b/pom.xml @@ -187,12 +187,6 @@ under the License. slf4j-api ${slf4jVersion} - - - org.slf4j - jul-to-slf4j - ${slf4jVersion} - diff --git a/src/it/MPMD-244-logging/logging-disabled/pom.xml b/src/it/MPMD-244-logging/logging-disabled/pom.xml deleted file mode 100644 index 46f0e2b0..00000000 --- a/src/it/MPMD-244-logging/logging-disabled/pom.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - 4.0.0 - - - org.apache.maven.plugins.pmd.its - MPMD-244-logging - 1.0-SNAPSHOT - - MPMD-244-logging-disabled - - - UTF-8 - - - - - - - - - - @project.groupId@ - @project.artifactId@ - @project.version@ - - true - false - - - - test-compile - - check - - - - - - - diff --git a/src/it/MPMD-244-logging/logging-disabled/src/main/java/BrokenFile.java b/src/it/MPMD-244-logging/logging-disabled/src/main/java/BrokenFile.java deleted file mode 100644 index 1c5335a1..00000000 --- a/src/it/MPMD-244-logging/logging-disabled/src/main/java/BrokenFile.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -public class BrokenFile -{ - - // This file has a parse error, so PMD will fail to parse it - broken!! - -} diff --git a/src/it/MPMD-244-logging/logging-enabled/pom.xml b/src/it/MPMD-244-logging/logging-enabled/pom.xml index 355992c3..2decabeb 100644 --- a/src/it/MPMD-244-logging/logging-enabled/pom.xml +++ b/src/it/MPMD-244-logging/logging-enabled/pom.xml @@ -45,7 +45,6 @@ under the License. @project.version@ true - true diff --git a/src/it/MPMD-244-logging/pom.xml b/src/it/MPMD-244-logging/pom.xml index 6d9d3c16..e10d8d37 100644 --- a/src/it/MPMD-244-logging/pom.xml +++ b/src/it/MPMD-244-logging/pom.xml @@ -36,7 +36,6 @@ under the License. - logging-disabled logging-enabled diff --git a/src/it/MPMD-244-logging/verify.groovy b/src/it/MPMD-244-logging/verify.groovy index dfdc8d9e..1494cd4a 100644 --- a/src/it/MPMD-244-logging/verify.groovy +++ b/src/it/MPMD-244-logging/verify.groovy @@ -23,15 +23,12 @@ assert buildLog.text.contains( "PMD processing errors" ) assert buildLog.text.contains( "ParseException: Parse exception" ) assert buildLog.text.contains( "at line 24, column 5: Encountered" ) -String disabledPath = new File( basedir, 'logging-disabled/src/main/java/BrokenFile.java' ).getCanonicalPath() String enabledPath = new File( basedir, 'logging-enabled/src/main/java/BrokenFile.java' ).getCanonicalPath() -// logging disabled: the pmd exception is only output through the processing error reporting (since MPMD-246) -assert 1 == buildLog.text.count( "${disabledPath}: ParseException: Parse exception in" ) // logging enabled: the pmd exception is still output only once: through the processing error reporting (since MPMD-246) - PMD 7 doesn't log the processing error additionally assert 1 == buildLog.text.count( "${enabledPath}: ParseException: Parse exception in" ) // build.log contains the logging from the two PMD executions // only one execution has logging enabled, so we expect only one log output -// TODO assert 1 == buildLog.text.count( "[DEBUG] Rules loaded from" ) -// TODO logging is always enabled and can't be disabled, because PMD 7 switched to slf4j +assert 1 == buildLog.text.count( "[DEBUG] Rules loaded from" ) +// with --debug switch or -X the logging is always enabled and can't be disabled , because PMD 7 switched to slf4j diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java index cacf0bf7..6e00be91 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java +++ b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java @@ -144,8 +144,6 @@ public CpdExecutor(CpdRequest request) { } private CpdResult run() throws MavenReportException { - setupPmdLogging(request.isShowPmdLog(), request.getLogLevel()); - try { excludeDuplicationsFromFile.loadExcludeFromFailuresData(request.getExcludeFromFailureFile()); } catch (MojoExecutionException e) { diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/Executor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/Executor.java index d8f902c0..e128f7c1 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/exec/Executor.java +++ b/src/main/java/org/apache/maven/plugins/pmd/exec/Executor.java @@ -29,9 +29,6 @@ import java.net.URLClassLoader; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.SimpleFormatter; import org.apache.maven.cli.logging.Slf4jConfiguration; import org.apache.maven.cli.logging.Slf4jConfigurationFactory; @@ -39,48 +36,10 @@ import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.slf4j.bridge.SLF4JBridgeHandler; abstract class Executor { private static final Logger LOG = LoggerFactory.getLogger(Executor.class); - /** - * This holds a strong reference in case we configured the logger to - * redirect to slf4j. See {@link #showPmdLog}. Without a strong reference, - * the logger might be garbage collected and the redirect to slf4j is gone. - */ - private java.util.logging.Logger julLogger; - - protected void setupPmdLogging(boolean showPmdLog, String logLevel) { - if (!showPmdLog) { - return; - } - - java.util.logging.Logger logger = java.util.logging.Logger.getLogger("net.sourceforge.pmd"); - - boolean slf4jBridgeAlreadyAdded = false; - for (Handler handler : logger.getHandlers()) { - if (handler instanceof SLF4JBridgeHandler) { - slf4jBridgeAlreadyAdded = true; - break; - } - } - - if (slf4jBridgeAlreadyAdded) { - return; - } - - SLF4JBridgeHandler handler = new SLF4JBridgeHandler(); - SimpleFormatter formatter = new SimpleFormatter(); - handler.setFormatter(formatter); - logger.setUseParentHandlers(false); - logger.addHandler(handler); - handler.setLevel(Level.ALL); - logger.setLevel(Level.ALL); - julLogger = logger; - julLogger.fine("Configured jul-to-slf4j bridge for " + logger.getName()); - } - protected void setupLogLevel(String logLevel) { ILoggerFactory slf4jLoggerFactory = LoggerFactory.getILoggerFactory(); Slf4jConfiguration slf4jConfiguration = Slf4jConfigurationFactory.getConfiguration(slf4jLoggerFactory); diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java index d52331b5..e6dacdbe 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java +++ b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java @@ -149,8 +149,6 @@ public PmdExecutor(PmdRequest request) { } private PmdResult run() throws MavenReportException { - setupPmdLogging(request.isShowPmdLog(), request.getLogLevel()); - PMDConfiguration configuration = new PMDConfiguration(); LanguageVersion languageVersion = null; Language language = configuration diff --git a/src/site/apt/index.apt.vm b/src/site/apt/index.apt.vm index 97fede36..19f47fa6 100644 --- a/src/site/apt/index.apt.vm +++ b/src/site/apt/index.apt.vm @@ -89,6 +89,11 @@ ${project.name} * Upgrading Notes + <> Starting with Maven PMD Plugin 3.22.0, the plugin requires PDM version 7.0.0 or higher. + The PMD 7.0.0 switched to the SLF4J and since Maven 3.1.0+ the SLF4J is the default logging API, + because of that the <<>> makes no sense to exist. See + {{{}https://maven.apache.org/ref/3.9.6/maven-embedder/logging.html}}Maven Logging for more details. + <> Starting with PMD 6.0.0 and Maven PMD Plugin 3.9.0, the rules have been reorganized into categories, e.g. <<>>. So when upgrading to Maven PMD Plugin 3.9.0 you should review your plugin configuration and/or custom ruleset. From f9449bc575a4e516462d1288c26c13dd8cc9b1bb Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 5 Apr 2024 20:30:34 +0200 Subject: [PATCH 06/13] [MPMD-379] Remove deprecated CpdReport#createRenderer --- .../org/apache/maven/plugins/pmd/CpdReport.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java index 3b424de6..c813bc16 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java @@ -22,7 +22,6 @@ import java.io.UnsupportedEncodingException; import java.util.Locale; -import net.sourceforge.pmd.cpd.CPDReportRenderer; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -219,16 +218,4 @@ private void executeCpd() throws MavenReportException { public String getOutputName() { return "cpd"; } - - /** - * Create and return the correct renderer for the output type. - * - * @return the renderer based on the configured output - * @throws org.apache.maven.reporting.MavenReportException if no renderer found for the output type - * @deprecated Use {@link CpdExecutor#createRenderer(String, String)} instead. - */ - @Deprecated - public CPDReportRenderer createRenderer() throws MavenReportException { - return CpdExecutor.createRenderer(format, getOutputEncoding()); - } } From 00b9f13aec218bbb3113a8322ba9799efaca374c Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 5 Apr 2024 20:31:36 +0200 Subject: [PATCH 07/13] [MPMD-379] Simplify language selection in CpdExecutor --- .../maven/plugins/pmd/exec/CpdExecutor.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java index 6e00be91..e41d535e 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java +++ b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java @@ -39,9 +39,6 @@ import net.sourceforge.pmd.cpd.SimpleRenderer; import net.sourceforge.pmd.cpd.XMLRenderer; import net.sourceforge.pmd.lang.Language; -import net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule; -import net.sourceforge.pmd.lang.java.JavaLanguageModule; -import net.sourceforge.pmd.lang.jsp.JspLanguageModule; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.pmd.ExcludeDuplicationsFromFile; import org.apache.maven.reporting.MavenReportException; @@ -156,16 +153,13 @@ private CpdResult run() throws MavenReportException { cpdConfiguration.setIgnoreLiterals(request.isIgnoreLiterals()); cpdConfiguration.setIgnoreIdentifiers(request.isIgnoreIdentifiers()); - Language cpdLanguage; - if ("java".equals(request.getLanguage()) || null == request.getLanguage()) { - cpdLanguage = new JavaLanguageModule(); - } else if ("javascript".equals(request.getLanguage())) { - cpdLanguage = new EcmascriptLanguageModule(); - } else if ("jsp".equals(request.getLanguage())) { - cpdLanguage = new JspLanguageModule(); - } else { - cpdLanguage = cpdConfiguration.getLanguageRegistry().getLanguageById(request.getLanguage()); + String languageId = request.getLanguage(); + if ("javascript".equals(languageId)) { + languageId = "ecmascript"; + } else if (languageId == null) { + languageId = "java"; // default } + Language cpdLanguage = cpdConfiguration.getLanguageRegistry().getLanguageById(languageId); cpdConfiguration.setOnlyRecognizeLanguage(cpdLanguage); cpdConfiguration.setSourceEncoding(Charset.forName(request.getSourceEncoding())); @@ -191,7 +185,7 @@ private CpdResult run() throws MavenReportException { } }); } catch (IOException e) { - LOG.error(e.getMessage(), e); + LOG.error("Error while executing CPD: {}", e.getMessage(), e); } LOG.debug("CPD finished."); From ed944d58fc5fd84c188227d952708d25e1890477 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 5 Apr 2024 20:33:38 +0200 Subject: [PATCH 08/13] [MPMD-379] Deprecate parameter "showPmdLog" --- .../maven/plugins/pmd/AbstractPmdReport.java | 16 ++++++++++++++++ .../org/apache/maven/plugins/pmd/CpdReport.java | 3 --- .../org/apache/maven/plugins/pmd/PmdReport.java | 2 -- .../maven/plugins/pmd/exec/CpdRequest.java | 9 --------- .../maven/plugins/pmd/exec/PmdRequest.java | 9 --------- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java b/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java index 4fd2a54f..56eaf2b3 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java @@ -196,10 +196,20 @@ public abstract class AbstractPmdReport extends AbstractMavenReport { * the PMD logger is also configured for debug. * * @since 3.9.0 + * @deprecated With 3.22.0 and the upgrade to PMD 7, this parameter has no effect anymore. The PMD log + * is now always redirected into the maven log and this can't be disabled by this parameter anymore. + * In order to disable the logging, see Maven Logging. + * You'd need to start maven with MAVEN_OPTS=-Dorg.slf4j.simpleLogger.log.net.sourceforge.pmd=off mvn <goals>. */ @Parameter(defaultValue = "true", property = "pmd.showPmdLog") + @Deprecated(since = "3.22.0", forRemoval = true) protected boolean showPmdLog = true; + /** + * Used to avoid showing the deprecation warning for "showPmdLog" multiple times. + */ + private boolean warnedAboutShowPmdLog = false; + /** *

* Allow for configuration of the jvm used to run PMD via maven toolchains. @@ -454,6 +464,12 @@ protected boolean isXml() { */ @Override public boolean canGenerateReport() { + if (!showPmdLog && !warnedAboutShowPmdLog) { + getLog().warn("The parameter \"showPmdLog\" has been deprecated and will be removed." + + "Setting it to \"false\" has no effect."); + warnedAboutShowPmdLog = true; + } + if (aggregate && !project.isExecutionRoot()) { return false; } diff --git a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java index c813bc16..8c003641 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/CpdReport.java @@ -185,10 +185,7 @@ private void executeCpd() throws MavenReportException { request.setIgnoreLiterals(ignoreLiterals); request.setSourceEncoding(getInputEncoding()); request.addFiles(filesToProcess.keySet()); - - request.setShowPmdLog(showPmdLog); request.setLogLevel(determineCurrentRootLogLevel()); - request.setExcludeFromFailureFile(excludeFromFailureFile); request.setTargetDirectory(targetDirectory.getAbsolutePath()); request.setOutputEncoding(getOutputEncoding()); diff --git a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java index bd41e278..27db1f54 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java @@ -366,11 +366,9 @@ private void executePmd() throws MavenReportException { request.setBenchmarkOutputLocation(benchmark ? benchmarkOutputFilename : null); request.setAnalysisCacheLocation(analysisCache ? analysisCacheLocation : null); request.setExcludeFromFailureFile(excludeFromFailureFile); - request.setTargetDirectory(targetDirectory.getAbsolutePath()); request.setOutputEncoding(getOutputEncoding()); request.setFormat(format); - request.setShowPmdLog(showPmdLog); request.setSkipPmdError(skipPmdError); request.setIncludeXmlInSite(includeXmlInSite); request.setReportOutputDirectory(getReportOutputDirectory().getAbsolutePath()); diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdRequest.java b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdRequest.java index 96bc5557..7ecc7109 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdRequest.java +++ b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdRequest.java @@ -44,7 +44,6 @@ public class CpdRequest implements Serializable { private String sourceEncoding; private List files = new ArrayList<>(); - private boolean showPmdLog; private String logLevel; private String excludeFromFailureFile; @@ -105,10 +104,6 @@ public void setReportOutputDirectory(String reportOutputDirectory) { this.reportOutputDirectory = reportOutputDirectory; } - public void setShowPmdLog(boolean showPmdLog) { - this.showPmdLog = showPmdLog; - } - public void setLogLevel(String logLevel) { this.logLevel = logLevel; } @@ -161,10 +156,6 @@ public String getReportOutputDirectory() { return reportOutputDirectory; } - public boolean isShowPmdLog() { - return showPmdLog; - } - public String getLogLevel() { return logLevel; } diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdRequest.java b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdRequest.java index d1a80998..07036577 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/exec/PmdRequest.java +++ b/src/main/java/org/apache/maven/plugins/pmd/exec/PmdRequest.java @@ -47,7 +47,6 @@ public class PmdRequest implements Serializable { private String sourceEncoding; private List files = new ArrayList<>(); - private boolean showPmdLog; private String logLevel; private boolean skipPmdError; @@ -126,10 +125,6 @@ public void setFormat(String format) { this.format = format; } - public void setShowPmdLog(boolean showPmdLog) { - this.showPmdLog = showPmdLog; - } - public void setLogLevel(String logLevel) { this.logLevel = logLevel; } @@ -206,10 +201,6 @@ public String getFormat() { return format; } - public boolean isShowPmdLog() { - return showPmdLog; - } - public String getLogLevel() { return logLevel; } From 73b40104ccb4a26904f58200ef20f876d0772f4c Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 5 Apr 2024 20:34:23 +0200 Subject: [PATCH 09/13] [MPMD-379] Improve upgrading notes --- .../examples/upgrading-PMD-at-runtime.apt.vm | 10 +++--- src/site/apt/index.apt.vm | 33 ++++++++++++++----- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/site/apt/examples/upgrading-PMD-at-runtime.apt.vm b/src/site/apt/examples/upgrading-PMD-at-runtime.apt.vm index 3e1f627b..c6baab3b 100644 --- a/src/site/apt/examples/upgrading-PMD-at-runtime.apt.vm +++ b/src/site/apt/examples/upgrading-PMD-at-runtime.apt.vm @@ -85,11 +85,11 @@ Upgrading PMD at Runtime Here's a historical overview about the default PMD version used: -*--------------------------------------------------------------------------------*--------------------------------------------------* -| <> | <> | -*--------------------------------------------------------------------------------*--------------------------------------------------* -| {{{https://maven.apache.org/plugins-archives/maven-pmd-plugin-3.22.0/}3.22.0}} | {{{https://pmd.github.io/pmd-7.0.0/}7.0.0}} | -*--------------------------------------------------------------------------------*--------------------------------------------------* +*--------------------------------------------------------------------------------*-----------------------------------------------------* +| <> | <> | +*--------------------------------------------------------------------------------*-----------------------------------------------------* +| {{{https://maven.apache.org/plugins-archives/maven-pmd-plugin-3.22.0/}3.22.0}} | {{{https://docs.pmd-code.org/pmd-doc-7.0.0/}7.0.0}} | +*--------------------------------------------------------------------------------*-----------------------------------------------------* | {{{https://maven.apache.org/plugins-archives/maven-pmd-plugin-3.21.0/}3.21.0}} | {{{https://pmd.github.io/pmd-6.55.0/}6.55.0}} | *--------------------------------------------------------------------------------*--------------------------------------------------* | {{{https://maven.apache.org/plugins-archives/maven-pmd-plugin-3.20.0/}3.20.0}} | {{{https://pmd.github.io/pmd-6.53.0/}6.53.0}} | diff --git a/src/site/apt/index.apt.vm b/src/site/apt/index.apt.vm index 19f47fa6..ad0a3b31 100644 --- a/src/site/apt/index.apt.vm +++ b/src/site/apt/index.apt.vm @@ -89,15 +89,30 @@ ${project.name} * Upgrading Notes - <> Starting with Maven PMD Plugin 3.22.0, the plugin requires PDM version 7.0.0 or higher. - The PMD 7.0.0 switched to the SLF4J and since Maven 3.1.0+ the SLF4J is the default logging API, - because of that the <<>> makes no sense to exist. See - {{{}https://maven.apache.org/ref/3.9.6/maven-embedder/logging.html}}Maven Logging for more details. - - <> Starting with PMD 6.0.0 and Maven PMD Plugin 3.9.0, the rules have been reorganized - into categories, e.g. <<>>. So when upgrading to - Maven PMD Plugin 3.9.0 you should review your plugin configuration and/or custom ruleset. - See {{{./examples/usingRuleSets.html}Using Rule Sets}} for more information. +** 3.22.0 + + * Starting with Maven PMD Plugin 3.22.0, the plugin requires PMD version 7.0.0 or higher. + PMD 7.0.0 switched to SLF4J and since Maven 3.1.0+ SLF4J is the default logging API. + Logs from PMD are now always shown and cannot be disabled at runtime after maven has started. + The property <<>> makes no sense anymore and is deprecated now. See + {{{https://maven.apache.org/maven-logging.html}Maven Logging}} for how to configure logging. + For disabling PMD logs, you'd need to start maven with <<>>>. + + * The upgrade from PMD 6 to PMD 7.0.0 is a major version change. If you use the default ruleset + from Maven PMD Plugin, then everything should just work. But if you use a custom ruleset, you + most likely need to review your ruleset and migrate it to PMD 7. Rules might have been renamed or + replaced. See {{{https://docs.pmd-code.org/latest/pmd_release_notes_pmd7.html}Detailed Release Notes for PMD 7}} + and {{{https://docs.pmd-code.org/latest/pmd_userdocs_migrating_to_pmd7.html}Migration Guide for PMD 7}}. + + * If you currently override the dependency to PMD ({{{./examples/upgrading-PMD-at-runtime.html}Upgrading PMD at Runtime}}) + make sure to upgrade PMD as well to 7.0.0 or later when upgrading the Maven PMD Plugin. + +** 3.9.0 + + * Starting with PMD 6.0.0 and Maven PMD Plugin 3.9.0, the rules have been reorganized + into categories, e.g. <<>>. So when upgrading to + Maven PMD Plugin 3.9.0 you should review your plugin configuration and/or custom ruleset. + See {{{./examples/usingRuleSets.html}Using Rule Sets}} for more information. * Examples From 193c037a6d2284e9caa7f601323f110ce342bc12 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 5 Apr 2024 20:38:16 +0200 Subject: [PATCH 10/13] [MPMD-379] Add IT for Java 21 --- src/it/MPMD-379-JDK21/invoker.properties | 28 ++++++ src/it/MPMD-379-JDK21/pom.xml | 95 +++++++++++++++++++ .../src/main/java/com/mycompany/app/App.java | 25 +++++ .../src/main/java/com/mycompany/app/Foo.java | 30 ++++++ src/it/MPMD-379-JDK21/verify.groovy | 24 +++++ .../apache/maven/plugins/pmd/PmdReport.java | 9 +- 6 files changed, 208 insertions(+), 3 deletions(-) create mode 100644 src/it/MPMD-379-JDK21/invoker.properties create mode 100644 src/it/MPMD-379-JDK21/pom.xml create mode 100644 src/it/MPMD-379-JDK21/src/main/java/com/mycompany/app/App.java create mode 100644 src/it/MPMD-379-JDK21/src/main/java/com/mycompany/app/Foo.java create mode 100644 src/it/MPMD-379-JDK21/verify.groovy diff --git a/src/it/MPMD-379-JDK21/invoker.properties b/src/it/MPMD-379-JDK21/invoker.properties new file mode 100644 index 00000000..3289da6d --- /dev/null +++ b/src/it/MPMD-379-JDK21/invoker.properties @@ -0,0 +1,28 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.java.version = 1.8+ + +# available toolchains under linux: +# https://github.com/apache/infrastructure-p6/blob/production/modules/build_nodes/files/toolchains.xml + +# the jdk toolchain "21:openjdk" is selected in pom.xml +invoker.toolchain.jdk.version = 21 +invoker.toolchain.jdk.vendor = openjdk + +invoker.goals = clean verify +invoker.buildResult = failure diff --git a/src/it/MPMD-379-JDK21/pom.xml b/src/it/MPMD-379-JDK21/pom.xml new file mode 100644 index 00000000..89d97143 --- /dev/null +++ b/src/it/MPMD-379-JDK21/pom.xml @@ -0,0 +1,95 @@ + + + + + + 4.0.0 + org.apache.maven.plugins.pmd.it + MPMD-379-JDK21 + 1.0-SNAPSHOT + + + UTF-8 + 21 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + @compilerPluginVersion@ + + ${javaVersion} + ${javaVersion} + + + + + + + org.apache.maven.plugins + maven-pmd-plugin + @project.version@ + + false + false + false + true + 4 + true + ${javaVersion} + 100 + + + + default + verify + + check + + + + + + org.apache.maven.plugins + maven-toolchains-plugin + 3.1.0 + + + + toolchain + + + + + + + ${javaVersion} + openjdk + + + + + + + diff --git a/src/it/MPMD-379-JDK21/src/main/java/com/mycompany/app/App.java b/src/it/MPMD-379-JDK21/src/main/java/com/mycompany/app/App.java new file mode 100644 index 00000000..8e4972d3 --- /dev/null +++ b/src/it/MPMD-379-JDK21/src/main/java/com/mycompany/app/App.java @@ -0,0 +1,25 @@ +package com.mycompany.app; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public class App +{ + +} diff --git a/src/it/MPMD-379-JDK21/src/main/java/com/mycompany/app/Foo.java b/src/it/MPMD-379-JDK21/src/main/java/com/mycompany/app/Foo.java new file mode 100644 index 00000000..4823d574 --- /dev/null +++ b/src/it/MPMD-379-JDK21/src/main/java/com/mycompany/app/Foo.java @@ -0,0 +1,30 @@ +package com.mycompany.app; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.ArrayList; + +public class Foo +{ + public Foo( final ArrayList foo ) + { + } + +} diff --git a/src/it/MPMD-379-JDK21/verify.groovy b/src/it/MPMD-379-JDK21/verify.groovy new file mode 100644 index 00000000..2846ad3c --- /dev/null +++ b/src/it/MPMD-379-JDK21/verify.groovy @@ -0,0 +1,24 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.exists() +assert buildLog.text.contains( '[INFO] PMD Failure: com.mycompany.app.Foo:26 Rule:UnusedFormalParameter Priority:3' ) +assert !buildLog.text.contains( '[WARNING] PMD' ) diff --git a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java index 27db1f54..e781b861 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java @@ -63,16 +63,19 @@ @Mojo(name = "pmd", threadSafe = true, requiresDependencyResolution = ResolutionScope.TEST) public class PmdReport extends AbstractPmdReport { /** - * The target JDK to analyze based on. Should match the source used in the compiler plugin. Valid values - * with the default PMD version are + * The target JDK to analyze based on. Should match the source used in the compiler plugin. + * Valid values depend on the used PMD version. With the default PMD version valid values are * currently 1.3, 1.4, 1.5, 1.6, 1.7, * 1.8, 9, 10, 11, 12, 13, * 14, 15, 16, 17, 18, 19, - * and 20. + * 20, 21, and 22. * *

You can override the default PMD version by specifying PMD as a dependency, * see Upgrading PMD at Runtime.

* + *

To see the supported Java versions for each PMD version, see + * Java support (PMD).

+ * *

* Note: this parameter is only used if the language parameter is set to java. *

From 1528f30a8297a8a463fcb7fd75a8e648205b6afd Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 5 Apr 2024 21:27:25 +0200 Subject: [PATCH 11/13] [MPMD-379] Fix build for Java8 --- .../java/org/apache/maven/plugins/pmd/AbstractPmdReport.java | 2 +- src/site/apt/index.apt.vm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java b/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java index 56eaf2b3..87c40d85 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/AbstractPmdReport.java @@ -202,7 +202,7 @@ public abstract class AbstractPmdReport extends AbstractMavenReport { * You'd need to start maven with MAVEN_OPTS=-Dorg.slf4j.simpleLogger.log.net.sourceforge.pmd=off mvn <goals>. */ @Parameter(defaultValue = "true", property = "pmd.showPmdLog") - @Deprecated(since = "3.22.0", forRemoval = true) + @Deprecated // (since = "3.22.0", forRemoval = true) protected boolean showPmdLog = true; /** diff --git a/src/site/apt/index.apt.vm b/src/site/apt/index.apt.vm index ad0a3b31..1ec94a1c 100644 --- a/src/site/apt/index.apt.vm +++ b/src/site/apt/index.apt.vm @@ -96,7 +96,7 @@ ${project.name} Logs from PMD are now always shown and cannot be disabled at runtime after maven has started. The property <<>> makes no sense anymore and is deprecated now. See {{{https://maven.apache.org/maven-logging.html}Maven Logging}} for how to configure logging. - For disabling PMD logs, you'd need to start maven with <<>>>. + For disabling PMD logs, you'd need to start maven with << >>>. * The upgrade from PMD 6 to PMD 7.0.0 is a major version change. If you use the default ruleset from Maven PMD Plugin, then everything should just work. But if you use a custom ruleset, you From 4aaf0da7f8337aed08c417ff8a7eb0204a4b925e Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Mon, 8 Apr 2024 19:57:55 +0200 Subject: [PATCH 12/13] Fixups from review (#144) --- src/it/MPMD-379-JDK21/invoker.properties | 2 -- .../java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/it/MPMD-379-JDK21/invoker.properties b/src/it/MPMD-379-JDK21/invoker.properties index 3289da6d..03135633 100644 --- a/src/it/MPMD-379-JDK21/invoker.properties +++ b/src/it/MPMD-379-JDK21/invoker.properties @@ -15,8 +15,6 @@ # specific language governing permissions and limitations # under the License. -invoker.java.version = 1.8+ - # available toolchains under linux: # https://github.com/apache/infrastructure-p6/blob/production/modules/build_nodes/files/toolchains.xml diff --git a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java index e41d535e..3cdd5758 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java +++ b/src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java @@ -181,11 +181,11 @@ private CpdResult run() throws MavenReportException { writeFormattedReport(report); } } catch (MavenReportException e) { - LOG.error(e.getMessage(), e); + LOG.error("Error while writing CPD report", e); } }); } catch (IOException e) { - LOG.error("Error while executing CPD: {}", e.getMessage(), e); + LOG.error("Error while executing CPD", e); } LOG.debug("CPD finished."); From f884af3f354aae619a6a97a83be6bf46067a53cf Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Tue, 9 Apr 2024 19:23:09 +0200 Subject: [PATCH 13/13] Fixups from review (#144) --- src/it/MPMD-379-JDK21/invoker.properties | 3 +-- src/it/MPMD-379-JDK21/pom.xml | 4 +--- .../org/apache/maven/plugins/pmd/PmdReport.java | 15 ++++++--------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/it/MPMD-379-JDK21/invoker.properties b/src/it/MPMD-379-JDK21/invoker.properties index 03135633..451e64ea 100644 --- a/src/it/MPMD-379-JDK21/invoker.properties +++ b/src/it/MPMD-379-JDK21/invoker.properties @@ -18,9 +18,8 @@ # available toolchains under linux: # https://github.com/apache/infrastructure-p6/blob/production/modules/build_nodes/files/toolchains.xml -# the jdk toolchain "21:openjdk" is selected in pom.xml +# the jdk toolchain "21" is selected in pom.xml invoker.toolchain.jdk.version = 21 -invoker.toolchain.jdk.vendor = openjdk invoker.goals = clean verify invoker.buildResult = failure diff --git a/src/it/MPMD-379-JDK21/pom.xml b/src/it/MPMD-379-JDK21/pom.xml index 89d97143..d1580654 100644 --- a/src/it/MPMD-379-JDK21/pom.xml +++ b/src/it/MPMD-379-JDK21/pom.xml @@ -39,8 +39,7 @@ under the License. maven-compiler-plugin @compilerPluginVersion@ - ${javaVersion} - ${javaVersion} + ${javaVersion} @@ -85,7 +84,6 @@ under the License. ${javaVersion} - openjdk diff --git a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java index e781b861..5b3a14c8 100644 --- a/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java +++ b/src/main/java/org/apache/maven/plugins/pmd/PmdReport.java @@ -64,18 +64,15 @@ public class PmdReport extends AbstractPmdReport { /** * The target JDK to analyze based on. Should match the source used in the compiler plugin. - * Valid values depend on the used PMD version. With the default PMD version valid values are - * currently 1.3, 1.4, 1.5, 1.6, 1.7, - * 1.8, 9, 10, 11, 12, 13, - * 14, 15, 16, 17, 18, 19, - * 20, 21, and 22. + * Valid values depend on the used PMD version. Most common values are + * 8, 11, 17, and 21. * - *

You can override the default PMD version by specifying PMD as a dependency, - * see Upgrading PMD at Runtime.

- * - *

To see the supported Java versions for each PMD version, see + *

The full list of supported Java versions for each PMD version is available at * Java support (PMD).

* + *

You can override the default PMD version by specifying PMD as a dependency, + * see Upgrading PMD at Runtime.

+ * *

* Note: this parameter is only used if the language parameter is set to java. *