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 PluginManagement
28 extends PluginContainer
29 implements Serializable, InputLocationTracker
30 {
31
32 final Map<Object, InputLocation> locations;
33
34
35
36
37
38 protected PluginManagement(Builder builder) {
39 super(builder);
40 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
41 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
42 Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
43 this.locations = Collections.unmodifiableMap(mutableLocations);
44 }
45
46
47
48
49 public InputLocation getLocation(Object key) {
50 return locations != null ? locations.get(key) : null;
51 }
52
53
54
55
56 public Set<Object> getLocationKeys() {
57 return locations != null ? locations.keySet() : null;
58 }
59
60
61
62
63
64
65 @Nonnull
66 public Builder with() {
67 return newBuilder(this);
68 }
69
70
71
72
73
74
75 @Nonnull
76 public PluginManagement withPlugins(Collection<Plugin> plugins) {
77 return newBuilder(this, true).plugins(plugins).build();
78 }
79
80
81
82
83
84
85
86
87 @Nonnull
88 public static PluginManagement newInstance() {
89 return newInstance(true);
90 }
91
92
93
94
95
96
97
98
99 @Nonnull
100 public static PluginManagement newInstance(boolean withDefaults) {
101 return newBuilder(withDefaults).build();
102 }
103
104
105
106
107
108
109
110
111 @Nonnull
112 public static Builder newBuilder() {
113 return newBuilder(true);
114 }
115
116
117
118
119
120
121
122 @Nonnull
123 public static Builder newBuilder(boolean withDefaults) {
124 return new Builder(withDefaults);
125 }
126
127
128
129
130
131
132
133
134 @Nonnull
135 public static Builder newBuilder(PluginManagement from) {
136 return newBuilder(from, false);
137 }
138
139
140
141
142
143
144
145
146 @Nonnull
147 public static Builder newBuilder(PluginManagement from, boolean forceCopy) {
148 return new Builder(from, forceCopy);
149 }
150
151
152
153
154
155
156 @NotThreadSafe
157 public static class Builder
158 extends PluginContainer.Builder
159 {
160 PluginManagement base;
161
162 protected Builder(boolean withDefaults) {
163 super(withDefaults);
164 if (withDefaults) {
165 }
166 }
167
168 protected Builder(PluginManagement base, boolean forceCopy) {
169 super(base, forceCopy);
170 if (forceCopy) {
171 this.locations = base.locations;
172 this.importedFrom = base.importedFrom;
173 } else {
174 this.base = base;
175 }
176 }
177
178 @Nonnull
179 public Builder plugins(Collection<Plugin> plugins) {
180 this.plugins = plugins;
181 return this;
182 }
183
184
185 @Nonnull
186 public Builder location(Object key, InputLocation location) {
187 if (location != null) {
188 if (!(this.locations instanceof HashMap)) {
189 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
190 }
191 this.locations.put(key, location);
192 }
193 return this;
194 }
195
196 @Nonnull
197 public Builder importedFrom(InputLocation importedFrom) {
198 this.importedFrom = importedFrom;
199 return this;
200 }
201
202 @Nonnull
203 public PluginManagement build() {
204
205 if (base != null
206 && (plugins == null || plugins == base.plugins)
207 ) {
208 return base;
209 }
210 return new PluginManagement(this);
211 }
212 }
213
214 }