1 package org.apache.maven.plugins.invoker;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
32
33
34
35
36
37 class CompositeMap
38 implements Map<String, Object>
39 {
40
41
42
43
44 private MavenProject mavenProject;
45
46
47
48
49 private Map<String, Object> properties;
50
51
52
53
54 private final boolean escapeXml;
55
56
57
58
59
60
61
62
63
64 protected CompositeMap( MavenProject mavenProject, Map<String, Object> properties, boolean escapeXml )
65 {
66 if ( mavenProject == null )
67 {
68 throw new IllegalArgumentException( "no project specified" );
69 }
70 this.mavenProject = mavenProject;
71 this.properties = properties == null ? new HashMap<String, Object>() : properties;
72 this.escapeXml = escapeXml;
73 }
74
75
76
77
78
79
80 public void clear()
81 {
82
83 }
84
85
86
87
88
89
90 public boolean containsKey( Object key )
91 {
92 if ( !( key instanceof String ) )
93 {
94 return false;
95 }
96
97 String expression = (String) key;
98 if ( expression.startsWith( "project." ) || expression.startsWith( "pom." ) )
99 {
100 try
101 {
102 Object evaluated = ReflectionValueExtractor.evaluate( expression, this.mavenProject );
103 if ( evaluated != null )
104 {
105 return true;
106 }
107 }
108 catch ( Exception e )
109 {
110
111 }
112 }
113
114 return properties.containsKey( key ) || mavenProject.getProperties().containsKey( key );
115 }
116
117
118
119
120
121
122 public boolean containsValue( Object value )
123 {
124 throw new UnsupportedOperationException();
125 }
126
127
128
129
130
131
132 public Set<Entry<String, Object>> entrySet()
133 {
134 throw new UnsupportedOperationException();
135 }
136
137
138
139
140
141
142 public Object get( Object key )
143 {
144 if ( !( key instanceof String ) )
145 {
146 return null;
147 }
148
149 Object value = null;
150 String expression = (String) key;
151 if ( expression.startsWith( "project." ) || expression.startsWith( "pom." ) )
152 {
153 try
154 {
155 Object evaluated = ReflectionValueExtractor.evaluate( expression, this.mavenProject );
156 if ( evaluated != null )
157 {
158 value = evaluated;
159 }
160 }
161 catch ( Exception e )
162 {
163
164 }
165 }
166
167 if ( value == null )
168 {
169 value = properties.get( key );
170 }
171
172 if ( value == null )
173 {
174 value = this.mavenProject.getProperties().get( key );
175 }
176
177 if ( value != null && this.escapeXml )
178 {
179 value = value.toString().
180 replaceAll( "\"", """ ).
181 replaceAll( "<", "<" ).
182 replaceAll( ">", ">" ).
183 replaceAll( "&", "&" );
184
185 }
186
187 return value;
188 }
189
190
191
192
193
194
195 public boolean isEmpty()
196 {
197 return this.mavenProject.getProperties().isEmpty() && this.properties.isEmpty();
198 }
199
200
201
202
203
204
205 public Set<String> keySet()
206 {
207 throw new UnsupportedOperationException();
208 }
209
210
211
212
213
214
215 public Object put( String key, Object value )
216 {
217 throw new UnsupportedOperationException();
218 }
219
220
221
222
223
224
225 public void putAll( Map<? extends String, ? extends Object> t )
226 {
227 throw new UnsupportedOperationException();
228 }
229
230
231
232
233
234
235 public Object remove( Object key )
236 {
237 throw new UnsupportedOperationException();
238 }
239
240
241
242
243
244
245 public int size()
246 {
247 throw new UnsupportedOperationException();
248 }
249
250
251
252
253
254
255 public Collection<Object> values()
256 {
257 throw new UnsupportedOperationException();
258 }
259 }