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