Coverage Report - org.apache.maven.plugin.assembly.utils.PrefixedObjectBasedValueSource
 
Classes in this File Line Coverage Branch Coverage Complexity
PrefixedObjectBasedValueSource
59%
13/22
40%
4/10
2.667
 
 1  
 package org.apache.maven.plugin.assembly.utils;
 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 org.codehaus.plexus.logging.Logger;
 23  
 import org.codehaus.plexus.util.interpolation.ValueSource;
 24  
 import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
 25  
 
 26  
 /**
 27  
  * @version $Id: PrefixedObjectBasedValueSource.java 610981 2008-01-10 23:10:00Z vsiveton $
 28  
  */
 29  
 public class PrefixedObjectBasedValueSource
 30  
     implements ValueSource
 31  
 {
 32  
 
 33  
     private String prefix;
 34  
     private final Object root;
 35  
     private final Logger logger;
 36  
 
 37  
     public PrefixedObjectBasedValueSource( String prefix, Object root )
 38  337
     {
 39  337
         this.prefix = prefix;
 40  337
         this.root = root;
 41  337
         logger = null;
 42  337
     }
 43  
 
 44  
     public PrefixedObjectBasedValueSource( String prefix, Object root, Logger logger )
 45  0
     {
 46  0
         this.prefix = prefix;
 47  0
         this.root = root;
 48  0
         this.logger = logger;
 49  0
     }
 50  
 
 51  
     public Object getValue( String expression )
 52  
     {
 53  129
         if ( ( expression == null ) || !expression.startsWith( prefix ) )
 54  
         {
 55  81
             return null;
 56  
         }
 57  
 
 58  48
         String realExpr = expression.substring( prefix.length() );
 59  48
         if ( realExpr.startsWith( "." ) )
 60  
         {
 61  0
             realExpr = realExpr.substring( 1 );
 62  
         }
 63  
 
 64  48
         Object value = null;
 65  
         try
 66  
         {
 67  48
             value = ReflectionValueExtractor.evaluate( realExpr, root, false );
 68  
         }
 69  0
         catch ( Exception e )
 70  
         {
 71  0
             if ( ( logger != null ) && logger.isDebugEnabled() )
 72  
             {
 73  0
                 logger.debug( "Failed to extract \'" + realExpr + "\' from: " + root + " (full expression was: \'" + expression + "\').", e );
 74  
             }
 75  48
         }
 76  
 
 77  48
         return value;
 78  
     }
 79  
 
 80  
 }