Skip to content

Commit

Permalink
[MPMD-410] Number agreement
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo committed Dec 29, 2024
1 parent 3bce10b commit 3ef7a53
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/it/MPMD-244-logging/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()
assert buildLog.text.contains( "PMD processing errors" )
assert buildLog.text.contains( "PMD processing error" )
assert buildLog.text.contains( "ParseException: Parse exception" )
assert buildLog.text.contains( "at line 24, column 5: Encountered" )

Expand Down
16 changes: 11 additions & 5 deletions src/main/java/org/apache/maven/plugins/pmd/exec/PmdExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,22 @@ private PmdResult run() throws MavenReportException {
if (!request.isSkipPmdError()) {
LOG.error("PMD processing errors:");
LOG.error(getErrorsAsString(errors, request.isDebugEnabled()));
throw new MavenReportException("Found " + errors.size() + " PMD processing errors");
String msg = errors.size() > 1
? "Found " + errors.size() + " PMD processing errors"
: "Found 1 PMD processing error";
throw new MavenReportException(msg);
}
LOG.warn("There are {} PMD processing errors:", errors.size());
String message = errors.size() > 1
? "There are " + errors.size() + " PMD processing errors:"
: "There is 1 PMD processing error:";
LOG.warn(message);
LOG.warn(getErrorsAsString(errors, request.isDebugEnabled()));
}

report = removeExcludedViolations(report);
// always write XML report, as this might be needed by the check mojo
// we need to output it even if the file list is empty or we have no violations
// so the "check" goals can check for violations
// Always write the XML report, as this might be needed by the check mojo.
// We need to output it even if the file list is empty or there are no violations
// so the "check" goals can check for violations.
try {
writeXmlReport(report);
} catch (IOException e) {
Expand Down
32 changes: 17 additions & 15 deletions src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public void testPMDProcessingError() throws Exception {
generateReport(getGoal(), "processing-error/pmd-processing-error-plugin-config.xml");
fail("Expected exception");
} catch (MojoExecutionException e) {
assertTrue(e.getCause().getMessage().endsWith("Found 1 PMD processing errors"));
assertTrue(e.getCause().getMessage().endsWith("Found 1 PMD processing error"));
}
}

Expand All @@ -510,19 +510,20 @@ public void testPMDProcessingErrorWithDetailsSkipped() throws Exception {
assertTrue(FileUtils.fileExists(generatedReport.getAbsolutePath()));

String output = CapturingPrintStream.getOutput();
assertTrue(output.contains("There are 1 PMD processing errors:"));
assertTrue(output, output.contains("There is 1 PMD processing error:"));

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:"));

// The parse exception must be in the XML report
assertTrue(str.contains("at line 23, column 5: Encountered"));
String xml = readFile(generatedFile);
assertTrue(xml.contains("ParseException:"));
assertTrue(xml.contains("at line 23, column 5: Encountered"));

str = readFile(generatedReport);
// The parse exception must also be in the HTML report
assertTrue(str.contains("ParseException:"));
assertTrue(str.contains("at line 23, column 5: Encountered"));
String html = readFile(generatedReport);
assertTrue(html.contains("ParseException:"));
assertTrue(html.contains("at line 23, column 5: Encountered"));
}

public void testPMDProcessingErrorWithDetailsNoReport() throws Exception {
Expand All @@ -531,19 +532,20 @@ public void testPMDProcessingErrorWithDetailsNoReport() throws Exception {
assertTrue(FileUtils.fileExists(generatedReport.getAbsolutePath()));

String output = CapturingPrintStream.getOutput();
assertTrue(output.contains("There are 1 PMD processing errors:"));
assertTrue(output, output.contains("There is 1 PMD processing error:"));

File generatedFile = new File(getBasedir(), "target/test/unit/parse-error/target/pmd.xml");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
String str = readFile(generatedFile);

// The parse exception must be in the XML report
assertTrue(str.contains("ParseException:"));
assertTrue(str.contains("at line 23, column 5: Encountered"));
String xml = readFile(generatedFile);
assertTrue(xml.contains("ParseException:"));
assertTrue(xml.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:"));
assertFalse(str.contains("at line 23, column 5: Encountered"));
String html = readFile(generatedReport);
assertFalse(html.contains("ParseException:"));
assertFalse(html.contains("at line 23, column 5: Encountered"));
}

public void testPMDExcludeRootsShouldExcludeSubdirectories() throws Exception {
Expand Down

0 comments on commit 3ef7a53

Please sign in to comment.