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 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   * Section for management of default plugin information for use in a group of POMs.
24   */
25  @Experimental
26  @Generated @ThreadSafe @Immutable
27  public class PluginManagement
28      extends PluginContainer
29      implements Serializable, InputLocationTracker
30  {
31      /** Locations (this potentially hides the same name field from the super class) */
32      final Map<Object, InputLocation> locations;
33  
34      /**
35        * Constructor for this class, to be called from its subclasses and {@link Builder}.
36        * @see Builder#build()
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       * Gets the location of the specified field in the input source.
48       */
49      public InputLocation getLocation(Object key) {
50          return locations != null ? locations.get(key) : null;
51      }
52  
53      /**
54      * Gets the keys of the locations of the input source.
55      */
56      public Set<Object> getLocationKeys() {
57          return locations != null ? locations.keySet() : null;
58      }
59  
60      /**
61       * Creates a new builder with this object as the basis.
62       *
63       * @return a {@code Builder}
64       */
65      @Nonnull
66      public Builder with() {
67          return newBuilder(this);
68      }
69      /**
70       * Creates a new {@code PluginManagement} instance using the specified plugins.
71       *
72       * @param plugins the new {@code Collection<Plugin>} to use
73       * @return a {@code PluginManagement} with the specified plugins
74       */
75      @Nonnull
76      public PluginManagement withPlugins(Collection<Plugin> plugins) {
77          return newBuilder(this, true).plugins(plugins).build();
78      }
79  
80      /**
81       * Creates a new {@code PluginManagement} instance.
82       * Equivalent to {@code newInstance(true)}.
83       * @see #newInstance(boolean)
84       *
85       * @return a new {@code PluginManagement}
86       */
87      @Nonnull
88      public static PluginManagement newInstance() {
89          return newInstance(true);
90      }
91  
92      /**
93       * Creates a new {@code PluginManagement} instance using default values or not.
94       * Equivalent to {@code newBuilder(withDefaults).build()}.
95       *
96       * @param withDefaults the boolean indicating whether default values should be used
97       * @return a new {@code PluginManagement}
98       */
99      @Nonnull
100     public static PluginManagement newInstance(boolean withDefaults) {
101         return newBuilder(withDefaults).build();
102     }
103 
104     /**
105      * Creates a new {@code PluginManagement} builder instance.
106      * Equivalent to {@code newBuilder(true)}.
107      * @see #newBuilder(boolean)
108      *
109      * @return a new {@code Builder}
110      */
111     @Nonnull
112     public static Builder newBuilder() {
113         return newBuilder(true);
114     }
115 
116     /**
117      * Creates a new {@code PluginManagement} builder instance using default values or not.
118      *
119      * @param withDefaults the boolean indicating whether default values should be used
120      * @return a new {@code Builder}
121      */
122     @Nonnull
123     public static Builder newBuilder(boolean withDefaults) {
124         return new Builder(withDefaults);
125     }
126 
127     /**
128      * Creates a new {@code PluginManagement} builder instance using the specified object as a basis.
129      * Equivalent to {@code newBuilder(from, false)}.
130      *
131      * @param from the {@code PluginManagement} instance to use as a basis
132      * @return a new {@code Builder}
133      */
134     @Nonnull
135     public static Builder newBuilder(PluginManagement from) {
136         return newBuilder(from, false);
137     }
138 
139     /**
140      * Creates a new {@code PluginManagement} builder instance using the specified object as a basis.
141      *
142      * @param from the {@code PluginManagement} instance to use as a basis
143      * @param forceCopy the boolean indicating if a copy should be forced
144      * @return a new {@code Builder}
145      */
146     @Nonnull
147     public static Builder newBuilder(PluginManagement from, boolean forceCopy) {
148         return new Builder(from, forceCopy);
149     }
150 
151     /**
152      * Builder class used to create PluginManagement instances.
153      * @see #with()
154      * @see #newBuilder()
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             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
205             if (base != null
206                     && (plugins == null || plugins == base.plugins)
207             ) {
208                 return base;
209             }
210             return new PluginManagement(this);
211         }
212     }
213 
214 }