1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.execution;
20
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Set;
27 import java.util.function.Predicate;
28
29 import static java.util.stream.Collectors.toSet;
30
31
32
33
34
35 public class ProfileActivation {
36 private final Map<String, ActivationSettings> activations = new HashMap<>();
37
38
39
40
41
42 @Deprecated
43 public List<String> getActiveProfiles() {
44 return Collections.unmodifiableList(new ArrayList<>(getProfileIds(pa -> pa.active)));
45 }
46
47
48
49
50
51 @Deprecated
52 public List<String> getInactiveProfiles() {
53 return Collections.unmodifiableList(new ArrayList<>(getProfileIds(pa -> !pa.active)));
54 }
55
56
57
58
59
60
61 @Deprecated
62 public void overwriteActiveProfiles(List<String> activeProfileIds) {
63 getActiveProfiles().forEach(this.activations::remove);
64 activeProfileIds.forEach(this::activateOptionalProfile);
65 }
66
67
68
69
70
71
72 @Deprecated
73 public void overwriteInactiveProfiles(List<String> inactiveProfileIds) {
74 getInactiveProfiles().forEach(this.activations::remove);
75 inactiveProfileIds.forEach(this::deactivateOptionalProfile);
76 }
77
78
79
80
81
82 public void activateRequiredProfile(String id) {
83 this.activations.put(id, ActivationSettings.ACTIVATION_REQUIRED);
84 }
85
86
87
88
89
90 public void activateOptionalProfile(String id) {
91 this.activations.put(id, ActivationSettings.ACTIVATION_OPTIONAL);
92 }
93
94
95
96
97
98 public void deactivateRequiredProfile(String id) {
99 this.activations.put(id, ActivationSettings.DEACTIVATION_REQUIRED);
100 }
101
102
103
104
105
106 public void deactivateOptionalProfile(String id) {
107 this.activations.put(id, ActivationSettings.DEACTIVATION_OPTIONAL);
108 }
109
110
111
112
113
114
115
116 public void addProfileActivation(String id, boolean active, boolean optional) {
117 final ActivationSettings settings = ActivationSettings.of(active, optional);
118 this.activations.put(id, settings);
119 }
120
121 private Set<String> getProfileIds(final Predicate<ActivationSettings> predicate) {
122 return this.activations.entrySet().stream()
123 .filter(e -> predicate.test(e.getValue()))
124 .map(Map.Entry::getKey)
125 .collect(toSet());
126 }
127
128
129
130
131 public Set<String> getRequiredActiveProfileIds() {
132 return getProfileIds(pa -> !pa.optional && pa.active);
133 }
134
135
136
137
138 public Set<String> getOptionalActiveProfileIds() {
139 return getProfileIds(pa -> pa.optional && pa.active);
140 }
141
142
143
144
145 public Set<String> getRequiredInactiveProfileIds() {
146 return getProfileIds(pa -> !pa.optional && !pa.active);
147 }
148
149
150
151
152 public Set<String> getOptionalInactiveProfileIds() {
153 return getProfileIds(pa -> pa.optional && !pa.active);
154 }
155 }