Skip to content

Commit

Permalink
Improve layout of Markdown.
Browse files Browse the repository at this point in the history
- Simplify warnings message.
- Use the configured icon if set.
  • Loading branch information
uhafner committed May 8, 2024
1 parent ede7795 commit e15e89c
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 40 deletions.
6 changes: 3 additions & 3 deletions src/main/java/edu/hm/hafner/grading/AnalysisMarkdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ private int sum(final AnalysisScore score, final Function<AnalysisScore, Integer

protected String extractSeverities(final AnalysisScore score) {
if (score.getReport().isEmpty()) {
return "No warnings found";
return "No warnings";
}
else {
return String.format("%d warning%s found (%d error%s, %d high, %d normal, %d low)",
return String.format("%d warning%s (%d error%s, %d high, %d normal, %d low)",
score.getTotalSize(), AnalysisScore.plural(score.getTotalSize()),
score.getErrorSize(), AnalysisScore.plural(score.getErrorSize()),
score.getHighSeveritySize(),
Expand Down Expand Up @@ -121,7 +121,7 @@ private String getIconAndName(final AnalysisScore analysisScore) {
private String extractParserIcon(final AnalysisScore analysisScore) {
var descriptor = REGISTRY.get(analysisScore.getId());
if (descriptor.getIconUrl().isEmpty()) {
return ":exclamation:";
return getIcon(analysisScore);
}
else {
return "<img src=\"%s\" alt=\"%s\" height=\"%d\" width=\"%d\">"
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/grading/AnalysisScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public int getTotalSize() {
@Override
protected String createSummary() {
if (getReport().isEmpty()) {
return "No warnings found";
return "No warnings";
}
else {
return String.format("%d warning%s found (%d error%s, %d high, %d normal, %d low)",
return String.format("%d warning%s (%d error%s, %d high, %d normal, %d low)",
getTotalSize(), plural(getTotalSize()),
getErrorSize(), plural(getErrorSize()),
getHighSeveritySize(), getNormalSeveritySize(), getLowSeveritySize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.nio.file.Path;

import org.apache.commons.lang3.StringUtils;

import edu.hm.hafner.analysis.FileReaderFactory;
import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.registry.ParserDescriptor;
Expand All @@ -23,17 +25,22 @@ public final class FileSystemAnalysisReportFactory implements AnalysisReportFact
public Report create(final ToolConfiguration tool, final FilteredLog log) {
ParserDescriptor parser = new ParserRegistry().get(tool.getId());

var total = new Report(tool.getId(), tool.getDisplayName());
var displayName = getDisplayName(tool, parser.getName());
var total = new Report(tool.getId(), displayName);

var analysisParser = parser.createParser();
for (Path file : REPORT_FINDER.find(tool, log)) {
for (Path file : REPORT_FINDER.find(log, displayName, tool.getPattern())) {
Report report = analysisParser.parseFile(new FileReaderFactory(file));
report.setOrigin(tool.getId(), tool.getDisplayName());
report.setOrigin(tool.getId(), displayName);
log.logInfo("- %s: %d warnings", PATH_UTIL.getRelativePath(file), report.size());
total.addAll(report);
}

log.logInfo("-> %s Total: %d warnings", tool.getDisplayName(), total.size());
log.logInfo("-> %s Total: %d warnings", displayName, total.size());
return total;
}

private String getDisplayName(final ToolConfiguration tool, final String defaultName) {
return StringUtils.defaultIfBlank(tool.getName(), defaultName);
}
}
16 changes: 11 additions & 5 deletions src/main/java/edu/hm/hafner/grading/ReportFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,20 @@ class ReportFinder {
*
* @return the paths
*/
public List<Path> find(final ToolConfiguration tool, final FilteredLog log) {
log.logInfo("Searching for %s results matching file name pattern %s",
tool.getDisplayName(), tool.getPattern());
List<Path> files = find("glob:" + tool.getPattern(), ".", log);
List<Path> find(final ToolConfiguration tool, final FilteredLog log) {
var displayName = tool.getDisplayName();
var pattern = tool.getPattern();

return find(log, displayName, pattern);
}

List<Path> find(final FilteredLog log, final String displayName, final String pattern) {
log.logInfo("Searching for %s results matching file name pattern %s", displayName, pattern);
List<Path> files = find("glob:" + pattern, ".", log);

if (files.isEmpty()) {
log.logError("No matching report files found when using pattern '%s'! "
+ "Configuration error for '%s'?", tool.getPattern(), tool.getDisplayName());
+ "Configuration error for '%s'?", pattern, displayName);
}

Collections.sort(files);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/hm/hafner/grading/TestMarkdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ protected String createSummary(final TestScore score) {
- :microscope: &nbsp; Mutation Coverage: 93% mutations killed
- ☑️ 99% Test strength
---
- :warning: &nbsp; Style:: No warnings found
- :bug: &nbsp; Bugs: No warnings found
- :warning: &nbsp; Style:: No warnings
- :bug: &nbsp; Bugs: No warnings
<br/>
Created by [Quality Monitor](https://github.com/uhafner/quality-monitor/releases/tag/v1.6.0) v1.6.0 (#85eae94). More details are shown in the [GitHub Checks Result](https://github.com/jenkinsci/coverage-model/runs/23474192891).
Expand Down
20 changes: 10 additions & 10 deletions src/test/java/edu/hm/hafner/grading/AnalysisMarkdownTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void shouldShowMaximumScore() {
.contains(IMPACT_CONFIGURATION);
assertThat(analysisMarkdown.createSummary(score))
.contains("CheckStyle - 100 of 100")
.contains("No warnings found");
.contains("No warnings");
}

@Test
Expand Down Expand Up @@ -87,7 +87,7 @@ void shouldShowScoreWithOneResult() {
var analysisMarkdown = new AnalysisMarkdown();

assertThat(analysisMarkdown.createSummary(score)).contains(
"CS - 70 of 100: 10 warnings found (1 error, 2 high, 3 normal, 4 low)");
"CS - 70 of 100: 10 warnings (1 error, 2 high, 3 normal, 4 low)");
assertThat(analysisMarkdown.createDetails(score))
.contains("TopLevel Warnings - 70 of 100")
.contains("|CS|1|1|2|3|4|10|-30")
Expand Down Expand Up @@ -126,8 +126,8 @@ void shouldShowScoreWithTwoSubResults() {

assertThat(analysisMarkdown.createSummary(score))
.contains(
"CheckStyle - 70 of 100: 10 warnings found (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs - 80 of 100: 10 warnings found (4 errors, 3 high, 2 normal, 1 low)");
"CheckStyle - 70 of 100: 10 warnings (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs - 80 of 100: 10 warnings (4 errors, 3 high, 2 normal, 1 low)");
assertThat(analysisMarkdown.createDetails(score))
.contains("CheckStyle - 50 of 100",
"|CheckStyle|1|1|2|3|4|10|-30",
Expand Down Expand Up @@ -162,8 +162,8 @@ void shouldShowNoImpactsWithTwoSubResults() {
var analysisMarkdown = new AnalysisMarkdown();

assertThat(analysisMarkdown.createSummary(score))
.contains("CheckStyle: 10 warnings found (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs: 10 warnings found (4 errors, 3 high, 2 normal, 1 low)");
.contains("CheckStyle: 10 warnings (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs: 10 warnings (4 errors, 3 high, 2 normal, 1 low)");
assertThat(analysisMarkdown.createDetails(score))
.contains("CheckStyle",
"|CheckStyle|1|1|2|3|4|10",
Expand Down Expand Up @@ -217,10 +217,10 @@ void shouldShowScoreWithTwoResults() {
":moneybag:|:heavy_minus_sign:|*1*|*2*|*3*|*4*|:heavy_minus_sign:|:heavy_minus_sign:",
":moneybag:|:heavy_minus_sign:|*-11*|*-12*|*-13*|*-14*|:heavy_minus_sign:|:heavy_minus_sign:");
assertThat(analysisMarkdown.createSummary(score))
.contains("CheckStyle 1 - 30 of 100: 10 warnings found (1 error, 2 high, 3 normal, 4 low)",
"CheckStyle 2 - 30 of 100: 10 warnings found (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs 1 - 0 of 100: 10 warnings found (4 errors, 3 high, 2 normal, 1 low)",
"SpotBugs 2 - 0 of 100: 10 warnings found (4 errors, 3 high, 2 normal, 1 low)")
.contains("CheckStyle 1 - 30 of 100: 10 warnings (1 error, 2 high, 3 normal, 4 low)",
"CheckStyle 2 - 30 of 100: 10 warnings (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs 1 - 0 of 100: 10 warnings (4 errors, 3 high, 2 normal, 1 low)",
"SpotBugs 2 - 0 of 100: 10 warnings (4 errors, 3 high, 2 normal, 1 low)")
.doesNotContain("Total");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ class FileSystemAnalysisReportFactoryTest {
"tools": [
{
"id": "checkstyle",
"name": "CheckStyle",
"pattern": "**/src/**/checkstyle*.xml"
},
{
"id": "pmd",
"name": "PMD",
"pattern": "**/src/**/pmd*.xml"
}
],
Expand All @@ -35,11 +33,15 @@ class FileSystemAnalysisReportFactoryTest {
{
"name": "Bugs",
"id": "bugs",
"icon": "bug",
"tools": [
{
"id": "spotbugs",
"name": "SpotBugs",
"pattern": "**/src/**/spotbugs*.xml"
},
{
"id": "error-prone",
"pattern": "**/src/**/error-prone.log"
}
],
"errorImpact": -11,
Expand All @@ -51,7 +53,7 @@ class FileSystemAnalysisReportFactoryTest {
]
}
""";
private static final int EXPECTED_ISSUES = 6 + 4 + 2;
private static final int EXPECTED_ISSUES = 6 + 4 + 2 + 1;

@Test
void shouldCreateAggregation() {
Expand All @@ -66,7 +68,8 @@ void shouldCreateAggregation() {
"CopyToClipboard.java",
"ChangeSelectionAction.java",
"SelectSourceDialog.java",
"IssuesTest.java");
"IssuesTest.java",
"RobocopyParser.java");
assertThat(score.getIssues().stream()
.filter(issue -> issue.getBaseName().equals("CsharpNamespaceDetector.java")))
.map(Issue::getOriginName)
Expand All @@ -82,6 +85,21 @@ void shouldCreateAggregation() {
"Searching for SpotBugs results matching file name pattern **/src/**/spotbugs*.xml",
"- src/test/resources/edu/hm/hafner/grading/spotbugsXml.xml: 2 warnings",
"-> SpotBugs Total: 2 warnings",
"=> Bugs Score: 72 of 100");
"Searching for Error Prone results matching file name pattern **/src/**/error-prone.log",
"- src/test/resources/edu/hm/hafner/grading/error-prone.log: 1 warnings",
"-> Error Prone Total: 1 warnings",
"=> Bugs Score: 59 of 100");

var gradingReport = new GradingReport();
assertThat(gradingReport.getMarkdownSummary(score)).contains(
"Autograding score - 77 of 200 (38%)",
"<img src=\"https://raw.githubusercontent.com/checkstyle/checkstyle/master/src/site/resources/images/checkstyle_logo_small_64.png\"",
"CheckStyle - 6 of 100: 6 warnings (6 errors, 0 high, 0 normal, 0 low)",
"<img src=\"https://raw.githubusercontent.com/pmd/pmd/master/docs/images/logo/PMD_small.svg\"",
"PMD - 12 of 100: 4 warnings (0 error, 1 high, 2 normal, 1 low)",
"<img src=\"https://raw.githubusercontent.com/spotbugs/spotbugs.github.io/master/images/logos/spotbugs_icon_only_zoom_256px.png\"",
"SpotBugs - 72 of 100: 2 warnings (0 error, 0 high, 0 normal, 2 low)",
":bug:",
"Error Prone - 87 of 100: 1 warning (0 error, 0 high, 1 normal, 0 low)");
}
}
16 changes: 8 additions & 8 deletions src/test/java/edu/hm/hafner/grading/GradingReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ void shouldCreateAllGradingResults() {
"Line Coverage - 60 of 100", "80% (20 missed lines)",
"Branch Coverage - 20 of 100", "60% (40 missed branches)",
"Mutation Coverage - 20 of 100: 60% (40 survived mutations)",
"Checkstyle - 30 of 100: 10 warnings found (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs - 0 of 100: 10 warnings found (4 errors, 3 high, 2 normal, 1 low)");
"Checkstyle - 30 of 100: 10 warnings (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs - 0 of 100: 10 warnings (4 errors, 3 high, 2 normal, 1 low)");
assertThat(results.getTextSummary(score)).isEqualTo(
"Autograding score - 167 of 500 (33%)");
assertThat(results.getMarkdownDetails(score)).contains(
Expand All @@ -142,8 +142,8 @@ void shouldCreateAllQualityResults() {
"Line Coverage: 80% (20 missed lines)",
"Branch Coverage: 60% (40 missed branches)",
"Mutation Coverage: 60% (40 survived mutations)",
"Checkstyle: 10 warnings found (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs: 10 warnings found (4 errors, 3 high, 2 normal, 1 low)");
"Checkstyle: 10 warnings (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs: 10 warnings (4 errors, 3 high, 2 normal, 1 low)");
assertThat(results.getTextSummary(score)).isEqualTo(
"Autograding score");
assertThat(results.getMarkdownDetails(score)).contains(
Expand Down Expand Up @@ -198,8 +198,8 @@ void shouldSkipScores() {
aggregation.gradeAnalysis((tool, log) -> AnalysisMarkdownTest.createTwoReports(tool));
assertThat(logger.getInfoMessages()).contains(
"Processing 2 static analysis configuration(s)",
"=> Style: 10 warnings found (1 error, 2 high, 3 normal, 4 low)",
"=> Bugs: 10 warnings found (4 errors, 3 high, 2 normal, 1 low)");
"=> Style: 10 warnings (1 error, 2 high, 3 normal, 4 low)",
"=> Bugs: 10 warnings (4 errors, 3 high, 2 normal, 1 low)");

aggregation.gradeTests((tool, log) -> TestMarkdownTest.createTwoReports(tool));
assertThat(logger.getInfoMessages()).contains(
Expand Down Expand Up @@ -229,8 +229,8 @@ void shouldSkipScores() {
"Line Coverage: 80% (20 missed lines)",
"Branch Coverage: 60% (40 missed branches)",
"Mutation Coverage: 60% (40 survived mutations)",
"Checkstyle: 10 warnings found (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs: 10 warnings found (4 errors, 3 high, 2 normal, 1 low)");
"Checkstyle: 10 warnings (1 error, 2 high, 3 normal, 4 low)",
"SpotBugs: 10 warnings (4 errors, 3 high, 2 normal, 1 low)");
assertThat(results.getTextSummary(aggregation)).isEqualTo(
"Autograding score");
assertThat(results.getTextSummary(aggregation, "Quality Summary")).isEqualTo(
Expand Down
7 changes: 7 additions & 0 deletions src/test/resources/edu/hm/hafner/grading/error-prone.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[INFO] Compiling 143 source files to /Users/hafner/Development/jenkins/workspace/Model - Freestyle - New/target/classes
[WARNING] /Users/hafner/Development/jenkins/workspace/Model - Freestyle - New/src/main/java/edu/hm/hafner/analysis/parser/RobocopyParser.java:[29,45] [StringSplitter] String.split(String) has surprising behavior
(see http://errorprone.info/bugpattern/StringSplitter)
Did you mean 'String file = matcher.group(4).split("\\s{11}", -1)[0];'?
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ analysis-model ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.

0 comments on commit e15e89c

Please sign in to comment.