Skip to content

Commit 4ffa208

Browse files
committed
chore: sonar issues
1 parent 8bc0dc6 commit 4ffa208

File tree

2 files changed

+98
-88
lines changed

2 files changed

+98
-88
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@ A simple plugin to check the presence of JUnit5 test by tags.
88
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=fugerit-org_junit5-tag-check-maven-plugin&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=fugerit-org_junit5-tag-check-maven-plugin)
99
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=fugerit-org_junit5-tag-check-maven-plugin&metric=coverage)](https://sonarcloud.io/summary/new_code?id=fugerit-org_junit5-tag-check-maven-plugin)
1010

11-
Here a sample configuration
11+
## Configuration reference
12+
13+
| parameter | type | required | notes |
14+
|--------------------------|---------|----------|------------------------------------------------------|
15+
| format | string | true | only 'html' accepted |
16+
| outputFile | string | true | path where should be produced the report |
17+
| requiredTags.requiredTag | string | true | tag to be checked |
18+
| failOnMissingTag | boolean | true | if set to 'true' the build will fail on missing tags |
19+
20+
Here is a sample configuration
1221

1322
```
1423
<plugin>

src/main/java/org/fugerit/java/junit5/tag/check/ExecutedTestTagReporterMojo.java

Lines changed: 88 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.fugerit.java.junit5.tag.check;
22

3+
import org.apache.maven.artifact.DependencyResolutionRequiredException;
34
import org.apache.maven.plugin.AbstractMojo;
45
import org.apache.maven.plugin.MojoExecutionException;
56
import org.apache.maven.plugins.annotations.*;
@@ -90,7 +91,7 @@ public void execute() throws MojoExecutionException {
9091
}
9192
}
9293

93-
private URLClassLoader createTestClassLoader() throws Exception {
94+
private URLClassLoader createTestClassLoader() throws DependencyResolutionRequiredException {
9495
List<String> classpathElements = project.getTestClasspathElements();
9596
URL[] urls = classpathElements.stream()
9697
.map(element -> {
@@ -252,9 +253,9 @@ private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
252253
String line = repeatString("-", 80);
253254

254255
try (FileWriter writer = new FileWriter(outputFile)) {
255-
writer.write(separator + "\n");
256-
writer.write("EXECUTED TEST TAG REPORT\n");
257-
writer.write(separator + "\n\n");
256+
writer.write(separator + "%n");
257+
writer.write("EXECUTED TEST TAG REPORT%n");
258+
writer.write(separator + "%n%n");
258259

259260
int totalTests = testTagMap.size();
260261

@@ -268,16 +269,16 @@ private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
268269
int skippedTests = (int) testTagMap.keySet().stream()
269270
.filter(ExecutedTest::isSkipped).count();
270271

271-
writer.write("EXECUTION SUMMARY:\n");
272-
writer.write(line + "\n");
273-
writer.write(String.format(" Total Tests: %d\n", totalTests));
274-
writer.write(String.format(" Passed: %d\n", passedTests));
275-
writer.write(String.format(" Failed: %d\n", failedTests));
276-
writer.write(String.format(" Errors: %d\n", errorTests));
272+
writer.write("EXECUTION SUMMARY:%n");
273+
writer.write(line + "%n");
274+
writer.write(String.format(" Total Tests: %d%n", totalTests));
275+
writer.write(String.format(" Passed: %d%n", passedTests));
276+
writer.write(String.format(" Failed: %d%n", failedTests));
277+
writer.write(String.format(" Errors: %d%n", errorTests));
277278
if (includeSkipped) {
278-
writer.write(String.format(" Skipped: %d\n", skippedTests));
279+
writer.write(String.format(" Skipped: %d%n", skippedTests));
279280
}
280-
writer.write("\n");
281+
writer.write("%n");
281282

282283
// Summary by tag (Java 8 compatible map operations: computeIfAbsent is fine)
283284
Map<String, List<ExecutedTest>> tagToTests = new HashMap<>();
@@ -296,16 +297,16 @@ private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
296297
}
297298
}
298299

299-
writer.write("SUMMARY BY TAG:\n");
300-
writer.write(line + "\n");
301-
writer.write(String.format("%-20s | %5s | %5s | %5s | %5s\n",
300+
writer.write("SUMMARY BY TAG:%n");
301+
writer.write(line + "%n");
302+
writer.write(String.format("%-20s | %5s | %5s | %5s | %5s%n",
302303
"Tag", "Total", "Pass", "Fail", "Error"));
303-
writer.write(line + "\n");
304+
writer.write(line + "%n");
304305

305306
for (Map.Entry<String, TestStats> entry : tagStats.entrySet()) {
306307
TestStats stats = entry.getValue();
307308
int passed = stats.total - stats.failed - stats.errors - stats.skipped;
308-
writer.write(String.format("%-20s | %5d | %5d | %5d | %5d\n",
309+
writer.write(String.format("%-20s | %5d | %5d | %5d | %5d%n",
309310
entry.getKey(), stats.total, passed, stats.failed, stats.errors));
310311
}
311312

@@ -315,32 +316,32 @@ private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
315316
.count();
316317

317318
if (testsWithoutTags > 0) {
318-
writer.write(String.format("%-20s | %5d | %5s | %5s | %5s\n",
319+
writer.write(String.format("%-20s | %5d | %5s | %5s | %5s%n",
319320
"<NO TAG>", testsWithoutTags, "?", "?", "?"));
320321
}
321322

322-
writer.write("\n" + separator + "\n");
323-
writer.write("EXECUTED TESTS BY TAG:\n");
324-
writer.write(separator + "\n\n");
323+
writer.write("%n" + separator + "%n");
324+
writer.write("EXECUTED TESTS BY TAG:%n");
325+
writer.write(separator + "%n%n");
325326

326327
for (Map.Entry<String, List<ExecutedTest>> entry : tagToTests.entrySet()) {
327-
writer.write(String.format("Tag: %s (%d tests)\n",
328+
writer.write(String.format("Tag: %s (%d tests)%n",
328329
entry.getKey(), entry.getValue().size()));
329-
writer.write(line + "\n");
330+
writer.write(line + "%n");
330331
for (ExecutedTest test : entry.getValue()) {
331332
String status = getStatusIcon(test);
332-
writer.write(String.format(" %s %s#%s (%.3fs)\n",
333+
writer.write(String.format(" %s %s#%s (%.3fs)%n",
333334
status,
334335
test.getClassName(),
335336
test.getMethodName(),
336337
Double.parseDouble(test.getTime())));
337338
}
338-
writer.write("\n");
339+
writer.write("%n");
339340
}
340341

341-
writer.write("\n" + separator + "\n");
342-
writer.write("ALL EXECUTED TESTS WITH TAGS:\n");
343-
writer.write(separator + "\n\n");
342+
writer.write("%n" + separator + "%n");
343+
writer.write("ALL EXECUTED TESTS WITH TAGS:%n");
344+
writer.write(separator + "%n%n");
344345

345346
for (Map.Entry<ExecutedTest, Set<String>> entry : testTagMap.entrySet()) {
346347
ExecutedTest test = entry.getKey();
@@ -351,17 +352,17 @@ private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
351352
String tags = entry.getValue().isEmpty() ?
352353
"<NO TAGS>" : "[" + entry.getValue().stream().collect(Collectors.joining(", ")) + "]";
353354

354-
writer.write(String.format("%s %-50s : %s\n",
355+
writer.write(String.format("%s %-50s : %s%n",
355356
status,
356357
test.getClassName() + "#" + test.getMethodName(),
357358
tags));
358359
}
359360

360361
if (testsWithoutTags > 0) {
361-
writer.write("\n" + separator + "\n");
362+
writer.write("%n" + separator + "%n");
362363
writer.write("⚠️ WARNING: " + testsWithoutTags +
363-
" executed tests without tags\n");
364-
writer.write(separator + "\n");
364+
" executed tests without tags%n");
365+
writer.write(separator + "%n");
365366
}
366367
}
367368
}
@@ -380,40 +381,40 @@ private String repeatString(String s, int count) {
380381
private void generateHtmlReport(Map<ExecutedTest, Set<String>> testTagMap)
381382
throws IOException {
382383
try (FileWriter writer = new FileWriter(outputFile)) {
383-
writer.write("<!DOCTYPE html>\n<html>\n<head>\n");
384-
writer.write("<meta charset=\"UTF-8\">\n");
385-
writer.write("<title>Executed Test Tag Report</title>\n");
386-
writer.write("<style>\n");
387-
writer.write("body { font-family: Arial, sans-serif; margin: 20px; }\n");
388-
writer.write("table { border-collapse: collapse; width: 100%; margin: 20px 0; }\n");
389-
writer.write("th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }\n");
390-
writer.write("th { background-color: #4CAF50; color: white; }\n");
391-
writer.write("tr:nth-child(even) { background-color: #f2f2f2; }\n");
392-
writer.write(".pass { color: green; }\n");
393-
writer.write(".fail { color: red; }\n");
394-
writer.write(".error { color: orange; }\n");
395-
writer.write(".skip { color: gray; }\n");
384+
writer.write("<!DOCTYPE html>%n<html>%n<head>%n");
385+
writer.write("<meta charset=\"UTF-8\">%n");
386+
writer.write("<title>Executed Test Tag Report</title>%n");
387+
writer.write("<style>%n");
388+
writer.write("body { font-family: Arial, sans-serif; margin: 20px; }%n");
389+
writer.write("table { border-collapse: collapse; width: 100%; margin: 20px 0; }%n");
390+
writer.write("th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }%n");
391+
writer.write("th { background-color: #4CAF50; color: white; }%n");
392+
writer.write("tr:nth-child(even) { background-color: #f2f2f2; }%n");
393+
writer.write(".pass { color: green; }%n");
394+
writer.write(".fail { color: red; }%n");
395+
writer.write(".error { color: orange; }%n");
396+
writer.write(".skip { color: gray; }%n");
396397
writer.write(".tag { background-color: #e7f3ff; padding: 2px 8px; ");
397-
writer.write("border-radius: 3px; margin: 2px; display: inline-block; }\n");
398-
writer.write("</style>\n");
399-
writer.write("</head>\n<body>\n");
400-
writer.write("<h1>Executed Test Tag Report</h1>\n");
398+
writer.write("border-radius: 3px; margin: 2px; display: inline-block; }%n");
399+
writer.write("</style>%n");
400+
writer.write("</head>%n<body>%n");
401+
writer.write("<h1>Executed Test Tag Report</h1>%n");
401402

402403
// Summary
403-
writer.write("<h2>Summary</h2>\n");
404-
writer.write("<table>\n");
405-
writer.write("<tr><th>Metric</th><th>Count</th></tr>\n");
406-
writer.write("<tr><td>Total Tests</td><td>" + testTagMap.size() + "</td></tr>\n");
404+
writer.write("<h2>Summary</h2>%n");
405+
writer.write("<table>%n");
406+
writer.write("<tr><th>Metric</th><th>Count</th></tr>%n");
407+
writer.write("<tr><td>Total Tests</td><td>" + testTagMap.size() + "</td></tr>%n");
407408

408409
long passed = testTagMap.keySet().stream()
409410
.filter(t -> !t.isFailed() && !t.isError()).count();
410411
long failed = testTagMap.keySet().stream().filter(ExecutedTest::isFailed).count();
411412
long errors = testTagMap.keySet().stream().filter(ExecutedTest::isError).count();
412413

413-
writer.write("<tr><td>Passed</td><td class='pass'>" + passed + "</td></tr>\n");
414-
writer.write("<tr><td>Failed</td><td class='fail'>" + failed + "</td></tr>\n");
415-
writer.write("<tr><td>Errors</td><td class='error'>" + errors + "</td></tr>\n");
416-
writer.write("</table>\n");
414+
writer.write("<tr><td>Passed</td><td class='pass'>" + passed + "</td></tr>%n");
415+
writer.write("<tr><td>Failed</td><td class='fail'>" + failed + "</td></tr>%n");
416+
writer.write("<tr><td>Errors</td><td class='error'>" + errors + "</td></tr>%n");
417+
writer.write("</table>%n");
417418

418419
// Tags summary
419420
Map<String, List<ExecutedTest>> tagToTests = new HashMap<>();
@@ -423,19 +424,19 @@ private void generateHtmlReport(Map<ExecutedTest, Set<String>> testTagMap)
423424
}
424425
}
425426

426-
writer.write("<h2>Tags Summary</h2>\n");
427-
writer.write("<table>\n");
428-
writer.write("<tr><th>Tag</th><th>Tests</th></tr>\n");
427+
writer.write("<h2>Tags Summary</h2>%n");
428+
writer.write("<table>%n");
429+
writer.write("<tr><th>Tag</th><th>Tests</th></tr>%n");
429430
for (Map.Entry<String, List<ExecutedTest>> entry : tagToTests.entrySet()) {
430431
writer.write("<tr><td>" + entry.getKey() + "</td><td>" +
431-
entry.getValue().size() + "</td></tr>\n");
432+
entry.getValue().size() + "</td></tr>%n");
432433
}
433-
writer.write("</table>\n");
434+
writer.write("</table>%n");
434435

435436
// All tests
436-
writer.write("<h2>All Executed Tests</h2>\n");
437-
writer.write("<table>\n");
438-
writer.write("<tr><th>Status</th><th>Test</th><th>Tags</th><th>Time</th></tr>\n");
437+
writer.write("<h2>All Executed Tests</h2>%n");
438+
writer.write("<table>%n");
439+
writer.write("<tr><th>Status</th><th>Test</th><th>Tags</th><th>Time</th></tr>%n");
439440
for (Map.Entry<ExecutedTest, Set<String>> entry : testTagMap.entrySet()) {
440441
ExecutedTest test = entry.getKey();
441442
String statusClass = test.isFailed() ? "fail" :
@@ -451,49 +452,49 @@ private void generateHtmlReport(Map<ExecutedTest, Set<String>> testTagMap)
451452
}
452453
writer.write("</td>");
453454
writer.write("<td>" + test.getTime() + "s</td>");
454-
writer.write("</tr>\n");
455+
writer.write("</tr>%n");
455456
}
456-
writer.write("</table>\n");
457+
writer.write("</table>%n");
457458

458-
writer.write("</body>\n</html>");
459+
writer.write("</body>%n</html>");
459460
}
460461
}
461462

462463
private void generateJsonReport(Map<ExecutedTest, Set<String>> testTagMap)
463464
throws IOException {
464465
try (FileWriter writer = new FileWriter(outputFile)) {
465-
writer.write("{\n");
466-
writer.write(" \"executedTests\": [\n");
466+
writer.write("{%n");
467+
writer.write(" \"executedTests\": [%n");
467468

468469
int count = 0;
469470
for (Map.Entry<ExecutedTest, Set<String>> entry : testTagMap.entrySet()) {
470-
if (count++ > 0) writer.write(",\n");
471+
if (count++ > 0) writer.write(",%n");
471472
ExecutedTest test = entry.getKey();
472-
writer.write(" {\n");
473-
writer.write(" \"class\": \"" + escapeJson(test.getClassName()) + "\",\n");
474-
writer.write(" \"method\": \"" + escapeJson(test.getMethodName()) + "\",\n");
475-
writer.write(" \"time\": " + test.getTime() + ",\n");
476-
writer.write(" \"skipped\": " + test.isSkipped() + ",\n");
477-
writer.write(" \"failed\": " + test.isFailed() + ",\n");
478-
writer.write(" \"error\": " + test.isError() + ",\n");
473+
writer.write(" {%n");
474+
writer.write(" \"class\": \"" + escapeJson(test.getClassName()) + "\",%n");
475+
writer.write(" \"method\": \"" + escapeJson(test.getMethodName()) + "\",%n");
476+
writer.write(" \"time\": " + test.getTime() + ",%n");
477+
writer.write(" \"skipped\": " + test.isSkipped() + ",%n");
478+
writer.write(" \"failed\": " + test.isFailed() + ",%n");
479+
writer.write(" \"error\": " + test.isError() + ",%n");
479480
writer.write(" \"tags\": [");
480481
writer.write(entry.getValue().stream()
481482
.map(tag -> "\"" + escapeJson(tag) + "\"")
482483
.collect(Collectors.joining(", ")));
483-
writer.write("]\n");
484+
writer.write("]%n");
484485
writer.write(" }");
485486
}
486487

487-
writer.write("\n ]\n");
488-
writer.write("}\n");
488+
writer.write("%n ]%n");
489+
writer.write("}%n");
489490
}
490491
}
491492

492493
private void generateXmlReport(Map<ExecutedTest, Set<String>> testTagMap)
493494
throws IOException {
494495
try (FileWriter writer = new FileWriter(outputFile)) {
495-
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
496-
writer.write("<executedTestTagReport>\n");
496+
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n");
497+
writer.write("<executedTestTagReport>%n");
497498

498499
for (Map.Entry<ExecutedTest, Set<String>> entry : testTagMap.entrySet()) {
499500
ExecutedTest test = entry.getKey();
@@ -502,14 +503,14 @@ private void generateXmlReport(Map<ExecutedTest, Set<String>> testTagMap)
502503
writer.write("time=\"" + test.getTime() + "\" ");
503504
writer.write("skipped=\"" + test.isSkipped() + "\" ");
504505
writer.write("failed=\"" + test.isFailed() + "\" ");
505-
writer.write("error=\"" + test.isError() + "\">\n");
506+
writer.write("error=\"" + test.isError() + "\">%n");
506507
for (String tag : entry.getValue()) {
507-
writer.write(" <tag>" + escapeXml(tag) + "</tag>\n");
508+
writer.write(" <tag>" + escapeXml(tag) + "</tag>%n");
508509
}
509-
writer.write(" </test>\n");
510+
writer.write(" </test>%n");
510511
}
511512

512-
writer.write("</executedTestTagReport>\n");
513+
writer.write("</executedTestTagReport>%n");
513514
}
514515
}
515516

0 commit comments

Comments
 (0)