View Javadoc

1   package org.apache.maven.plugin;
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  import java.lang.reflect.Array;
23  
24  import org.codehaus.plexus.component.configurator.ConfigurationListener;
25  import org.codehaus.plexus.logging.Logger;
26  
27  /**
28   * Log at debug level the mojo configuration.
29   *
30   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
31   */
32  @Deprecated
33  public class DebugConfigurationListener
34      implements ConfigurationListener
35  {
36      private Logger logger;
37  
38      public DebugConfigurationListener( Logger logger )
39      {
40          this.logger = logger;
41      }
42  
43      public void notifyFieldChangeUsingSetter( String fieldName, Object value, Object target )
44      {
45          if ( logger.isDebugEnabled() )
46          {
47              logger.debug( "  (s) " + fieldName + " = " + toString( value ) );
48          }
49      }
50  
51      public void notifyFieldChangeUsingReflection( String fieldName, Object value, Object target )
52      {
53          if ( logger.isDebugEnabled() )
54          {
55              logger.debug( "  (f) " + fieldName + " = " + toString( value ) );
56          }
57      }
58  
59      /**
60       * Creates a human-friendly string represenation of the specified object.
61       * 
62       * @param obj The object to create a string representation for, may be <code>null</code>.
63       * @return The string representation, never <code>null</code>.
64       */
65      private String toString( Object obj )
66      {
67          String str;
68          if ( obj != null && obj.getClass().isArray() )
69          {
70              int n = Array.getLength( obj );
71              StringBuilder buf = new StringBuilder( 256 );
72              buf.append( '[' );
73              for ( int i = 0; i < n; i++ )
74              {
75                  if ( i > 0 )
76                  {
77                      buf.append( ", " );
78                  }
79                  buf.append( String.valueOf( Array.get( obj, i ) ) );
80              }
81              buf.append( ']' );
82              str = buf.toString();
83          }
84          else
85          {
86              str = String.valueOf( obj );
87          }
88          return str;
89      }
90  
91  }