View Javadoc
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  /**
22   * Message builder implementation that just ignores styling, for Maven version earlier than 3.5.0.
23   */
24  class PlainMessageBuilder implements MessageBuilder, LoggerLevelRenderer {
25      private StringBuilder buffer;
26  
27      PlainMessageBuilder() {
28          buffer = new StringBuilder();
29      }
30  
31      PlainMessageBuilder(StringBuilder builder) {
32          buffer = builder;
33      }
34  
35      PlainMessageBuilder(int size) {
36          buffer = new StringBuilder(size);
37      }
38  
39      public String debug(String message) {
40          return a(message).toString();
41      }
42  
43      public String info(String message) {
44          return a(message).toString();
45      }
46  
47      public String warning(String message) {
48          return a(message).toString();
49      }
50  
51      public String error(String message) {
52          return a(message).toString();
53      }
54  
55      public PlainMessageBuilder success(Object message) {
56          return a(message);
57      }
58  
59      public PlainMessageBuilder warning(Object message) {
60          return a(message);
61      }
62  
63      public PlainMessageBuilder failure(Object message) {
64          return a(message);
65      }
66  
67      public PlainMessageBuilder strong(Object message) {
68          return a(message);
69      }
70  
71      public PlainMessageBuilder mojo(Object message) {
72          return a(message);
73      }
74  
75      public PlainMessageBuilder project(Object message) {
76          return a(message);
77      }
78  
79      public PlainMessageBuilder a(char[] value, int offset, int len) {
80          buffer.append(value, offset, len);
81          return this;
82      }
83  
84      public PlainMessageBuilder a(char[] value) {
85          buffer.append(value);
86          return this;
87      }
88  
89      public PlainMessageBuilder a(CharSequence value, int start, int end) {
90          buffer.append(value, start, end);
91          return this;
92      }
93  
94      public PlainMessageBuilder a(CharSequence value) {
95          buffer.append(value);
96          return this;
97      }
98  
99      public PlainMessageBuilder a(Object value) {
100         buffer.append(value);
101         return this;
102     }
103 
104     public PlainMessageBuilder newline() {
105         buffer.append(System.getProperty("line.separator"));
106         return this;
107     }
108 
109     public PlainMessageBuilder format(String pattern, Object... args) {
110         buffer.append(String.format(pattern, args));
111         return this;
112     }
113 
114     @Override
115     public String toString() {
116         return build();
117     }
118 
119     @Override
120     public String build() {
121         return buffer.toString();
122     }
123 }