1
2
3
4
5 package org.apache.maven.api.model;
6
7 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Set;
15 import org.apache.maven.api.annotations.Experimental;
16 import org.apache.maven.api.annotations.Generated;
17 import org.apache.maven.api.annotations.Immutable;
18 import org.apache.maven.api.annotations.Nonnull;
19 import org.apache.maven.api.annotations.NotThreadSafe;
20 import org.apache.maven.api.annotations.ThreadSafe;
21
22
23
24
25 @Experimental
26 @Generated @ThreadSafe @Immutable
27 public class PluginConfiguration
28 extends PluginContainer
29 implements Serializable, InputLocationTracker
30 {
31
32
33
34
35
36
37 final PluginManagement pluginManagement;
38
39 final Map<Object, InputLocation> locations;
40
41
42
43
44
45 protected PluginConfiguration(Builder builder) {
46 super(builder);
47 this.pluginManagement = builder.pluginManagement != null ? builder.pluginManagement : (builder.base != null ? builder.base.pluginManagement : null);
48 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
49 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
50 Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
51 mutableLocations.put("pluginManagement", newlocs.containsKey("pluginManagement") ? newlocs.get("pluginManagement") : oldlocs.get("pluginManagement"));
52 this.locations = Collections.unmodifiableMap(mutableLocations);
53 }
54
55
56
57
58
59
60
61
62
63 public PluginManagement getPluginManagement() {
64 return this.pluginManagement;
65 }
66
67
68
69
70 public InputLocation getLocation(Object key) {
71 return locations != null ? locations.get(key) : null;
72 }
73
74
75
76
77 public Set<Object> getLocationKeys() {
78 return locations != null ? locations.keySet() : null;
79 }
80
81
82
83
84
85
86 @Nonnull
87 public Builder with() {
88 return newBuilder(this);
89 }
90
91
92
93
94
95
96 @Nonnull
97 public PluginConfiguration withPlugins(Collection<Plugin> plugins) {
98 return newBuilder(this, true).plugins(plugins).build();
99 }
100
101
102
103
104
105
106 @Nonnull
107 public PluginConfiguration withPluginManagement(PluginManagement pluginManagement) {
108 return newBuilder(this, true).pluginManagement(pluginManagement).build();
109 }
110
111
112
113
114
115
116
117
118 @Nonnull
119 public static PluginConfiguration newInstance() {
120 return newInstance(true);
121 }
122
123
124
125
126
127
128
129
130 @Nonnull
131 public static PluginConfiguration newInstance(boolean withDefaults) {
132 return newBuilder(withDefaults).build();
133 }
134
135
136
137
138
139
140
141
142 @Nonnull
143 public static Builder newBuilder() {
144 return newBuilder(true);
145 }
146
147
148
149
150
151
152
153 @Nonnull
154 public static Builder newBuilder(boolean withDefaults) {
155 return new Builder(withDefaults);
156 }
157
158
159
160
161
162
163
164
165 @Nonnull
166 public static Builder newBuilder(PluginConfiguration from) {
167 return newBuilder(from, false);
168 }
169
170
171
172
173
174
175
176
177 @Nonnull
178 public static Builder newBuilder(PluginConfiguration from, boolean forceCopy) {
179 return new Builder(from, forceCopy);
180 }
181
182
183
184
185
186
187 @NotThreadSafe
188 public static class Builder
189 extends PluginContainer.Builder
190 {
191 PluginConfiguration base;
192 PluginManagement pluginManagement;
193
194 protected Builder(boolean withDefaults) {
195 super(withDefaults);
196 if (withDefaults) {
197 }
198 }
199
200 protected Builder(PluginConfiguration base, boolean forceCopy) {
201 super(base, forceCopy);
202 if (forceCopy) {
203 this.pluginManagement = base.pluginManagement;
204 this.locations = base.locations;
205 this.importedFrom = base.importedFrom;
206 } else {
207 this.base = base;
208 }
209 }
210
211 @Nonnull
212 public Builder plugins(Collection<Plugin> plugins) {
213 this.plugins = plugins;
214 return this;
215 }
216
217 @Nonnull
218 public Builder pluginManagement(PluginManagement pluginManagement) {
219 this.pluginManagement = pluginManagement;
220 return this;
221 }
222
223
224 @Nonnull
225 public Builder location(Object key, InputLocation location) {
226 if (location != null) {
227 if (!(this.locations instanceof HashMap)) {
228 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
229 }
230 this.locations.put(key, location);
231 }
232 return this;
233 }
234
235 @Nonnull
236 public Builder importedFrom(InputLocation importedFrom) {
237 this.importedFrom = importedFrom;
238 return this;
239 }
240
241 @Nonnull
242 public PluginConfiguration build() {
243
244 if (base != null
245 && (plugins == null || plugins == base.plugins)
246 && (pluginManagement == null || pluginManagement == base.pluginManagement)
247 ) {
248 return base;
249 }
250 return new PluginConfiguration(this);
251 }
252 }
253
254
255
256
257
258
259 public String toString()
260 {
261 return "PluginConfiguration {" + super.toString() + "}";
262 }
263
264
265 }