[MNG-8361][MNG-8300] Fix color styles" (#1851)

* [MNG-8361] Document color styles properly
* [MNG-8300] Revert to bright-black to restore transfer colors
This commit is contained in:
Guillaume Nodet 2024-10-25 14:24:08 +02:00 committed by GitHub
parent 2f620ef9c9
commit f6528183f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 141 additions and 17 deletions

View File

@ -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 <code>auto</code>, <code>always</code>, <code>never</code>.
@ -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.

View File

@ -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

View File

@ -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<String, AttributedStyle> 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

View File

@ -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. <br/> Default: <code>"true"</code>. | `true` | 4.0.0 | User properties |
| 21. | `maven.resolver.transport` | `String` | Resolver transport to use. Can be <code>default</code>, <code>wagon</code>, <code>apache</code>, <code>jdk</code> or <code>auto</code>. | `default` | 4.0.0 | User properties |
| 22. | `maven.style.color` | `String` | Maven output color mode. Allowed values are <code>auto</code>, <code>always</code>, <code>never</code>. | `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). <br/> Supported filters: <ul> <li>"h" or "h(num)" - highest version or top list of highest ones filter</li> <li>"l" or "l(num)" - lowest version or bottom list of lowest ones filter</li> <li>"s" - contextual snapshot filter</li> <li>"e(G:A:V)" - predicate filter (leaves out G:A:V from range, if hit, V can be range)</li> </ul> Example filter expression: <code>"h(5);s;e(org.foo:bar:1)</code> 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 <code>org.foo:bar</code> 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). <br/> Supported filters: <ul> <li>"h" or "h(num)" - highest version or top list of highest ones filter</li> <li>"l" or "l(num)" - lowest version or bottom list of lowest ones filter</li> <li>"s" - contextual snapshot filter</li> <li>"e(G:A:V)" - predicate filter (leaves out G:A:V from range, if hit, V can be range)</li> </ul> Example filter expression: <code>"h(5);s;e(org.foo:bar:1)</code> 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 <code>org.foo:bar</code> is being processed, version 1 is omitted. | - | 4.0.0 | User properties |