View Javadoc
1   package org.apache.maven.plugins.assembly.internal;
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.slf4j.Logger;
26  
27  /**
28   * Copy of deprecated {@link org.apache.maven.plugin.DebugConfigurationListener} updated to Slf4j.
29   */
30  public class DebugConfigurationListener
31          implements ConfigurationListener
32  {
33      private final Logger logger;
34  
35      public DebugConfigurationListener( Logger logger )
36      {
37          this.logger = logger;
38      }
39  
40      @Override
41      public void notifyFieldChangeUsingSetter( String fieldName, Object value, Object target )
42      {
43          if ( logger.isDebugEnabled() )
44          {
45              logger.debug( "  (s) " + fieldName + " = " + toString( value ) );
46          }
47      }
48  
49      @Override
50      public void notifyFieldChangeUsingReflection( String fieldName, Object value, Object target )
51      {
52          if ( logger.isDebugEnabled() )
53          {
54              logger.debug( "  (f) " + fieldName + " = " + toString( value ) );
55          }
56      }
57  
58      /**
59       * Creates a human-friendly string representation of the specified object.
60       *
61       * @param obj The object to create a string representation for, may be <code>null</code>.
62       * @return The string representation, never <code>null</code>.
63       */
64      private String toString( Object obj )
65      {
66          String str;
67          if ( obj != null && obj.getClass().isArray() )
68          {
69              int n = Array.getLength( obj );
70              StringBuilder buf = new StringBuilder( 256 );
71              buf.append( '[' );
72              for ( int i = 0; i < n; i++ )
73              {
74                  if ( i > 0 )
75                  {
76                      buf.append( ", " );
77                  }
78                  buf.append( Array.get( obj, i ) );
79              }
80              buf.append( ']' );
81              str = buf.toString();
82          }
83          else
84          {
85              str = String.valueOf( obj );
86          }
87          return str;
88      }
89  
90  }