View Javadoc
1   package org.apache.maven.shared.utils.logging;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  /**
23   * Message builder implementation that just ignores styling, for Maven version earlier than 3.5.0.
24   */
25  class PlainMessageBuilder
26      implements MessageBuilder, LoggerLevelRenderer
27  {
28      private StringBuilder buffer;
29  
30      PlainMessageBuilder()
31      {
32          buffer = new StringBuilder();
33      }
34  
35      PlainMessageBuilder( StringBuilder builder )
36      {
37          buffer = builder;
38      }
39  
40      PlainMessageBuilder( int size )
41      {
42          buffer = new StringBuilder( size );
43      }
44  
45      public String debug( String level )
46      {
47          return a( level ).toString();
48      }
49  
50      public String info( String level )
51      {
52          return a( level ).toString();
53      }
54  
55      public String warning( String level )
56      {
57          return a( level ).toString();
58      }
59  
60      public String error( String level )
61      {
62          return a( level ).toString();
63      }
64  
65      public PlainMessageBuilder success( Object message )
66      {
67          return a( message );
68      }
69  
70      public PlainMessageBuilder warning( Object message )
71      {
72          return a( message );
73      }
74  
75      public PlainMessageBuilder failure( Object message )
76      {
77          return a( message );
78      }
79  
80      public PlainMessageBuilder strong( Object message )
81      {
82          return a( message );
83      }
84  
85      public PlainMessageBuilder mojo( Object message )
86      {
87          return a( message );
88      }
89  
90      public PlainMessageBuilder project( Object message )
91      {
92          return a( message );
93      }
94  
95      public PlainMessageBuilder a( char[] value, int offset, int len )
96      {
97          buffer.append( value, offset, len );
98          return this;
99      }
100 
101     public PlainMessageBuilder a( char[] value )
102     {
103         buffer.append( value );
104         return this;
105     }
106 
107     public PlainMessageBuilder a( CharSequence value, int start, int end )
108     {
109         buffer.append( value, start, end );
110         return this;
111     }
112 
113     public PlainMessageBuilder a( CharSequence value )
114     {
115         buffer.append( value );
116         return this;
117     }
118 
119     public PlainMessageBuilder a( Object value )
120     {
121         buffer.append( value );
122         return this;
123     }
124 
125     public PlainMessageBuilder newline()
126     {
127         buffer.append( System.getProperty( "line.separator" ) );
128         return this;
129     }
130 
131     public PlainMessageBuilder format( String pattern, Object... args )
132     {
133         buffer.append( String.format( pattern, args ) );
134         return this;
135     }
136 
137     @Override
138     public String toString()
139     {
140         return buffer.toString();
141     }
142 }