Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
DebugConfigurationListener |
|
| 2.25;2,25 |
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 | * @version $Id: DebugConfigurationListener.java 720043 2008-11-23 21:15:31Z bentmann $ | |
32 | */ | |
33 | public class DebugConfigurationListener | |
34 | implements ConfigurationListener | |
35 | { | |
36 | private Logger logger; | |
37 | ||
38 | public DebugConfigurationListener( Logger logger ) | |
39 | 0 | { |
40 | 0 | this.logger = logger; |
41 | 0 | } |
42 | ||
43 | public void notifyFieldChangeUsingSetter( String fieldName, Object value, Object target ) | |
44 | { | |
45 | 0 | if ( logger.isDebugEnabled() ) |
46 | { | |
47 | 0 | logger.debug( " (s) " + fieldName + " = " + toString( value ) ); |
48 | } | |
49 | 0 | } |
50 | ||
51 | public void notifyFieldChangeUsingReflection( String fieldName, Object value, Object target ) | |
52 | { | |
53 | 0 | if ( logger.isDebugEnabled() ) |
54 | { | |
55 | 0 | logger.debug( " (f) " + fieldName + " = " + toString( value ) ); |
56 | } | |
57 | 0 | } |
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 | 0 | if ( obj != null && obj.getClass().isArray() ) |
69 | { | |
70 | 0 | int n = Array.getLength( obj ); |
71 | 0 | StringBuffer buf = new StringBuffer( 256 ); |
72 | 0 | buf.append( '[' ); |
73 | 0 | for ( int i = 0; i < n; i++ ) |
74 | { | |
75 | 0 | if ( i > 0 ) |
76 | { | |
77 | 0 | buf.append( ", " ); |
78 | } | |
79 | 0 | buf.append( String.valueOf( Array.get( obj, i ) ) ); |
80 | } | |
81 | 0 | buf.append( ']' ); |
82 | 0 | str = buf.toString(); |
83 | } | |
84 | else | |
85 | { | |
86 | 0 | str = String.valueOf( obj ); |
87 | } | |
88 | 0 | return str; |
89 | } | |
90 | ||
91 | } |