View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //  Generated by Modello Velocity from model.vm
3   //  template, any modifications will be overwritten.
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   * Section for management of default plugin information for use in a group of POMs.
23   */
24  @Experimental
25  @Generated @ThreadSafe @Immutable
26  public class PluginManagement
27      extends PluginContainer
28      implements Serializable, InputLocationTracker
29  {
30  
31      /**
32        * Constructor for this class, package protected.
33        * @see Builder#build()
34        */
35      PluginManagement(
36          Collection<Plugin> plugins,
37          Map<Object, InputLocation> locations
38      ) {
39          super(
40              plugins,
41              locations
42          );
43      }
44  
45      /**
46       * Creates a new builder with this object as the basis.
47       *
48       * @return a {@code Builder}
49       */
50      @Nonnull
51      public Builder with() {
52          return newBuilder(this);
53      }
54      /**
55       * Creates a new {@code PluginManagement} instance using the specified plugins.
56       *
57       * @param plugins the new {@code Collection<Plugin>} to use
58       * @return a {@code PluginManagement} with the specified plugins
59       */
60      @Nonnull
61      public PluginManagement withPlugins(Collection<Plugin> plugins) {
62          return newBuilder(this, true).plugins(plugins).build();
63      }
64  
65      /**
66       * Creates a new {@code PluginManagement} instance.
67       * Equivalent to {@code newInstance(true)}.
68       * @see #newInstance(boolean)
69       *
70       * @return a new {@code PluginManagement}
71       */
72      @Nonnull
73      public static PluginManagement newInstance() {
74          return newInstance(true);
75      }
76  
77      /**
78       * Creates a new {@code PluginManagement} instance using default values or not.
79       * Equivalent to {@code newBuilder(withDefaults).build()}.
80       *
81       * @param withDefaults the boolean indicating whether default values should be used
82       * @return a new {@code PluginManagement}
83       */
84      @Nonnull
85      public static PluginManagement newInstance(boolean withDefaults) {
86          return newBuilder(withDefaults).build();
87      }
88  
89      /**
90       * Creates a new {@code PluginManagement} builder instance.
91       * Equivalent to {@code newBuilder(true)}.
92       * @see #newBuilder(boolean)
93       *
94       * @return a new {@code Builder}
95       */
96      @Nonnull
97      public static Builder newBuilder() {
98          return newBuilder(true);
99      }
100 
101     /**
102      * Creates a new {@code PluginManagement} builder instance using default values or not.
103      *
104      * @param withDefaults the boolean indicating whether default values should be used
105      * @return a new {@code Builder}
106      */
107     @Nonnull
108     public static Builder newBuilder(boolean withDefaults) {
109         return new Builder(withDefaults);
110     }
111 
112     /**
113      * Creates a new {@code PluginManagement} builder instance using the specified object as a basis.
114      * Equivalent to {@code newBuilder(from, false)}.
115      *
116      * @param from the {@code PluginManagement} instance to use as a basis
117      * @return a new {@code Builder}
118      */
119     @Nonnull
120     public static Builder newBuilder(PluginManagement from) {
121         return newBuilder(from, false);
122     }
123 
124     /**
125      * Creates a new {@code PluginManagement} builder instance using the specified object as a basis.
126      *
127      * @param from the {@code PluginManagement} instance to use as a basis
128      * @param forceCopy the boolean indicating if a copy should be forced
129      * @return a new {@code Builder}
130      */
131     @Nonnull
132     public static Builder newBuilder(PluginManagement from, boolean forceCopy) {
133         return new Builder(from, forceCopy);
134     }
135 
136     /**
137      * Builder class used to create PluginManagement instances.
138      * @see #with()
139      * @see #newBuilder()
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 }