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 static java.util.stream.Collectors.toSet;
22
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.Set;
27 import java.util.function.Predicate;
28 import java.util.stream.Collectors;
29 import java.util.stream.Stream;
30
31
32
33
34
35 public class ProjectActivation {
36 private static class ProjectActivationSettings {
37
38
39
40 final String selector;
41
42
43
44
45 final ActivationSettings activationSettings;
46
47 ProjectActivationSettings(String selector, ActivationSettings activationSettings) {
48 this.selector = selector;
49 this.activationSettings = activationSettings;
50 }
51 }
52
53
54
55
56 private final List<ProjectActivationSettings> activations = new ArrayList<>();
57
58
59
60
61
62
63
64 public void addProjectActivation(String selector, boolean active, boolean optional) {
65 final ActivationSettings settings = ActivationSettings.of(active, optional);
66 this.activations.add(new ProjectActivationSettings(selector, settings));
67 }
68
69 private Stream<ProjectActivationSettings> getProjects(final Predicate<ActivationSettings> predicate) {
70 return this.activations.stream().filter(activation -> predicate.test(activation.activationSettings));
71 }
72
73 private Set<String> getProjectSelectors(final Predicate<ActivationSettings> predicate) {
74 return getProjects(predicate).map(activation -> activation.selector).collect(toSet());
75 }
76
77
78
79
80 public Set<String> getRequiredActiveProjectSelectors() {
81 return getProjectSelectors(pa -> !pa.optional && pa.active);
82 }
83
84
85
86
87 public Set<String> getOptionalActiveProjectSelectors() {
88 return getProjectSelectors(pa -> pa.optional && pa.active);
89 }
90
91
92
93
94 public Set<String> getRequiredInactiveProjectSelectors() {
95 return getProjectSelectors(pa -> !pa.optional && !pa.active);
96 }
97
98
99
100
101 public Set<String> getOptionalInactiveProjectSelectors() {
102 return getProjectSelectors(pa -> pa.optional && !pa.active);
103 }
104
105
106
107
108
109
110 @Deprecated
111 public List<String> getSelectedProjects() {
112 return Collections.unmodifiableList(new ArrayList<>(getProjectSelectors(pa -> pa.active)));
113 }
114
115
116
117
118
119
120 @Deprecated
121 public List<String> getExcludedProjects() {
122 return Collections.unmodifiableList(new ArrayList<>(getProjectSelectors(pa -> !pa.active)));
123 }
124
125
126
127
128
129
130 @Deprecated
131 public void overwriteActiveProjects(List<String> activeProjectSelectors) {
132 List<ProjectActivationSettings> projects = getProjects(pa -> pa.active).collect(Collectors.toList());
133 this.activations.removeAll(projects);
134 activeProjectSelectors.forEach(this::activateOptionalProject);
135 }
136
137
138
139
140
141
142 @Deprecated
143 public void overwriteInactiveProjects(List<String> inactiveProjectSelectors) {
144 List<ProjectActivationSettings> projects = getProjects(pa -> !pa.active).collect(Collectors.toList());
145 this.activations.removeAll(projects);
146 inactiveProjectSelectors.forEach(this::deactivateOptionalProject);
147 }
148
149
150
151
152
153 public void activateRequiredProject(String selector) {
154 this.activations.add(new ProjectActivationSettings(selector, ActivationSettings.ACTIVATION_REQUIRED));
155 }
156
157
158
159
160
161 public void activateOptionalProject(String selector) {
162 this.activations.add(new ProjectActivationSettings(selector, ActivationSettings.ACTIVATION_OPTIONAL));
163 }
164
165
166
167
168
169 public void deactivateRequiredProject(String selector) {
170 this.activations.add(new ProjectActivationSettings(selector, ActivationSettings.DEACTIVATION_REQUIRED));
171 }
172
173
174
175
176
177 public void deactivateOptionalProject(String selector) {
178 this.activations.add(new ProjectActivationSettings(selector, ActivationSettings.DEACTIVATION_OPTIONAL));
179 }
180
181 public boolean isEmpty() {
182 return this.activations.isEmpty();
183 }
184 }