Skip to content

Commit 77bb371

Browse files
committed
chore: Better log handling of missing tags
1 parent c469b8f commit 77bb371

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Better log handling of missing tags
13+
14+
### Fixed
15+
16+
- Wrap URLClassLoader creation in try-with-resources to ensure it's closed and avoid leaks. <https://github.com/fugerit-org/junit5-tag-check-maven-plugin/pull/2>
17+
1018
## [1.1.0] - 2025-11-28
1119

1220
### Added

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<maven-core-version>3.9.11</maven-core-version>
6262
<sonar.organization>fugerit-org</sonar.organization>
6363
<fj-doc-version>8.17.9</fj-doc-version>
64+
<common-lang3-version>3.20.0</common-lang3-version>
6465
</properties>
6566
<dependencyManagement>
6667
<dependencies>
@@ -105,6 +106,11 @@
105106
<artifactId>junit-platform-launcher</artifactId>
106107
<version>${junit-platform-launcher-version}</version>
107108
</dependency>
109+
<dependency>
110+
<groupId>org.apache.commons</groupId>
111+
<artifactId>commons-lang3</artifactId>
112+
<version>${common-lang3-version}</version>
113+
</dependency>
108114
<dependency>
109115
<groupId>org.junit.jupiter</groupId>
110116
<artifactId>junit-jupiter-api</artifactId>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.fugerit.java.junit5.tag.check.facade;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.apache.commons.lang3.StringUtils;
5+
6+
import java.util.Collection;
7+
8+
@Slf4j
9+
public class LogUtils {
10+
11+
private LogUtils() {}
12+
13+
/**
14+
* Logs a message surrounded by a simple ASCII border using log.warn().
15+
* The border adapts to the length of the longest line in the message.
16+
*
17+
* @param lines The warning message.
18+
*/
19+
public static void logWarningInBox(Collection<String> lines) {
20+
// 1. Find the maximum line length
21+
int maxLength = 0;
22+
for (String line : lines) {
23+
if (line.length() > maxLength) {
24+
maxLength = line.length();
25+
}
26+
}
27+
28+
// 2. Determine the border length: max line length + 2 spaces for padding
29+
int contentWidth = maxLength + 2; // + 2 for the ' ' padding before and after text
30+
31+
// 3. Create the top and bottom borders using the Java 8 compatible helper
32+
String horizontalLine = StringUtils.repeat("-", contentWidth );
33+
String horizontalBorder = "+" + horizontalLine + "+";
34+
35+
// Log the top border
36+
log.warn(horizontalBorder);
37+
38+
// 4. Log each line with padding
39+
for (String line : lines) {
40+
// Calculate necessary trailing spaces for uniform box width
41+
int trailingSpaces = maxLength - line.length();
42+
String paddedSpaces = StringUtils.repeat( " ", trailingSpaces);
43+
44+
String paddedLine = "| " + line + paddedSpaces + " |";
45+
log.warn(paddedLine);
46+
}
47+
48+
// Log the bottom border
49+
log.warn(horizontalBorder);
50+
}
51+
52+
}

src/main/java/org/fugerit/java/junit5/tag/check/facade/TagCheckFacade.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ public static void checkRequiredTags(Collection<String> requiredTags, boolean fa
3131
if (failOnMissingTag) {
3232
throw new MojoExecutionException(message);
3333
} else {
34-
log.warn(message);
34+
LogUtils.logWarningInBox( Arrays.asList( message ) );
3535
}
3636
} else {
3737
log.info("All required tags found in executed tests: {}",
3838
String.join(", ", requiredTags));
3939
}
4040
}
4141

42+
43+
4244
}

0 commit comments

Comments
 (0)