View Javadoc

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.Map;
24  import java.util.Properties;
25  import java.util.Set;
26  
27  import org.apache.maven.project.MavenProject;
28  import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
29  
30  /**
31   * @author <a href="mailto:olamy@apache.org">olamy</a>
32   * @since 22 nov. 07
33   * @version $Id: CompositeMap.java 655038 2008-05-10 10:12:02Z bentmann $
34   */
35  class CompositeMap
36      implements Map
37  {
38  
39      private MavenProject mavenProject;
40  
41      private Properties properties;
42  
43      protected CompositeMap( MavenProject mavenProject, Properties properties )
44      {
45          this.mavenProject = mavenProject;
46          this.properties = properties == null ? new Properties() : properties;
47      }
48  
49      /**
50       * @see java.util.Map#clear()
51       */
52      public void clear()
53      {
54          // nothing here
55  
56      }
57  
58      /**
59       * @see java.util.Map#containsKey(java.lang.Object)
60       */
61      public boolean containsKey( Object key )
62      {
63          if ( key == null )
64          {
65              return false;
66          }
67          try
68          {
69              Object evaluated = ReflectionValueExtractor.evaluate( (String) key, this.mavenProject );
70              return evaluated == null;
71          }
72          catch ( Exception e )
73          {
74              // uhm do we have to throw a RuntimeException here ?
75          }
76  
77          return ( mavenProject.getProperties().containsKey( key ) || properties.containsKey( key ) );
78      }
79  
80      /**
81       * @see java.util.Map#containsValue(java.lang.Object)
82       */
83      public boolean containsValue( Object value )
84      {
85          throw new UnsupportedOperationException();
86      }
87  
88      /**
89       * @see java.util.Map#entrySet()
90       */
91      public Set entrySet()
92      {
93          throw new UnsupportedOperationException();
94      }
95  
96      /**
97       * @see java.util.Map#get(java.lang.Object)
98       */
99      public Object get( Object key )
100     {
101         if ( key == null )
102         {
103             return null;
104         }
105         try
106         {
107             Object evaluated = ReflectionValueExtractor.evaluate( (String) key, this.mavenProject );
108             if ( evaluated != null )
109             {
110                 return evaluated;
111             }
112         }
113         catch ( Exception e )
114         {
115             // uhm do we have to throw a RuntimeException here ?
116         }
117 
118         Object value = properties.get( key );
119 
120         return ( value != null ? value : this.mavenProject.getProperties().get( key ) );
121 
122     }
123 
124     /**
125      * @see java.util.Map#isEmpty()
126      */
127     public boolean isEmpty()
128     {
129         return this.mavenProject == null && this.mavenProject.getProperties().isEmpty() && this.properties.isEmpty();
130     }
131 
132     /**
133      * @see java.util.Map#keySet()
134      */
135     public Set keySet()
136     {
137         throw new UnsupportedOperationException();
138     }
139 
140     /**
141      * @see java.util.Map#put(java.lang.Object, java.lang.Object)
142      */
143     public Object put( Object key, Object value )
144     {
145         throw new UnsupportedOperationException();
146     }
147 
148     /**
149      * @see java.util.Map#putAll(java.util.Map)
150      */
151     public void putAll( Map t )
152     {
153         throw new UnsupportedOperationException();
154     }
155 
156     /**
157      * @see java.util.Map#remove(java.lang.Object)
158      */
159     public Object remove( Object key )
160     {
161         throw new UnsupportedOperationException();
162     }
163 
164     /**
165      * @see java.util.Map#size()
166      */
167     public int size()
168     {
169         throw new UnsupportedOperationException();
170     }
171 
172     /**
173      * @see java.util.Map#values()
174      */
175     public Collection values()
176     {
177         throw new UnsupportedOperationException();
178     }
179 }