001package org.apache.maven.plugin;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *  http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.lang.reflect.Array;
023
024import org.codehaus.plexus.component.configurator.ConfigurationListener;
025import org.codehaus.plexus.logging.Logger;
026
027/**
028 * Log at debug level the mojo configuration.
029 *
030 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
031 */
032@Deprecated
033public class DebugConfigurationListener
034    implements ConfigurationListener
035{
036    private Logger logger;
037
038    public DebugConfigurationListener( Logger logger )
039    {
040        this.logger = logger;
041    }
042
043    public void notifyFieldChangeUsingSetter( String fieldName, Object value, Object target )
044    {
045        if ( logger.isDebugEnabled() )
046        {
047            logger.debug( "  (s) " + fieldName + " = " + toString( value ) );
048        }
049    }
050
051    public void notifyFieldChangeUsingReflection( String fieldName, Object value, Object target )
052    {
053        if ( logger.isDebugEnabled() )
054        {
055            logger.debug( "  (f) " + fieldName + " = " + toString( value ) );
056        }
057    }
058
059    /**
060     * Creates a human-friendly string represenation of the specified object.
061     *
062     * @param obj The object to create a string representation for, may be <code>null</code>.
063     * @return The string representation, never <code>null</code>.
064     */
065    private String toString( Object obj )
066    {
067        String str;
068        if ( obj != null && obj.getClass().isArray() )
069        {
070            int n = Array.getLength( obj );
071            StringBuilder buf = new StringBuilder( 256 );
072            buf.append( '[' );
073            for ( int i = 0; i < n; i++ )
074            {
075                if ( i > 0 )
076                {
077                    buf.append( ", " );
078                }
079                buf.append( String.valueOf( Array.get( obj, i ) ) );
080            }
081            buf.append( ']' );
082            str = buf.toString();
083        }
084        else
085        {
086            str = String.valueOf( obj );
087        }
088        return str;
089    }
090
091}