Coverage Report - org.codehaus.plexus.component.configurator.converters.basic.FileConverter
 
Classes in this File Line Coverage Branch Coverage Complexity
FileConverter
87 %
7/8
50 %
1/2
1,667
 
 1  
 package org.codehaus.plexus.component.configurator.converters.basic;
 2  
 
 3  
 /*
 4  
  * The MIT License
 5  
  *
 6  
  * Copyright (c) 2004, The Codehaus
 7  
  *
 8  
  * Permission is hereby granted, free of charge, to any person obtaining a copy of
 9  
  * this software and associated documentation files (the "Software"), to deal in
 10  
  * the Software without restriction, including without limitation the rights to
 11  
  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 12  
  * of the Software, and to permit persons to whom the Software is furnished to do
 13  
  * so, subject to the following conditions:
 14  
  *
 15  
  * The above copyright notice and this permission notice shall be included in all
 16  
  * copies or substantial portions of the Software.
 17  
  *
 18  
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 19  
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 20  
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 21  
  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 22  
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 23  
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 24  
  * SOFTWARE.
 25  
  */
 26  
 
 27  
 import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
 28  
 import org.codehaus.plexus.component.configurator.ConfigurationListener;
 29  
 import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
 30  
 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
 31  
 import org.codehaus.plexus.configuration.PlexusConfiguration;
 32  
 
 33  
 import java.io.File;
 34  
 
 35  
 /**
 36  
  * @author <a href="mailto:brett@codehaus.org">Brett Porter</a>
 37  
  */
 38  67
 public class FileConverter
 39  
     extends AbstractBasicConverter
 40  
 {
 41  
     public boolean canConvert( Class type )
 42  
     {
 43  92
         return type.equals( File.class );
 44  
     }
 45  
 
 46  
     public Object fromString( String str )
 47  
     {
 48  9
         str = str.replace( '\\', File.separatorChar ).replace( '/', File.separatorChar );
 49  9
         return new File( str );
 50  
     }
 51  
 
 52  
     public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type,
 53  
                                      Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator,
 54  
                                      ConfigurationListener listener )
 55  
         throws ComponentConfigurationException
 56  
     {
 57  9
         File f = (File) super.fromConfiguration( converterLookup, configuration, type, baseType, classLoader,
 58  
                                                  expressionEvaluator, listener );
 59  
 
 60  9
         if ( f != null )
 61  
         {
 62  
             // Hmmm... is this cheating? Can't think of a better way right now
 63  9
             return expressionEvaluator.alignToBaseDirectory( f );
 64  
         }
 65  
         else
 66  
         {
 67  0
             return null;
 68  
         }
 69  
     }
 70  
 }