View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   //  Generated by Modello Velocity from model-v3.vm
3   //  template, any modifications will be overwritten.
4   // ==============================================================
5   package org.apache.maven.model;
6   
7   import java.io.Serializable;
8   import java.util.AbstractList;
9   import java.util.ArrayList;
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.stream.Collectors;
16  import java.util.stream.Stream;
17  import org.apache.maven.api.annotations.Generated;
18  import org.apache.maven.api.annotations.Nonnull;
19  import org.codehaus.plexus.util.xml.Xpp3Dom;
20  
21  @Generated
22  public class Plugin
23      extends ConfigurationContainer
24      implements Serializable, Cloneable
25  {
26  
27      public Plugin() {
28          this(org.apache.maven.api.model.Plugin.newInstance());
29      }
30  
31      public Plugin(org.apache.maven.api.model.Plugin delegate) {
32          this(delegate, null);
33      }
34  
35      public Plugin(org.apache.maven.api.model.Plugin delegate, BaseObject parent) {
36          super(delegate, parent);
37      }
38  
39      public Plugin clone(){
40          return new Plugin(getDelegate());
41      }
42  
43      @Override
44      public org.apache.maven.api.model.Plugin getDelegate() {
45          return (org.apache.maven.api.model.Plugin) super.getDelegate();
46      }
47  
48      @Override
49      public boolean equals(Object o) {
50          if (this == o) {
51              return true;
52          }
53          if (o == null || !(o instanceof Plugin)) {
54              return false;
55          }
56          Plugin that = (Plugin) o;
57          return Objects.equals(this.delegate, that.delegate);
58      }
59  
60      @Override
61      public int hashCode() {
62          return getDelegate().hashCode();
63      }
64  
65      public String getGroupId() {
66          return getDelegate().getGroupId();
67      }
68  
69      public void setGroupId(String groupId) {
70          if (!Objects.equals(groupId, getGroupId())) {
71              update(getDelegate().withGroupId(groupId));
72          }
73      }
74  
75      public String getArtifactId() {
76          return getDelegate().getArtifactId();
77      }
78  
79      public void setArtifactId(String artifactId) {
80          if (!Objects.equals(artifactId, getArtifactId())) {
81              update(getDelegate().withArtifactId(artifactId));
82          }
83      }
84  
85      public String getVersion() {
86          return getDelegate().getVersion();
87      }
88  
89      public void setVersion(String version) {
90          if (!Objects.equals(version, getVersion())) {
91              update(getDelegate().withVersion(version));
92          }
93      }
94  
95      public String getExtensions() {
96          return getDelegate().getExtensions();
97      }
98  
99      public void setExtensions(String extensions) {
100         if (!Objects.equals(extensions, getExtensions())) {
101             update(getDelegate().withExtensions(extensions));
102         }
103     }
104 
105     @Nonnull
106     public List<PluginExecution> getExecutions() {
107         return new WrapperList<PluginExecution, org.apache.maven.api.model.PluginExecution>(
108                     () -> getDelegate().getExecutions(), l -> update(getDelegate().withExecutions(l)),
109                     d -> new PluginExecution(d, this), PluginExecution::getDelegate);
110     }
111 
112     public void setExecutions(List<PluginExecution> executions) {
113         if (!Objects.equals(executions, getExecutions())) {
114             update(getDelegate().withExecutions(
115                    executions.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
116             executions.forEach(e -> e.childrenTracking = this::replace);
117         }
118     }
119 
120     public void addExecution(PluginExecution execution) {
121         update(getDelegate().withExecutions(
122                Stream.concat(getDelegate().getExecutions().stream(), Stream.of(execution.getDelegate()))
123                         .collect(Collectors.toList())));
124         execution.childrenTracking = this::replace;
125     }
126 
127     public void removeExecution(PluginExecution execution) {
128         update(getDelegate().withExecutions(
129                getDelegate().getExecutions().stream()
130                         .filter(e -> !Objects.equals(e, execution))
131                         .collect(Collectors.toList())));
132         execution.childrenTracking = null;
133     }
134 
135     @Nonnull
136     public List<Dependency> getDependencies() {
137         return new WrapperList<Dependency, org.apache.maven.api.model.Dependency>(
138                     () -> getDelegate().getDependencies(), l -> update(getDelegate().withDependencies(l)),
139                     d -> new Dependency(d, this), Dependency::getDelegate);
140     }
141 
142     public void setDependencies(List<Dependency> dependencies) {
143         if (!Objects.equals(dependencies, getDependencies())) {
144             update(getDelegate().withDependencies(
145                    dependencies.stream().map(c -> c.getDelegate()).collect(Collectors.toList())));
146             dependencies.forEach(e -> e.childrenTracking = this::replace);
147         }
148     }
149 
150     public void addDependency(Dependency dependency) {
151         update(getDelegate().withDependencies(
152                Stream.concat(getDelegate().getDependencies().stream(), Stream.of(dependency.getDelegate()))
153                         .collect(Collectors.toList())));
154         dependency.childrenTracking = this::replace;
155     }
156 
157     public void removeDependency(Dependency dependency) {
158         update(getDelegate().withDependencies(
159                getDelegate().getDependencies().stream()
160                         .filter(e -> !Objects.equals(e, dependency))
161                         .collect(Collectors.toList())));
162         dependency.childrenTracking = null;
163     }
164 
165     public InputLocation getLocation(Object key) {
166         org.apache.maven.api.model.InputLocation loc = getDelegate().getLocation(key);
167         return loc != null ? new InputLocation(loc) : null;
168     }
169 
170     public void setLocation(Object key, InputLocation location) {
171         update(org.apache.maven.api.model.Plugin.newBuilder(getDelegate(), true)
172                         .location(key, location.toApiLocation()).build());
173     }
174 
175     protected boolean replace(Object oldDelegate, Object newDelegate) {
176         if (super.replace(oldDelegate, newDelegate)) {
177             return true;
178         }
179         if (getDelegate().getExecutions().contains(oldDelegate)) {
180             List<org.apache.maven.api.model.PluginExecution> list = new ArrayList<>(getDelegate().getExecutions());
181             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.PluginExecution) newDelegate : d);
182             update(getDelegate().withExecutions(list));
183             return true;
184         }
185         if (getDelegate().getDependencies().contains(oldDelegate)) {
186             List<org.apache.maven.api.model.Dependency> list = new ArrayList<>(getDelegate().getDependencies());
187             list.replaceAll(d -> d == oldDelegate ? (org.apache.maven.api.model.Dependency) newDelegate : d);
188             update(getDelegate().withDependencies(list));
189             return true;
190         }
191         return false;
192     }
193 
194     public static List<org.apache.maven.api.model.Plugin> pluginToApiV4(List<Plugin> list) {
195         return list != null ? new WrapperList<>(list, Plugin::getDelegate, Plugin::new) : null;
196     }
197 
198     public static List<Plugin> pluginToApiV3(List<org.apache.maven.api.model.Plugin> list) {
199         return list != null ? new WrapperList<>(list, Plugin::new, Plugin::getDelegate) : null;
200     }
201 
202 
203             
204     public boolean isExtensions()
205     {
206         return ( getExtensions() != null ) ? Boolean.parseBoolean( getExtensions() ) : false;
207     }
208             
209           
210 
211             
212     public void setExtensions( boolean extensions )
213     {
214         setExtensions( String.valueOf( extensions ) );
215     }
216             
217           
218 
219             
220     private java.util.Map<String, PluginExecution> executionMap = null;
221 
222     /**
223      * Reset the {@code executionMap} field to {@code null}
224      */
225     public void flushExecutionMap()
226     {
227         this.executionMap = null;
228     }
229     /**
230      * @return a Map of executions field with {@code PluginExecution#getId()} as key
231      * @see PluginExecution#getId()
232      */
233     public java.util.Map<String, PluginExecution> getExecutionsAsMap()
234     {
235         if ( executionMap == null )
236         {
237             executionMap = new java.util.LinkedHashMap<String, PluginExecution>();
238             for ( java.util.Iterator<PluginExecution> i = getExecutions().iterator(); i.hasNext(); )
239             {
240                 PluginExecution exec = (PluginExecution) i.next();
241                 if ( executionMap.containsKey( exec.getId() ) )
242                 {
243                     throw new IllegalStateException( "You cannot have two plugin executions with the same (or missing) <id/> elements.\nOffending execution\n\nId: \'" + exec.getId() + "\'\nPlugin:\'" + getKey() + "\'\n\n" );
244                 }
245                 executionMap.put( exec.getId(), exec );
246             }
247         }
248         return executionMap;
249     }
250 
251     /**
252      * Gets the identifier of the plugin.
253      *
254      * @return the plugin id in the form {@code <groupId>:<artifactId>:<version>}, never {@code null}
255      */
256     public String getId()
257     {
258         StringBuilder id = new StringBuilder( 128 );
259 
260         id.append( ( getGroupId() == null ) ? "[unknown-group-id]" : getGroupId() );
261         id.append( ":" );
262         id.append( ( getArtifactId() == null ) ? "[unknown-artifact-id]" : getArtifactId() );
263         id.append( ":" );
264         id.append( ( getVersion() == null ) ? "[unknown-version]" : getVersion() );
265 
266         return id.toString();
267     }
268 
269     /**
270      * @return the key of the plugin, ie {@code groupId:artifactId}
271      */
272     public String getKey()
273     {
274         return constructKey( getGroupId(), getArtifactId() );
275     }
276 
277     /**
278      * @param groupId The group ID of the plugin in the repository
279      * @param artifactId The artifact ID of the reporting plugin in the repository
280      * @return the key of the plugin, ie {@code groupId:artifactId}
281      */
282     public static String constructKey( String groupId, String artifactId )
283     {
284         return groupId + ":" + artifactId;
285     }
286 
287             
288           
289 }