From f6528183f2ba561ab4066ca10bdbda9243e28ca9 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Fri, 25 Oct 2024 14:24:08 +0200 Subject: [PATCH] [MNG-8361][MNG-8300] Fix color styles" (#1851) * [MNG-8361] Document color styles properly * [MNG-8300] Revert to bright-black to restore transfer colors --- .../java/org/apache/maven/api/Constants.java | 107 +++++++++++++++++- .../maven/api/services/MessageBuilder.java | 21 ++-- .../jline/JLineMessageBuilderFactory.java | 9 +- src/site/markdown/configuration.md | 21 +++- 4 files changed, 141 insertions(+), 17 deletions(-) diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/Constants.java b/api/maven-api-core/src/main/java/org/apache/maven/api/Constants.java index 00997bd445..6e1f4fa7ad 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/Constants.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/Constants.java @@ -145,6 +145,34 @@ public final class Constants { @Config public static final String MAVEN_EXT_CLASS_PATH = "maven.ext.class.path"; + public static final String MAVEN_STYLE_PREFIX = "maven.style."; + + // Style Names + public static final String MAVEN_STYLE_TRANSFER_NAME = "transfer"; + public static final String MAVEN_STYLE_TRACE_NAME = "trace"; + public static final String MAVEN_STYLE_DEBUG_NAME = "debug"; + public static final String MAVEN_STYLE_INFO_NAME = "info"; + public static final String MAVEN_STYLE_WARNING_NAME = "warning"; + public static final String MAVEN_STYLE_ERROR_NAME = "error"; + public static final String MAVEN_STYLE_SUCCESS_NAME = "success"; + public static final String MAVEN_STYLE_FAILURE_NAME = "failure"; + public static final String MAVEN_STYLE_STRONG_NAME = "strong"; + public static final String MAVEN_STYLE_MOJO_NAME = "mojo"; + public static final String MAVEN_STYLE_PROJECT_NAME = "project"; + + // Default Values + public static final String MAVEN_STYLE_TRANSFER_DEFAULT = "f:bright-black"; + public static final String MAVEN_STYLE_TRACE_DEFAULT = "bold,f:magenta"; + public static final String MAVEN_STYLE_DEBUG_DEFAULT = "bold,f:cyan"; + public static final String MAVEN_STYLE_INFO_DEFAULT = "bold,f:blue"; + public static final String MAVEN_STYLE_WARNING_DEFAULT = "bold,f:yellow"; + public static final String MAVEN_STYLE_ERROR_DEFAULT = "bold,f:red"; + public static final String MAVEN_STYLE_SUCCESS_DEFAULT = "bold,f:green"; + public static final String MAVEN_STYLE_FAILURE_DEFAULT = "bold,f:red"; + public static final String MAVEN_STYLE_STRONG_DEFAULT = "bold"; + public static final String MAVEN_STYLE_MOJO_DEFAULT = "f:green"; + public static final String MAVEN_STYLE_PROJECT_DEFAULT = "f:cyan"; + /** * Maven output color mode. * Allowed values are auto, always, never. @@ -152,7 +180,84 @@ public final class Constants { * @since 4.0.0 */ @Config(defaultValue = "auto") - public static final String MAVEN_STYLE_COLOR_PROPERTY = "maven.style.color"; + public static final String MAVEN_STYLE_COLOR_PROPERTY = MAVEN_STYLE_PREFIX + "color"; + + /** + * Color style for transfer messages. + * @since 4.0.0 + */ + @Config(defaultValue = MAVEN_STYLE_TRANSFER_DEFAULT) + public static final String MAVEN_STYLE_TRANSFER = MAVEN_STYLE_PREFIX + MAVEN_STYLE_TRANSFER_NAME; + + /** + * Color style for trace messages. + * @since 4.0.0 + */ + @Config(defaultValue = MAVEN_STYLE_TRACE_DEFAULT) + public static final String MAVEN_STYLE_TRACE = MAVEN_STYLE_PREFIX + MAVEN_STYLE_TRACE_NAME; + + /** + * Color style for debug messages. + * @since 4.0.0 + */ + @Config(defaultValue = MAVEN_STYLE_DEBUG_DEFAULT) + public static final String MAVEN_STYLE_DEBUG = MAVEN_STYLE_PREFIX + MAVEN_STYLE_DEBUG_NAME; + + /** + * Color style for info messages. + * @since 4.0.0 + */ + @Config(defaultValue = MAVEN_STYLE_INFO_DEFAULT) + public static final String MAVEN_STYLE_INFO = MAVEN_STYLE_PREFIX + MAVEN_STYLE_INFO_NAME; + + /** + * Color style for warning messages. + * @since 4.0.0 + */ + @Config(defaultValue = MAVEN_STYLE_WARNING_DEFAULT) + public static final String MAVEN_STYLE_WARNING = MAVEN_STYLE_PREFIX + MAVEN_STYLE_WARNING_NAME; + + /** + * Color style for error messages. + * @since 4.0.0 + */ + @Config(defaultValue = MAVEN_STYLE_ERROR_DEFAULT) + public static final String MAVEN_STYLE_ERROR = MAVEN_STYLE_PREFIX + MAVEN_STYLE_ERROR_NAME; + + /** + * Color style for success messages. + * @since 4.0.0 + */ + @Config(defaultValue = MAVEN_STYLE_SUCCESS_DEFAULT) + public static final String MAVEN_STYLE_SUCCESS = MAVEN_STYLE_PREFIX + MAVEN_STYLE_SUCCESS_NAME; + + /** + * Color style for failure messages. + * @since 4.0.0 + */ + @Config(defaultValue = MAVEN_STYLE_FAILURE_DEFAULT) + public static final String MAVEN_STYLE_FAILURE = MAVEN_STYLE_PREFIX + MAVEN_STYLE_FAILURE_NAME; + + /** + * Color style for strong messages. + * @since 4.0.0 + */ + @Config(defaultValue = MAVEN_STYLE_STRONG_DEFAULT) + public static final String MAVEN_STYLE_STRONG = MAVEN_STYLE_PREFIX + MAVEN_STYLE_STRONG_NAME; + + /** + * Color style for mojo messages. + * @since 4.0.0 + */ + @Config(defaultValue = MAVEN_STYLE_MOJO_DEFAULT) + public static final String MAVEN_STYLE_MOJO = MAVEN_STYLE_PREFIX + MAVEN_STYLE_MOJO_NAME; + + /** + * Color style for project messages. + * @since 4.0.0 + */ + @Config(defaultValue = MAVEN_STYLE_PROJECT_DEFAULT) + public static final String MAVEN_STYLE_PROJECT = MAVEN_STYLE_PREFIX + MAVEN_STYLE_PROJECT_NAME; /** * Build timestamp format. diff --git a/api/maven-api-core/src/main/java/org/apache/maven/api/services/MessageBuilder.java b/api/maven-api-core/src/main/java/org/apache/maven/api/services/MessageBuilder.java index 8a996032e2..e38c861092 100644 --- a/api/maven-api-core/src/main/java/org/apache/maven/api/services/MessageBuilder.java +++ b/api/maven-api-core/src/main/java/org/apache/maven/api/services/MessageBuilder.java @@ -18,6 +18,7 @@ */ package org.apache.maven.api.services; +import org.apache.maven.api.Constants; import org.apache.maven.api.annotations.Nonnull; /** @@ -37,7 +38,7 @@ public interface MessageBuilder extends Appendable { */ @Nonnull default MessageBuilder trace(Object message) { - return style(".trace:-bold,f:magenta", message); + return style("." + Constants.MAVEN_STYLE_TRACE_NAME + ":-" + Constants.MAVEN_STYLE_TRACE_DEFAULT, message); } /** @@ -49,7 +50,7 @@ public interface MessageBuilder extends Appendable { */ @Nonnull default MessageBuilder debug(Object message) { - return style(".debug:-bold,f:cyan", message); + return style("." + Constants.MAVEN_STYLE_DEBUG_NAME + ":-" + Constants.MAVEN_STYLE_DEBUG_DEFAULT, message); } /** @@ -61,7 +62,7 @@ public interface MessageBuilder extends Appendable { */ @Nonnull default MessageBuilder info(Object message) { - return style(".info:-bold,f:blue", message); + return style("." + Constants.MAVEN_STYLE_INFO_NAME + ":-" + Constants.MAVEN_STYLE_INFO_DEFAULT, message); } /** @@ -73,7 +74,7 @@ public interface MessageBuilder extends Appendable { */ @Nonnull default MessageBuilder warning(Object message) { - return style(".warning:-bold,f:yellow", message); + return style("." + Constants.MAVEN_STYLE_WARNING_NAME + ":-" + Constants.MAVEN_STYLE_WARNING_DEFAULT, message); } /** @@ -85,7 +86,7 @@ public interface MessageBuilder extends Appendable { */ @Nonnull default MessageBuilder error(Object message) { - return style(".error:-bold,f:red", message); + return style("." + Constants.MAVEN_STYLE_ERROR_NAME + ":-" + Constants.MAVEN_STYLE_ERROR_DEFAULT, message); } /** @@ -97,7 +98,7 @@ public interface MessageBuilder extends Appendable { */ @Nonnull default MessageBuilder success(Object message) { - return style(".success:-bold,f:green", message); + return style("." + Constants.MAVEN_STYLE_DEBUG_NAME + ":-" + Constants.MAVEN_STYLE_DEBUG_DEFAULT, message); } /** @@ -109,7 +110,7 @@ public interface MessageBuilder extends Appendable { */ @Nonnull default MessageBuilder failure(Object message) { - return style(".failure:-bold,f:red", message); + return style("." + Constants.MAVEN_STYLE_FAILURE_NAME + ":-" + Constants.MAVEN_STYLE_FAILURE_DEFAULT, message); } /** @@ -121,7 +122,7 @@ public interface MessageBuilder extends Appendable { */ @Nonnull default MessageBuilder strong(Object message) { - return style(".strong:-bold", message); + return style("." + Constants.MAVEN_STYLE_STRONG_NAME + ":-" + Constants.MAVEN_STYLE_STRONG_DEFAULT, message); } /** @@ -133,7 +134,7 @@ public interface MessageBuilder extends Appendable { */ @Nonnull default MessageBuilder mojo(Object message) { - return style(".mojo:-f:green", message); + return style("." + Constants.MAVEN_STYLE_MOJO_NAME + ":-" + Constants.MAVEN_STYLE_MOJO_DEFAULT, message); } /** @@ -145,7 +146,7 @@ public interface MessageBuilder extends Appendable { */ @Nonnull default MessageBuilder project(Object message) { - return style(".project:-f:cyan", message); + return style("." + Constants.MAVEN_STYLE_PROJECT_NAME + ":-" + Constants.MAVEN_STYLE_PROJECT_DEFAULT, message); } @Nonnull diff --git a/maven-jline/src/main/java/org/apache/maven/jline/JLineMessageBuilderFactory.java b/maven-jline/src/main/java/org/apache/maven/jline/JLineMessageBuilderFactory.java index 703a880423..92a287a0a0 100644 --- a/maven-jline/src/main/java/org/apache/maven/jline/JLineMessageBuilderFactory.java +++ b/maven-jline/src/main/java/org/apache/maven/jline/JLineMessageBuilderFactory.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.apache.maven.api.Constants; import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.services.MessageBuilder; import org.apache.maven.api.services.MessageBuilderFactory; @@ -279,7 +280,13 @@ public class JLineMessageBuilderFactory implements MessageBuilderFactory, Prompt private final Map styles = new ConcurrentHashMap<>(); MavenStyleResolver() { - super(s -> System.getProperty("style." + s)); + super(key -> { + String v = System.getProperty(Constants.MAVEN_STYLE_PREFIX + key); + if (v == null) { + v = System.getProperty("style." + key); + } + return v; + }); } @Override diff --git a/src/site/markdown/configuration.md b/src/site/markdown/configuration.md index 03f197d900..098e5f991d 100644 --- a/src/site/markdown/configuration.md +++ b/src/site/markdown/configuration.md @@ -47,9 +47,20 @@ under the License. | 20. | `maven.resolver.dependencyManagerTransitivity` | `String` | User property for selecting dependency manager behaviour regarding transitive dependencies and dependency management entries in their POMs. Maven 3 targeted full backward compatibility with Maven2, hence it ignored dependency management entries in transitive dependency POMs. Maven 4 enables "transitivity" by default, hence unlike Maven2, obeys dependency management entries deep in dependency graph as well.
Default: "true". | `true` | 4.0.0 | User properties | | 21. | `maven.resolver.transport` | `String` | Resolver transport to use. Can be default, wagon, apache, jdk or auto. | `default` | 4.0.0 | User properties | | 22. | `maven.style.color` | `String` | Maven output color mode. Allowed values are auto, always, never. | `auto` | 4.0.0 | User properties | -| 23. | `maven.user.conf` | `String` | Maven user configuration directory. | `${user.home}/.m2` | 4.0.0 | User properties | -| 24. | `maven.user.extensions` | `String` | Maven user extensions. | `${maven.user.conf}/extensions.xml` | 4.0.0 | User properties | -| 25. | `maven.user.settings` | `String` | Maven user settings. | `${maven.user.conf}/settings.xml` | 4.0.0 | User properties | -| 26. | `maven.user.toolchains` | `String` | Maven user toolchains. | `${maven.user.home}/toolchains.xml` | 4.0.0 | User properties | -| 27. | `maven.versionFilters` | `String` | User property for version filters expression, a semicolon separated list of filters to apply. By default, no version filter is applied (like in Maven 3).
Supported filters: Example filter expression: "h(5);s;e(org.foo:bar:1) will cause: ranges are filtered for "top 5" (instead full range), snapshots are banned if root project is not a snapshot, and if range for org.foo:bar is being processed, version 1 is omitted. | - | 4.0.0 | User properties | +| 23. | `maven.style.debug` | `String` | Color style for debug messages. | `bold,f:cyan` | 4.0.0 | User properties | +| 24. | `maven.style.error` | `String` | Color style for error messages. | `bold,f:red` | 4.0.0 | User properties | +| 25. | `maven.style.failure` | `String` | Color style for failure messages. | `bold,f:red` | 4.0.0 | User properties | +| 26. | `maven.style.info` | `String` | Color style for info messages. | `bold,f:blue` | 4.0.0 | User properties | +| 27. | `maven.style.mojo` | `String` | Color style for mojo messages. | `f:green` | 4.0.0 | User properties | +| 28. | `maven.style.project` | `String` | Color style for project messages. | `f:cyan` | 4.0.0 | User properties | +| 29. | `maven.style.strong` | `String` | Color style for strong messages. | `bold` | 4.0.0 | User properties | +| 30. | `maven.style.success` | `String` | Color style for success messages. | `bold,f:green` | 4.0.0 | User properties | +| 31. | `maven.style.trace` | `String` | Color style for trace messages. | `bold,f:magenta` | 4.0.0 | User properties | +| 32. | `maven.style.transfer` | `String` | Color style for transfer messages. | `f:bright-black` | 4.0.0 | User properties | +| 33. | `maven.style.warning` | `String` | Color style for warning messages. | `bold,f:yellow` | 4.0.0 | User properties | +| 34. | `maven.user.conf` | `String` | Maven user configuration directory. | `${user.home}/.m2` | 4.0.0 | User properties | +| 35. | `maven.user.extensions` | `String` | Maven user extensions. | `${maven.user.conf}/extensions.xml` | 4.0.0 | User properties | +| 36. | `maven.user.settings` | `String` | Maven user settings. | `${maven.user.conf}/settings.xml` | 4.0.0 | User properties | +| 37. | `maven.user.toolchains` | `String` | Maven user toolchains. | `${maven.user.home}/toolchains.xml` | 4.0.0 | User properties | +| 38. | `maven.versionFilters` | `String` | User property for version filters expression, a semicolon separated list of filters to apply. By default, no version filter is applied (like in Maven 3).
Supported filters: Example filter expression: "h(5);s;e(org.foo:bar:1) will cause: ranges are filtered for "top 5" (instead full range), snapshots are banned if root project is not a snapshot, and if range for org.foo:bar is being processed, version 1 is omitted. | - | 4.0.0 | User properties |