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