1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.maven.shared.utils.logging; 20 21 import java.util.Formatter; 22 23 /** 24 * Message builder that supports configurable styling. 25 * An instance of this interface can be retrieved with {@link MessageUtils#buffer()}. 26 * After the message has been constructed with any of the append methods its content can be retrieved 27 * with {@link #build()}. 28 * 29 * @see MessageUtils 30 * @since 3.1.0 31 */ 32 public interface MessageBuilder { 33 /** 34 * Append message content in success style. 35 * By default, bold green 36 * @param message the message to append 37 * @return the current builder 38 */ 39 MessageBuilder success(Object message); 40 41 /** 42 * Append message content in warning style. 43 * By default, bold yellow 44 * @param message the message to append 45 * @return the current builder 46 */ 47 MessageBuilder warning(Object message); 48 49 /** 50 * Append message content in failure style. 51 * By default, bold red 52 * @param message the message to append 53 * @return the current builder 54 */ 55 MessageBuilder failure(Object message); 56 57 /** 58 * Append message content in strong style. 59 * By default, bold 60 * @param message the message to append 61 * @return the current builder 62 */ 63 MessageBuilder strong(Object message); 64 65 /** 66 * Append message content in mojo style. 67 * By default, green 68 * @param message the message to append 69 * @return the current builder 70 */ 71 MessageBuilder mojo(Object message); 72 73 /** 74 * Append message content in project style. 75 * By default, cyan 76 * @param message the message to append 77 * @return the current builder 78 */ 79 MessageBuilder project(Object message); 80 81 // 82 // message building methods modelled after Ansi methods 83 // 84 /** 85 * Append content to the message buffer. 86 * @param value the content to append 87 * @param offset the index of the first {@code char} to append 88 * @param len the number of {@code char}s to append 89 * @return the current builder 90 */ 91 MessageBuilder a(char[] value, int offset, int len); 92 93 /** 94 * Append content to the message buffer. 95 * @param value the content to append 96 * @return the current builder 97 */ 98 MessageBuilder a(char[] value); 99 100 /** 101 * Append content to the message buffer. 102 * @param value the content to append 103 * @param start the starting index of the subsequence to be appended 104 * @param end the end index of the subsequence to be appended 105 * @return the current builder 106 */ 107 MessageBuilder a(CharSequence value, int start, int end); 108 109 /** 110 * Append content to the message buffer. 111 * @param value the content to append 112 * @return the current builder 113 */ 114 MessageBuilder a(CharSequence value); 115 116 /** 117 * Append content to the message buffer. 118 * @param value the content to append 119 * @return the current builder 120 */ 121 MessageBuilder a(Object value); 122 123 /** 124 * Append newline to the message buffer. 125 * @return the current builder 126 */ 127 MessageBuilder newline(); 128 129 /** 130 * Append formatted content to the buffer. 131 * @see String#format(String, Object...) 132 * @param pattern a format string according to the {@link Formatter} syntax 133 * @param args arguments referenced by the format specifiers in the format string. 134 * @return the current builder 135 */ 136 MessageBuilder format(String pattern, Object... args); 137 138 /** 139 * Get the message constructed by this builder. 140 * The underlying buffer is not reset with this method, i.e. if you continue using this builder you just 141 * append content to the existing one. 142 * @return the message 143 * @since 4.0.0 144 */ 145 String build(); 146 147 /** 148 * Same as {@link MessageBuilder#build()}. 149 * @deprecated Rather use {@link MessageBuilder#build()} 150 */ 151 @Deprecated 152 String toString(); 153 }