gnodet-bot commented on code in PR #13888:
URL: https://github.com/apache/maven/pull/13888#discussion_r4505387859
##########
maven-jline/src/main/java/org/apache/maven/jline/JLineMessageBuilderFactory.java:
##########
@@ -58,29 +64,144 @@ public MessageBuilder builder() {
@Override
public MessageBuilder builder(int size) {
- return new JlineMessageBuilder(resolver, size);
+ return new AnsiMessageBuilder(size);
+ }
+
+ /**
+ * Resolves a style to its ANSI escape sequence (empty if it has no
effect). A style is either a spec like
+ * {@code bold,f:red}, or a reference {@code .name:-default} looked up
from the {@code maven.style.name} or
+ * {@code style.name} system property, falling back to {@code default}.
+ */
+ static String resolve(String style) {
+ return STYLES.computeIfAbsent(style,
JLineMessageBuilderFactory::doResolve);
+ }
+
+ private static String doResolve(String style) {
+ String spec = style;
+ if (spec.startsWith(".")) {
+ int i = spec.indexOf(":-");
+ String name = i < 0 ? spec.substring(1) : spec.substring(1, i);
+ String def = i < 0 ? "" : spec.substring(i + 2);
+ spec = System.getProperty("maven.style." + name,
System.getProperty("style." + name, def));
+ }
+ // same order as JLine emitted (ITs match exact bytes): attributes
3-9, foreground, background, bold, faint
+ String[] slots = new String[5];
+ TreeSet<String> attributes = new TreeSet<>();
+ for (String item : spec.split(",")) {
+ String code = code(item.trim().toLowerCase(Locale.ROOT));
+ if (code == null) {
+ continue;
+ }
+ int colon = item.indexOf(':');
+ if (colon > 0) {
+ String target = item.trim().substring(0,
colon).toLowerCase(Locale.ROOT);
Review Comment:
🔧 **Nit — `colon` index computed on untrimmed `item`, then used to slice the
trimmed string.**
`item.indexOf(':')` at line 95 operates on the raw (untrimmed) string from
`spec.split(",")`. If a spec contains a space after a comma (e.g. `"bold,
f:red"`), `item` is `" f:red"`, `item.indexOf(':')` returns `2`, but
`item.trim()` is `"f:red"` — `"f:red".substring(0, 2)` gives `"f:"` instead of
`"f"`. The `startsWith("f")` check still passes by accident, but the index math
is fragile. Compute `colon` on the already-trimmed string:
```suggestion
int colon = item.trim().indexOf(':');
if (colon > 0) {
String target = item.trim().substring(0,
colon).toLowerCase(Locale.ROOT);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]