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