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.Objects;
15  import java.util.Optional;
16  import java.util.Set;
17  import java.util.stream.Collectors;
18  import java.util.stream.Stream;
19  import org.apache.maven.api.annotations.Experimental;
20  import org.apache.maven.api.annotations.Generated;
21  import org.apache.maven.api.annotations.Immutable;
22  import org.apache.maven.api.annotations.Nonnull;
23  import org.apache.maven.api.annotations.NotThreadSafe;
24  import org.apache.maven.api.annotations.ThreadSafe;
25  
26  /**
27   * Section for management of default plugin information for use in a group of POMs.
28   */
29  @Experimental
30  @Generated @ThreadSafe @Immutable
31  public class PluginManagement
32      extends PluginContainer
33      implements Serializable, InputLocationTracker
34  {
35  
36      /**
37        * Constructor for this class, to be called from its subclasses and {@link Builder}.
38        * @see Builder#build()
39        */
40      protected PluginManagement(Builder builder) {
41          super(builder);
42      }
43  
44      /**
45       * Creates a new builder with this object as the basis.
46       *
47       * @return a {@code Builder}
48       */
49      @Nonnull
50      public Builder with() {
51          return newBuilder(this);
52      }
53      /**
54       * Creates a new {@code PluginManagement} instance using the specified plugins.
55       *
56       * @param plugins the new {@code Collection<Plugin>} to use
57       * @return a {@code PluginManagement} with the specified plugins
58       */
59      @Nonnull
60      public PluginManagement withPlugins(Collection<Plugin> plugins) {
61          return newBuilder(this, true).plugins(plugins).build();
62      }
63  
64      /**
65       * Creates a new {@code PluginManagement} instance.
66       * Equivalent to {@code newInstance(true)}.
67       * @see #newInstance(boolean)
68       *
69       * @return a new {@code PluginManagement}
70       */
71      @Nonnull
72      public static PluginManagement newInstance() {
73          return newInstance(true);
74      }
75  
76      /**
77       * Creates a new {@code PluginManagement} instance using default values or not.
78       * Equivalent to {@code newBuilder(withDefaults).build()}.
79       *
80       * @param withDefaults the boolean indicating whether default values should be used
81       * @return a new {@code PluginManagement}
82       */
83      @Nonnull
84      public static PluginManagement newInstance(boolean withDefaults) {
85          return newBuilder(withDefaults).build();
86      }
87  
88      /**
89       * Creates a new {@code PluginManagement} builder instance.
90       * Equivalent to {@code newBuilder(true)}.
91       * @see #newBuilder(boolean)
92       *
93       * @return a new {@code Builder}
94       */
95      @Nonnull
96      public static Builder newBuilder() {
97          return newBuilder(true);
98      }
99  
100     /**
101      * Creates a new {@code PluginManagement} builder instance using default values or not.
102      *
103      * @param withDefaults the boolean indicating whether default values should be used
104      * @return a new {@code Builder}
105      */
106     @Nonnull
107     public static Builder newBuilder(boolean withDefaults) {
108         return new Builder(withDefaults);
109     }
110 
111     /**
112      * Creates a new {@code PluginManagement} builder instance using the specified object as a basis.
113      * Equivalent to {@code newBuilder(from, false)}.
114      *
115      * @param from the {@code PluginManagement} instance to use as a basis
116      * @return a new {@code Builder}
117      */
118     @Nonnull
119     public static Builder newBuilder(PluginManagement from) {
120         return newBuilder(from, false);
121     }
122 
123     /**
124      * Creates a new {@code PluginManagement} builder instance using the specified object as a basis.
125      *
126      * @param from the {@code PluginManagement} instance to use as a basis
127      * @param forceCopy the boolean indicating if a copy should be forced
128      * @return a new {@code Builder}
129      */
130     @Nonnull
131     public static Builder newBuilder(PluginManagement from, boolean forceCopy) {
132         return new Builder(from, forceCopy);
133     }
134 
135     /**
136      * Builder class used to create PluginManagement instances.
137      * @see #with()
138      * @see #newBuilder()
139      */
140     @NotThreadSafe
141     public static class Builder
142         extends PluginContainer.Builder
143     {
144         PluginManagement base;
145 
146         protected Builder(boolean withDefaults) {
147             super(withDefaults);
148             if (withDefaults) {
149             }
150         }
151 
152         protected Builder(PluginManagement base, boolean forceCopy) {
153             super(base, forceCopy);
154             if (forceCopy) {
155                 this.locations = base.locations;
156                 this.importedFrom = base.importedFrom;
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 Builder importedFrom(InputLocation importedFrom) {
182             this.importedFrom = importedFrom;
183             return this;
184         }
185 
186         @Nonnull
187         public PluginManagement build() {
188             // this method should not contain any logic other than creating (or reusing) an object in order to ease subclassing
189             if (base != null
190                     && (plugins == null || plugins == base.plugins)
191             ) {
192                 return base;
193             }
194             return new PluginManagement(this);
195         }
196 
197     }
198 
199 }