Coverage Report - org.apache.maven.plugin.invoker.CompositeMap
 
Classes in this File Line Coverage Branch Coverage Complexity
CompositeMap
34%
13/38
28%
9/32
3,231
 
 1  
 package org.apache.maven.plugin.invoker;
 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.util.Collection;
 23  
 import java.util.HashMap;
 24  
 import java.util.Map;
 25  
 import java.util.Set;
 26  
 
 27  
 import org.apache.maven.project.MavenProject;
 28  
 import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
 29  
 
 30  
 /**
 31  
  * A map-like source to interpolate expressions.
 32  
  * 
 33  
  * @author Olivier Lamy
 34  
  * @since 1.1
 35  
  * @version $Id: CompositeMap.java 1412649 2012-11-22 19:47:02Z rfscholte $
 36  
  */
 37  0
 class CompositeMap
 38  
     implements Map<String, Object>
 39  
 {
 40  
 
 41  
     /**
 42  
      * The Maven project from which to extract interpolated values, never <code>null</code>.
 43  
      */
 44  
     private MavenProject mavenProject;
 45  
 
 46  
     /**
 47  
      * The set of additional properties from which to extract interpolated values, never <code>null</code>.
 48  
      */
 49  
     private Map<String, Object> properties;
 50  
 
 51  
     /**
 52  
      * Creates a new interpolation source backed by the specified Maven project and some user-specified properties.
 53  
      * 
 54  
      * @param mavenProject The Maven project from which to extract interpolated values, must not be <code>null</code>.
 55  
      * @param properties The set of additional properties from which to extract interpolated values, may be
 56  
      *            <code>null</code>.
 57  
      */
 58  
     protected CompositeMap( MavenProject mavenProject, Map<String, Object> properties )
 59  14
     {
 60  14
         if ( mavenProject == null )
 61  
         {
 62  0
             throw new IllegalArgumentException( "no project specified" );
 63  
         }
 64  14
         this.mavenProject = mavenProject;
 65  14
         this.properties = properties == null ? new HashMap<String, Object>() : properties;
 66  14
     }
 67  
 
 68  
     /**
 69  
      * {@inheritDoc}
 70  
      * 
 71  
      * @see java.util.Map#clear()
 72  
      */
 73  
     public void clear()
 74  
     {
 75  
         // nothing here
 76  0
     }
 77  
 
 78  
     /**
 79  
      * {@inheritDoc}
 80  
      * 
 81  
      * @see java.util.Map#containsKey(java.lang.Object)
 82  
      */
 83  
     public boolean containsKey( Object key )
 84  
     {
 85  0
         if ( !( key instanceof String ) )
 86  
         {
 87  0
             return false;
 88  
         }
 89  
 
 90  0
         String expression = (String) key;
 91  0
         if ( expression.startsWith( "project." ) || expression.startsWith( "pom." ) )
 92  
         {
 93  
             try
 94  
             {
 95  0
                 Object evaluated = ReflectionValueExtractor.evaluate( expression, this.mavenProject );
 96  0
                 if ( evaluated != null )
 97  
                 {
 98  0
                     return true;
 99  
                 }
 100  
             }
 101  0
             catch ( Exception e )
 102  
             {
 103  
                 // uhm do we have to throw a RuntimeException here ?
 104  0
             }
 105  
         }
 106  
 
 107  0
         return properties.containsKey( key ) || mavenProject.getProperties().containsKey( key );
 108  
     }
 109  
 
 110  
     /**
 111  
      * {@inheritDoc}
 112  
      * 
 113  
      * @see java.util.Map#containsValue(java.lang.Object)
 114  
      */
 115  
     public boolean containsValue( Object value )
 116  
     {
 117  0
         throw new UnsupportedOperationException();
 118  
     }
 119  
 
 120  
     /**
 121  
      * {@inheritDoc}
 122  
      * 
 123  
      * @see java.util.Map#entrySet()
 124  
      */
 125  
     public Set<Entry<String, Object>> entrySet()
 126  
     {
 127  0
         throw new UnsupportedOperationException();
 128  
     }
 129  
 
 130  
     /**
 131  
      * {@inheritDoc}
 132  
      * 
 133  
      * @see java.util.Map#get(java.lang.Object)
 134  
      */
 135  
     public Object get( Object key )
 136  
     {
 137  22
         if ( !( key instanceof String ) )
 138  
         {
 139  0
             return null;
 140  
         }
 141  
 
 142  22
         String expression = (String) key;
 143  22
         if ( expression.startsWith( "project." ) || expression.startsWith( "pom." ) )
 144  
         {
 145  
             try
 146  
             {
 147  12
                 Object evaluated = ReflectionValueExtractor.evaluate( expression, this.mavenProject );
 148  12
                 if ( evaluated != null )
 149  
                 {
 150  12
                     return evaluated;
 151  
                 }
 152  
             }
 153  0
             catch ( Exception e )
 154  
             {
 155  
                 // uhm do we have to throw a RuntimeException here ?
 156  0
             }
 157  
         }
 158  
 
 159  10
         Object value = properties.get( key );
 160  
 
 161  10
         return ( value != null ? value : this.mavenProject.getProperties().get( key ) );
 162  
 
 163  
     }
 164  
 
 165  
     /**
 166  
      * {@inheritDoc}
 167  
      * 
 168  
      * @see java.util.Map#isEmpty()
 169  
      */
 170  
     public boolean isEmpty()
 171  
     {
 172  0
         return this.mavenProject == null && this.mavenProject.getProperties().isEmpty() && this.properties.isEmpty();
 173  
     }
 174  
 
 175  
     /**
 176  
      * {@inheritDoc}
 177  
      * 
 178  
      * @see java.util.Map#keySet()
 179  
      */
 180  
     public Set<String> keySet()
 181  
     {
 182  0
         throw new UnsupportedOperationException();
 183  
     }
 184  
 
 185  
     /**
 186  
      * {@inheritDoc}
 187  
      * 
 188  
      * @see java.util.Map#put(java.lang.Object, java.lang.Object)
 189  
      */
 190  
     public Object put( String key, Object value )
 191  
     {
 192  0
         throw new UnsupportedOperationException();
 193  
     }
 194  
 
 195  
     /**
 196  
      * {@inheritDoc}
 197  
      * 
 198  
      * @see java.util.Map#putAll(java.util.Map)
 199  
      */
 200  
     public void putAll( Map<? extends String, ? extends Object> t )
 201  
     {
 202  0
         throw new UnsupportedOperationException();
 203  
     }
 204  
 
 205  
     /**
 206  
      * {@inheritDoc}
 207  
      * 
 208  
      * @see java.util.Map#remove(java.lang.Object)
 209  
      */
 210  
     public Object remove( Object key )
 211  
     {
 212  0
         throw new UnsupportedOperationException();
 213  
     }
 214  
 
 215  
     /**
 216  
      * {@inheritDoc}
 217  
      * 
 218  
      * @see java.util.Map#size()
 219  
      */
 220  
     public int size()
 221  
     {
 222  0
         throw new UnsupportedOperationException();
 223  
     }
 224  
 
 225  
     /**
 226  
      * {@inheritDoc}
 227  
      * 
 228  
      * @see java.util.Map#values()
 229  
      */
 230  
     public Collection<Object> values()
 231  
     {
 232  0
         throw new UnsupportedOperationException();
 233  
     }
 234  
 }