Coverage Report - org.codehaus.plexus.util.interpolation.EnvarBasedValueSource
 
Classes in this File Line Coverage Branch Coverage Complexity
EnvarBasedValueSource
0%
0/12
0%
0/4
1,667
 
 1  
 package org.codehaus.plexus.util.interpolation;
 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.util.cli.CommandLineUtils;
 23  
 
 24  
 import java.io.IOException;
 25  
 import java.util.Properties;
 26  
 
 27  
 public class EnvarBasedValueSource
 28  
     implements ValueSource
 29  
 {
 30  
     
 31  
     private Properties envars;
 32  
     private final boolean caseSensitive;
 33  
 
 34  
     /**
 35  
      * Create a new value source for interpolation based on shell environment variables. In this
 36  
      * case, envar keys ARE CASE SENSITIVE.
 37  
      * 
 38  
      * @throws IOException
 39  
      */
 40  
     public EnvarBasedValueSource() throws IOException
 41  
     {
 42  0
         this( true );
 43  0
     }
 44  
 
 45  
     /**
 46  
      * Create a new value source for interpolation based on shell environment variables.
 47  
      * 
 48  
      * @param caseSensitive Whether the environment variable key should be treated in a 
 49  
      *                      case-sensitive manner for lookups
 50  
      * @throws IOException
 51  
      */
 52  
     public EnvarBasedValueSource( boolean caseSensitive ) throws IOException
 53  0
     {
 54  0
         this.caseSensitive = caseSensitive;
 55  
         
 56  0
         envars = CommandLineUtils.getSystemEnvVars( caseSensitive );
 57  0
     }
 58  
 
 59  
     public Object getValue( String expression )
 60  
     {
 61  0
         String expr = expression;
 62  
         
 63  0
         if ( expr.startsWith( "env." ) )
 64  
         {
 65  0
             expr = expr.substring( "env.".length() );
 66  
         }
 67  
         
 68  0
         if ( !caseSensitive )
 69  
         {
 70  0
             expr = expr.toUpperCase();
 71  
         }
 72  
         
 73  0
         return envars.getProperty( expr );
 74  
     }
 75  
 }