diff --git a/src/main/java/org/apache/maven/shared/utils/logging/AnsiMessageBuilder.java b/src/main/java/org/apache/maven/shared/utils/logging/AnsiMessageBuilder.java index 7f442397..f7eed76e 100644 --- a/src/main/java/org/apache/maven/shared/utils/logging/AnsiMessageBuilder.java +++ b/src/main/java/org/apache/maven/shared/utils/logging/AnsiMessageBuilder.java @@ -150,6 +150,12 @@ public AnsiMessageBuilder format( String pattern, Object... args ) @Override public String toString() + { + return build(); + } + + @Override + public String build() { return ansi.toString(); } diff --git a/src/main/java/org/apache/maven/shared/utils/logging/MessageBuilder.java b/src/main/java/org/apache/maven/shared/utils/logging/MessageBuilder.java index 649c0860..5060bd11 100644 --- a/src/main/java/org/apache/maven/shared/utils/logging/MessageBuilder.java +++ b/src/main/java/org/apache/maven/shared/utils/logging/MessageBuilder.java @@ -19,8 +19,13 @@ * under the License. */ +import java.util.Formatter; + /** * Message builder that supports configurable styling. + * An instance of this interface can be retrieved with {@link MessageUtils#buffer()}. + * After the message has been constructed with any of the append methods its content can be retrieved + * with {@link #build()}. * @see MessageUtils * @since 3.1.0 */ @@ -125,9 +130,25 @@ public interface MessageBuilder /** * Append formatted content to the buffer. * @see String#format(String, Object...) - * @param pattern a format string + * @param pattern a format string according to the {@link Formatter} syntax * @param args arguments referenced by the format specifiers in the format string. * @return the current builder */ MessageBuilder format( String pattern, Object... args ); + + /** + * Get the message constructed by this builder. + * The underlying buffer is not reset with this method, i.e. if you continue using this builder you just + * append content to the existing one. + * @return the message + * @since 4.0.0 + */ + String build(); + + /** + * Same as {@link MessageBuilder#build()}. + * @deprecated Rather use {@link MessageBuilder#build()} + */ + @Deprecated + String toString(); } diff --git a/src/main/java/org/apache/maven/shared/utils/logging/PlainMessageBuilder.java b/src/main/java/org/apache/maven/shared/utils/logging/PlainMessageBuilder.java index 5ff48844..ce788262 100644 --- a/src/main/java/org/apache/maven/shared/utils/logging/PlainMessageBuilder.java +++ b/src/main/java/org/apache/maven/shared/utils/logging/PlainMessageBuilder.java @@ -136,6 +136,12 @@ public PlainMessageBuilder format( String pattern, Object... args ) @Override public String toString() + { + return build(); + } + + @Override + public String build() { return buffer.toString(); }