1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.model.profile;
20
21 import java.io.File;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.Properties;
26
27 import static java.util.stream.Collectors.collectingAndThen;
28 import static java.util.stream.Collectors.toMap;
29
30
31
32
33
34
35 public class DefaultProfileActivationContext implements ProfileActivationContext {
36
37 private List<String> activeProfileIds = Collections.emptyList();
38
39 private List<String> inactiveProfileIds = Collections.emptyList();
40
41 private Map<String, String> systemProperties = Collections.emptyMap();
42
43 private Map<String, String> userProperties = Collections.emptyMap();
44
45 private Map<String, String> projectProperties = Collections.emptyMap();
46
47 private File projectDirectory;
48
49 @Override
50 public List<String> getActiveProfileIds() {
51 return activeProfileIds;
52 }
53
54
55
56
57
58
59
60 public DefaultProfileActivationContext setActiveProfileIds(List<String> activeProfileIds) {
61 if (activeProfileIds != null) {
62 this.activeProfileIds = Collections.unmodifiableList(activeProfileIds);
63 } else {
64 this.activeProfileIds = Collections.emptyList();
65 }
66
67 return this;
68 }
69
70 @Override
71 public List<String> getInactiveProfileIds() {
72 return inactiveProfileIds;
73 }
74
75
76
77
78
79
80
81 public DefaultProfileActivationContext setInactiveProfileIds(List<String> inactiveProfileIds) {
82 if (inactiveProfileIds != null) {
83 this.inactiveProfileIds = Collections.unmodifiableList(inactiveProfileIds);
84 } else {
85 this.inactiveProfileIds = Collections.emptyList();
86 }
87
88 return this;
89 }
90
91 @Override
92 public Map<String, String> getSystemProperties() {
93 return systemProperties;
94 }
95
96
97
98
99
100
101
102
103 @SuppressWarnings("unchecked")
104 public DefaultProfileActivationContext setSystemProperties(Properties systemProperties) {
105 if (systemProperties != null) {
106 this.systemProperties = Collections.unmodifiableMap((Map) systemProperties);
107 } else {
108 this.systemProperties = Collections.emptyMap();
109 }
110
111 return this;
112 }
113
114
115
116
117
118
119
120
121 public DefaultProfileActivationContext setSystemProperties(Map<String, String> systemProperties) {
122 if (systemProperties != null) {
123 this.systemProperties = Collections.unmodifiableMap(systemProperties);
124 } else {
125 this.systemProperties = Collections.emptyMap();
126 }
127
128 return this;
129 }
130
131 @Override
132 public Map<String, String> getUserProperties() {
133 return userProperties;
134 }
135
136
137
138
139
140
141
142
143
144 @SuppressWarnings("unchecked")
145 public DefaultProfileActivationContext setUserProperties(Properties userProperties) {
146 if (userProperties != null) {
147 this.userProperties = Collections.unmodifiableMap((Map) userProperties);
148 } else {
149 this.userProperties = Collections.emptyMap();
150 }
151
152 return this;
153 }
154
155
156
157
158
159
160
161
162
163 public DefaultProfileActivationContext setUserProperties(Map<String, String> userProperties) {
164 if (userProperties != null) {
165 this.userProperties = Collections.unmodifiableMap(userProperties);
166 } else {
167 this.userProperties = Collections.emptyMap();
168 }
169
170 return this;
171 }
172
173 @Override
174 public File getProjectDirectory() {
175 return projectDirectory;
176 }
177
178
179
180
181
182
183
184
185 public DefaultProfileActivationContext setProjectDirectory(File projectDirectory) {
186 this.projectDirectory = projectDirectory;
187
188 return this;
189 }
190
191 @Override
192 public Map<String, String> getProjectProperties() {
193 return projectProperties;
194 }
195
196 public DefaultProfileActivationContext setProjectProperties(Properties projectProperties) {
197 if (projectProperties != null) {
198 this.projectProperties = projectProperties.entrySet().stream()
199 .collect(collectingAndThen(
200 toMap(e -> String.valueOf(e.getKey()), e -> String.valueOf(e.getValue())),
201 Collections::unmodifiableMap));
202 } else {
203 this.projectProperties = Collections.emptyMap();
204 }
205
206 return this;
207 }
208 }