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 static java.util.stream.Collectors.toMap;
22
23 import java.io.File;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Properties;
28 import java.util.stream.Collectors;
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 this.activeProfileIds = unmodifiable(activeProfileIds);
62 return this;
63 }
64
65 @Override
66 public List<String> getInactiveProfileIds() {
67 return inactiveProfileIds;
68 }
69
70
71
72
73
74
75
76 public DefaultProfileActivationContext setInactiveProfileIds(List<String> inactiveProfileIds) {
77 this.inactiveProfileIds = unmodifiable(inactiveProfileIds);
78 return this;
79 }
80
81 @Override
82 public Map<String, String> getSystemProperties() {
83 return systemProperties;
84 }
85
86
87
88
89
90
91
92
93 @SuppressWarnings("unchecked")
94 public DefaultProfileActivationContext setSystemProperties(Properties systemProperties) {
95 return setSystemProperties(toMap(systemProperties));
96 }
97
98
99
100
101
102
103
104
105 public DefaultProfileActivationContext setSystemProperties(Map<String, String> systemProperties) {
106 this.systemProperties = unmodifiable(systemProperties);
107 return this;
108 }
109
110 @Override
111 public Map<String, String> getUserProperties() {
112 return userProperties;
113 }
114
115
116
117
118
119
120
121
122
123 @SuppressWarnings("unchecked")
124 public DefaultProfileActivationContext setUserProperties(Properties userProperties) {
125 return setUserProperties(toMap(userProperties));
126 }
127
128
129
130
131
132
133
134
135
136 public DefaultProfileActivationContext setUserProperties(Map<String, String> userProperties) {
137 this.userProperties = unmodifiable(userProperties);
138 return this;
139 }
140
141 @Override
142 public File getProjectDirectory() {
143 return projectDirectory;
144 }
145
146
147
148
149
150
151
152
153 public DefaultProfileActivationContext setProjectDirectory(File projectDirectory) {
154 this.projectDirectory = projectDirectory;
155
156 return this;
157 }
158
159 @Override
160 public Map<String, String> getProjectProperties() {
161 return projectProperties;
162 }
163
164 public DefaultProfileActivationContext setProjectProperties(Properties projectProperties) {
165 return setProjectProperties(toMap(projectProperties));
166 }
167
168 public DefaultProfileActivationContext setProjectProperties(Map<String, String> projectProperties) {
169 this.projectProperties = unmodifiable(projectProperties);
170
171 return this;
172 }
173
174 private static List<String> unmodifiable(List<String> list) {
175 return list != null ? Collections.unmodifiableList(list) : Collections.emptyList();
176 }
177
178 private static Map<String, String> unmodifiable(Map<String, String> map) {
179 return map != null ? Collections.unmodifiableMap(map) : Collections.emptyMap();
180 }
181
182 private static Map<String, String> toMap(Properties properties) {
183 if (properties != null && !properties.isEmpty()) {
184 return properties.entrySet().stream()
185 .collect(Collectors.toMap(e -> String.valueOf(e.getKey()), e -> String.valueOf(e.getValue())));
186
187 } else {
188 return null;
189 }
190 }
191 }