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