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