1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.internal.impl.model;
20
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Properties;
25 import java.util.stream.Collectors;
26
27 import org.apache.maven.api.model.Model;
28 import org.apache.maven.api.services.model.ProfileActivationContext;
29
30
31
32
33
34 public class DefaultProfileActivationContext implements ProfileActivationContext {
35
36 private List<String> activeProfileIds = Collections.emptyList();
37
38 private List<String> inactiveProfileIds = Collections.emptyList();
39
40 private Map<String, String> systemProperties = Collections.emptyMap();
41
42 private Map<String, String> userProperties = Collections.emptyMap();
43
44 private Model model;
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 Model getModel() {
140 return model;
141 }
142
143 public DefaultProfileActivationContext setModel(Model model) {
144 this.model = model;
145
146 return this;
147 }
148
149 private static List<String> unmodifiable(List<String> list) {
150 return list != null ? Collections.unmodifiableList(list) : Collections.emptyList();
151 }
152
153 private static Map<String, String> unmodifiable(Map<String, String> map) {
154 return map != null ? Collections.unmodifiableMap(map) : Collections.emptyMap();
155 }
156
157 private static Map<String, String> toMap(Properties properties) {
158 if (properties != null && !properties.isEmpty()) {
159 return properties.entrySet().stream()
160 .collect(Collectors.toMap(e -> String.valueOf(e.getKey()), e -> String.valueOf(e.getValue())));
161
162 } else {
163 return null;
164 }
165 }
166 }