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