1 package org.apache.maven.model.profile;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Collections;
24 import java.util.Enumeration;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Properties;
29
30
31
32
33
34
35 public class DefaultProfileActivationContext
36 implements ProfileActivationContext
37 {
38
39 private List<String> activeProfileIds = Collections.emptyList();
40
41 private List<String> inactiveProfileIds = Collections.emptyList();
42
43 private Map<String, String> systemProperties = Collections.emptyMap();
44
45 private Map<String, String> userProperties = Collections.emptyMap();
46
47 private Map<String, String> projectProperties = Collections.emptyMap();
48
49 private File projectDirectory;
50
51 @Override
52 public List<String> getActiveProfileIds()
53 {
54 return activeProfileIds;
55 }
56
57
58
59
60
61
62
63 public DefaultProfileActivationContext setActiveProfileIds( List<String> activeProfileIds )
64 {
65 if ( activeProfileIds != null )
66 {
67 this.activeProfileIds = Collections.unmodifiableList( activeProfileIds );
68 }
69 else
70 {
71 this.activeProfileIds = Collections.emptyList();
72 }
73
74 return this;
75 }
76
77 @Override
78 public List<String> getInactiveProfileIds()
79 {
80 return inactiveProfileIds;
81 }
82
83
84
85
86
87
88
89 public DefaultProfileActivationContext setInactiveProfileIds( List<String> inactiveProfileIds )
90 {
91 if ( inactiveProfileIds != null )
92 {
93 this.inactiveProfileIds = Collections.unmodifiableList( inactiveProfileIds );
94 }
95 else
96 {
97 this.inactiveProfileIds = Collections.emptyList();
98 }
99
100 return this;
101 }
102
103 @Override
104 public Map<String, String> getSystemProperties()
105 {
106 return systemProperties;
107 }
108
109
110
111
112
113
114
115
116 @SuppressWarnings( "unchecked" )
117 public DefaultProfileActivationContext setSystemProperties( Properties systemProperties )
118 {
119 if ( systemProperties != null )
120 {
121 this.systemProperties = Collections.unmodifiableMap( (Map) systemProperties );
122 }
123 else
124 {
125 this.systemProperties = Collections.emptyMap();
126 }
127
128 return this;
129 }
130
131
132
133
134
135
136
137
138 public DefaultProfileActivationContext setSystemProperties( Map<String, String> systemProperties )
139 {
140 if ( systemProperties != null )
141 {
142 this.systemProperties = Collections.unmodifiableMap( systemProperties );
143 }
144 else
145 {
146 this.systemProperties = Collections.emptyMap();
147 }
148
149 return this;
150 }
151
152 @Override
153 public Map<String, String> getUserProperties()
154 {
155 return userProperties;
156 }
157
158
159
160
161
162
163
164
165
166 @SuppressWarnings( "unchecked" )
167 public DefaultProfileActivationContext setUserProperties( Properties userProperties )
168 {
169 if ( userProperties != null )
170 {
171 this.userProperties = Collections.unmodifiableMap( (Map) userProperties );
172 }
173 else
174 {
175 this.userProperties = Collections.emptyMap();
176 }
177
178 return this;
179 }
180
181
182
183
184
185
186
187
188
189 public DefaultProfileActivationContext setUserProperties( Map<String, String> userProperties )
190 {
191 if ( userProperties != null )
192 {
193 this.userProperties = Collections.unmodifiableMap( userProperties );
194 }
195 else
196 {
197 this.userProperties = Collections.emptyMap();
198 }
199
200 return this;
201 }
202
203 @Override
204 public File getProjectDirectory()
205 {
206 return projectDirectory;
207 }
208
209
210
211
212
213
214
215
216 public DefaultProfileActivationContext setProjectDirectory( File projectDirectory )
217 {
218 this.projectDirectory = projectDirectory;
219
220 return this;
221 }
222
223 @Override
224 public Map<String, String> getProjectProperties()
225 {
226 return projectProperties;
227 }
228
229 public DefaultProfileActivationContext setProjectProperties( Properties projectProperties )
230 {
231 if ( projectProperties != null )
232 {
233
234 this.projectProperties = Collections.unmodifiableMap( toMap( projectProperties ) );
235 }
236 else
237 {
238 this.projectProperties = Collections.emptyMap();
239 }
240
241 return this;
242 }
243
244 private Map<String, String> toMap( Properties properties )
245 {
246 if ( properties == null )
247 {
248 return Collections.emptyMap();
249 }
250 Map<String, String> map = new HashMap<String, String>();
251 Enumeration keys = properties.keys();
252 while ( keys.hasMoreElements() )
253 {
254 String key = (String) keys.nextElement();
255 map.put( key, properties.getProperty( key ) );
256 }
257 return map;
258 }
259 }