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