1
2
3
4 package org.apache.maven.model;
5
6 import java.io.Serializable;
7 import java.util.AbstractList;
8 import java.util.ArrayList;
9 import java.util.Collections;
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.Map;
13 import java.util.Objects;
14 import java.util.stream.Collectors;
15 import java.util.stream.Stream;
16 import org.apache.maven.api.annotations.Generated;
17 import org.apache.maven.api.annotations.Nonnull;
18 import org.codehaus.plexus.util.xml.Xpp3Dom;
19
20 @Generated
21 public class Plugin
22 extends ConfigurationContainer
23 implements Serializable, Cloneable
24 {
25
26 public Plugin()
27 {
28 this( org.apache.maven.api.model.Plugin.newInstance() );
29 }
30
31 public Plugin( org.apache.maven.api.model.Plugin delegate )
32 {
33 this( delegate, null );
34 }
35
36 public Plugin( org.apache.maven.api.model.Plugin delegate, BaseObject parent )
37 {
38 super( delegate, parent );
39 }
40
41 public Plugin clone()
42 {
43 return new Plugin( getDelegate() );
44 }
45
46 @Override
47 public org.apache.maven.api.model.Plugin getDelegate()
48 {
49 return ( org.apache.maven.api.model.Plugin ) super.getDelegate();
50 }
51
52 public String getGroupId()
53 {
54 return getDelegate().getGroupId();
55 }
56
57 public void setGroupId( String groupId )
58 {
59 if ( !Objects.equals( groupId, getDelegate().getGroupId() ) )
60 {
61 update( getDelegate().withGroupId( groupId ) );
62 }
63 }
64
65 public String getArtifactId()
66 {
67 return getDelegate().getArtifactId();
68 }
69
70 public void setArtifactId( String artifactId )
71 {
72 if ( !Objects.equals( artifactId, getDelegate().getArtifactId() ) )
73 {
74 update( getDelegate().withArtifactId( artifactId ) );
75 }
76 }
77
78 public String getVersion()
79 {
80 return getDelegate().getVersion();
81 }
82
83 public void setVersion( String version )
84 {
85 if ( !Objects.equals( version, getDelegate().getVersion() ) )
86 {
87 update( getDelegate().withVersion( version ) );
88 }
89 }
90
91 public String getExtensions()
92 {
93 return getDelegate().getExtensions();
94 }
95
96 public void setExtensions( String extensions )
97 {
98 if ( !Objects.equals( extensions, getDelegate().getExtensions() ) )
99 {
100 update( getDelegate().withExtensions( extensions ) );
101 }
102 }
103
104 @Nonnull
105 public List<PluginExecution> getExecutions()
106 {
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 {
114 if ( !Objects.equals( executions, getDelegate().getExecutions() ) )
115 {
116 update( getDelegate().withExecutions(
117 executions.stream().map( c -> c.getDelegate() ).collect( Collectors.toList() ) ) );
118 executions.forEach( e -> e.childrenTracking = this::replace );
119 }
120 }
121
122 public void addExecution( PluginExecution execution )
123 {
124 update( getDelegate().withExecutions(
125 Stream.concat( getDelegate().getExecutions().stream(), Stream.of( execution.getDelegate() ) )
126 .collect( Collectors.toList() ) ) );
127 execution.childrenTracking = this::replace;
128 }
129
130 public void removeExecution( PluginExecution execution )
131 {
132 update( getDelegate().withExecutions(
133 getDelegate().getExecutions().stream()
134 .filter( e -> !Objects.equals( e, execution ) )
135 .collect( Collectors.toList() ) ) );
136 execution.childrenTracking = null;
137 }
138
139 @Nonnull
140 public List<Dependency> getDependencies()
141 {
142 return new WrapperList<Dependency, org.apache.maven.api.model.Dependency>(
143 () -> getDelegate().getDependencies(), l -> update( getDelegate().withDependencies( l ) ),
144 d -> new Dependency( d, this ), Dependency::getDelegate );
145 }
146
147 public void setDependencies( List<Dependency> dependencies )
148 {
149 if ( !Objects.equals( dependencies, getDelegate().getDependencies() ) )
150 {
151 update( getDelegate().withDependencies(
152 dependencies.stream().map( c -> c.getDelegate() ).collect( Collectors.toList() ) ) );
153 dependencies.forEach( e -> e.childrenTracking = this::replace );
154 }
155 }
156
157 public void addDependency( Dependency dependency )
158 {
159 update( getDelegate().withDependencies(
160 Stream.concat( getDelegate().getDependencies().stream(), Stream.of( dependency.getDelegate() ) )
161 .collect( Collectors.toList() ) ) );
162 dependency.childrenTracking = this::replace;
163 }
164
165 public void removeDependency( Dependency dependency )
166 {
167 update( getDelegate().withDependencies(
168 getDelegate().getDependencies().stream()
169 .filter( e -> !Objects.equals( e, dependency ) )
170 .collect( Collectors.toList() ) ) );
171 dependency.childrenTracking = null;
172 }
173
174 public InputLocation getLocation( Object key )
175 {
176 org.apache.maven.api.model.InputLocation loc = getDelegate().getLocation( key );
177 return loc != null ? new InputLocation( loc ) : null;
178 }
179
180 public void setLocation( Object key, InputLocation location )
181 {
182 update( org.apache.maven.api.model.Plugin.newBuilder( getDelegate(), true )
183 .location( key, location.toApiLocation() ).build() );
184 }
185
186 protected boolean replace( Object oldDelegate, Object newDelegate )
187 {
188 if ( super.replace( oldDelegate, newDelegate ) )
189 {
190 return true;
191 }
192 if ( getDelegate().getExecutions().contains( oldDelegate ) )
193 {
194 List<org.apache.maven.api.model.PluginExecution> list = new ArrayList<>( getDelegate().getExecutions() );
195 list.replaceAll( d -> d == oldDelegate ? ( org.apache.maven.api.model.PluginExecution ) newDelegate : d );
196 update( getDelegate().withExecutions( list ) );
197 return true;
198 }
199 if ( getDelegate().getDependencies().contains( oldDelegate ) )
200 {
201 List<org.apache.maven.api.model.Dependency> list = new ArrayList<>( getDelegate().getDependencies() );
202 list.replaceAll( d -> d == oldDelegate ? ( org.apache.maven.api.model.Dependency ) newDelegate : d );
203 update( getDelegate().withDependencies( list ) );
204 return true;
205 }
206 return false;
207 }
208
209 public static List<org.apache.maven.api.model.Plugin> pluginToApiV4( List<Plugin> list )
210 {
211 return list != null ? new WrapperList<>( list, Plugin::getDelegate, Plugin::new ) : null;
212 }
213
214 public static List<Plugin> pluginToApiV3( List<org.apache.maven.api.model.Plugin> list )
215 {
216 return list != null ? new WrapperList<>( list, Plugin::new, Plugin::getDelegate ) : null;
217 }
218
219
220
221 public boolean isExtensions()
222 {
223 return ( getExtensions() != null ) ? Boolean.parseBoolean( getExtensions() ) : false;
224 }
225
226
227
228
229 public void setExtensions( boolean extensions )
230 {
231 setExtensions( String.valueOf( extensions ) );
232 }
233
234
235
236
237 private java.util.Map<String, PluginExecution> executionMap = null;
238
239
240
241
242 public void flushExecutionMap()
243 {
244 this.executionMap = null;
245 }
246
247
248
249
250 public java.util.Map<String, PluginExecution> getExecutionsAsMap()
251 {
252 if ( executionMap == null )
253 {
254 executionMap = new java.util.LinkedHashMap<String, PluginExecution>();
255 for ( java.util.Iterator<PluginExecution> i = getExecutions().iterator(); i.hasNext(); )
256 {
257 PluginExecution exec = (PluginExecution) i.next();
258 if ( executionMap.containsKey( exec.getId() ) )
259 {
260 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" );
261 }
262 executionMap.put( exec.getId(), exec );
263 }
264 }
265 return executionMap;
266 }
267
268
269
270
271
272
273 public String getId()
274 {
275 StringBuilder id = new StringBuilder( 128 );
276
277 id.append( ( getGroupId() == null ) ? "[unknown-group-id]" : getGroupId() );
278 id.append( ":" );
279 id.append( ( getArtifactId() == null ) ? "[unknown-artifact-id]" : getArtifactId() );
280 id.append( ":" );
281 id.append( ( getVersion() == null ) ? "[unknown-version]" : getVersion() );
282
283 return id.toString();
284 }
285
286
287
288
289 public String getKey()
290 {
291 return constructKey( getGroupId(), getArtifactId() );
292 }
293
294
295
296
297
298
299 public static String constructKey( String groupId, String artifactId )
300 {
301 return groupId + ":" + artifactId;
302 }
303
304
305
306
307 public boolean equals( Object other )
308 {
309 if ( other instanceof Plugin )
310 {
311 Plugin otherPlugin = (Plugin) other;
312
313 return getKey().equals( otherPlugin.getKey() );
314 }
315
316 return false;
317 }
318
319
320
321
322 public int hashCode()
323 {
324 return getKey().hashCode();
325 }
326
327
328
329
330 public String toString()
331 {
332 return "Plugin [" + getKey() + "]";
333 }
334
335
336 }