gnodet-bot commented on code in PR #14008: URL: https://github.com/apache/maven/pull/14008#discussion_r4582965495
########## maven-core/src/main/java/org/apache/maven/internal/message/ApiMessageBuilderFactory.java: ########## @@ -0,0 +1,260 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.internal.message; + +import javax.inject.Named; +import javax.inject.Singleton; + +import java.util.Arrays; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.TreeSet; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.BooleanSupplier; + +import org.apache.maven.api.services.MessageBuilder; +import org.apache.maven.api.services.MessageBuilderFactory; +import org.apache.maven.shared.utils.logging.MessageUtils; + +/** + * Provides the Maven 4 API {@link MessageBuilderFactory}, so that a plugin can use one API on Maven 3 and Maven 4. + * Colours follow the {@link MessageUtils} setting Maven applies from {@code --color} and {@code --batch-mode}; style + * names are resolved as Maven 3.10 and Maven 4 resolve them. + */ +@Named +@Singleton +public class ApiMessageBuilderFactory implements MessageBuilderFactory { + + static final String RESET = "\u001B[0m"; + + private static final List<String> COLORS = + Arrays.asList("black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"); + + private static final Map<String, String> STYLES = new ConcurrentHashMap<>(); Review Comment: **[low]** The `STYLES` cache is a static `ConcurrentHashMap` with `computeIfAbsent` — results are cached forever, including system property lookups performed inside `doResolve()`. If `maven.style.foo` is set after a `.foo:-default` style has been resolved once, the override is silently ignored. This matches Maven 3.10.x behavior (`#13919`) and is unlikely to bite in practice (styles are resolved before user code runs), but it's worth documenting in the class Javadoc to avoid confusion. ########## maven-core/src/main/java/org/apache/maven/api/services/MessageBuilder.java: ########## @@ -0,0 +1,274 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.api.services; + +import org.apache.maven.api.Constants; +import org.apache.maven.api.annotations.Nonnull; + +/** + * Message builder that supports configurable styling. + * + * @since 3.9.17 + * @see MessageBuilderFactory + */ +public interface MessageBuilder extends Appendable { + + /** + * Append message content in trace style. + * By default, bold magenta + * + * @param message the message to append + * @return the current builder + */ + @Nonnull + default MessageBuilder trace(Object message) { + return style("." + Constants.MAVEN_STYLE_TRACE_NAME + ":-" + Constants.MAVEN_STYLE_TRACE_DEFAULT, message); + } + + /** + * Append message content in debug style. + * By default, bold cyan + * + * @param message the message to append + * @return the current builder + */ + @Nonnull + default MessageBuilder debug(Object message) { + return style("." + Constants.MAVEN_STYLE_DEBUG_NAME + ":-" + Constants.MAVEN_STYLE_DEBUG_DEFAULT, message); + } + + /** + * Append message content in info style. + * By default, bold blue + * + * @param message the message to append + * @return the current builder + */ + @Nonnull + default MessageBuilder info(Object message) { + return style("." + Constants.MAVEN_STYLE_INFO_NAME + ":-" + Constants.MAVEN_STYLE_INFO_DEFAULT, message); + } + + /** + * Append message content in warning style. + * By default, bold yellow + * + * @param message the message to append + * @return the current builder + */ + @Nonnull + default MessageBuilder warning(Object message) { + return style("." + Constants.MAVEN_STYLE_WARNING_NAME + ":-" + Constants.MAVEN_STYLE_WARNING_DEFAULT, message); + } + + /** + * Append message content in error style. + * By default, bold red + * + * @param message the message to append + * @return the current builder + */ + @Nonnull + default MessageBuilder error(Object message) { + return style("." + Constants.MAVEN_STYLE_ERROR_NAME + ":-" + Constants.MAVEN_STYLE_ERROR_DEFAULT, message); + } + + /** + * Append message content in success style. + * By default, bold green + * + * @param message the message to append + * @return the current builder + */ + @Nonnull + default MessageBuilder success(Object message) { + return style("." + Constants.MAVEN_STYLE_SUCCESS_NAME + ":-" + Constants.MAVEN_STYLE_SUCCESS_DEFAULT, message); + } + + /** + * Append message content in failure style. + * By default, bold red + * + * @param message the message to append + * @return the current builder + */ + @Nonnull + default MessageBuilder failure(Object message) { + return style("." + Constants.MAVEN_STYLE_FAILURE_NAME + ":-" + Constants.MAVEN_STYLE_FAILURE_DEFAULT, message); + } + + /** + * Append message content in strong style. + * By default, bold + * + * @param message the message to append + * @return the current builder + */ + @Nonnull + default MessageBuilder strong(Object message) { + return style("." + Constants.MAVEN_STYLE_STRONG_NAME + ":-" + Constants.MAVEN_STYLE_STRONG_DEFAULT, message); + } + + /** + * Append message content in mojo style. + * By default, green + * + * @param message the message to append + * @return the current builder + */ + @Nonnull + default MessageBuilder mojo(Object message) { + return style("." + Constants.MAVEN_STYLE_MOJO_NAME + ":-" + Constants.MAVEN_STYLE_MOJO_DEFAULT, message); + } + + /** + * Append message content in project style. + * By default, cyan + * + * @param message the message to append + * @return the current builder + */ + @Nonnull + default MessageBuilder project(Object message) { + return style("." + Constants.MAVEN_STYLE_PROJECT_NAME + ":-" + Constants.MAVEN_STYLE_PROJECT_DEFAULT, message); + } + + @Nonnull + default MessageBuilder style(String style, Object message) { + return style(style).a(message).resetStyle(); + } + + MessageBuilder style(String style); + + MessageBuilder resetStyle(); Review Comment: **[low]** `style(String)` and `resetStyle()` are bare abstract declarations — no Javadoc, no `@param`/`@return`. Maven 4 main documents both. The 3.10.x copy (`#13919`) has the same gap, but syncing Javadoc here would make future forward-ports easier. ```suggestion /** * Applies the given style to subsequent append operations. * * @param style the style specification (e.g. {@code ".info:-bold"}) * @return this builder */ MessageBuilder style(String style); /** * Resets the current style to the default. * * @return this builder */ MessageBuilder resetStyle(); ``` -- 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]
