1
2
3
4
5
6 package org.apache.maven.artifact.repository.metadata;
7
8
9
10
11
12
13 @SuppressWarnings( "all" )
14 public class Metadata
15 implements java.io.Serializable, java.lang.Cloneable
16 {
17
18
19
20
21
22
23
24
25 private String modelVersion;
26
27
28
29
30
31 private String groupId;
32
33
34
35
36
37 private String artifactId;
38
39
40
41
42
43 private Versioning versioning;
44
45
46
47
48
49
50 private String version;
51
52
53
54
55 @Deprecated
56 private java.util.List<Plugin> plugins;
57
58
59
60
61 private String modelEncoding = "UTF-8";
62
63
64
65
66
67
68
69
70
71
72
73 public void addPlugin( Plugin plugin )
74 {
75 getPlugins().add( plugin );
76 }
77
78
79
80
81
82
83 public Metadata clone()
84 {
85 try
86 {
87 Metadata copy = (Metadata) super.clone();
88
89 if ( this.versioning != null )
90 {
91 copy.versioning = (Versioning) this.versioning.clone();
92 }
93
94 if ( this.plugins != null )
95 {
96 copy.plugins = new java.util.ArrayList<Plugin>();
97 for ( Plugin item : this.plugins )
98 {
99 copy.plugins.add( ( (Plugin) item).clone() );
100 }
101 }
102
103 return copy;
104 }
105 catch ( java.lang.Exception ex )
106 {
107 throw (java.lang.RuntimeException) new java.lang.UnsupportedOperationException( getClass().getName()
108 + " does not support clone()" ).initCause( ex );
109 }
110 }
111
112
113
114
115
116
117
118 public String getArtifactId()
119 {
120 return this.artifactId;
121 }
122
123
124
125
126
127
128
129 public String getGroupId()
130 {
131 return this.groupId;
132 }
133
134
135
136
137
138
139 public String getModelEncoding()
140 {
141 return this.modelEncoding;
142 }
143
144
145
146
147
148
149 public String getModelVersion()
150 {
151 return this.modelVersion;
152 }
153
154
155
156
157
158
159 public java.util.List<Plugin> getPlugins()
160 {
161 if ( this.plugins == null )
162 {
163 this.plugins = new java.util.ArrayList<Plugin>();
164 }
165
166 return this.plugins;
167 }
168
169
170
171
172
173
174
175
176 public String getVersion()
177 {
178 return this.version;
179 }
180
181
182
183
184
185
186
187 public Versioning getVersioning()
188 {
189 return this.versioning;
190 }
191
192
193
194
195
196
197 public void removePlugin( Plugin plugin )
198 {
199 getPlugins().remove( plugin );
200 }
201
202
203
204
205
206
207
208 public void setArtifactId( String artifactId )
209 {
210 this.artifactId = artifactId;
211 }
212
213
214
215
216
217
218
219 public void setGroupId( String groupId )
220 {
221 this.groupId = groupId;
222 }
223
224
225
226
227
228
229 public void setModelEncoding( String modelEncoding )
230 {
231 this.modelEncoding = modelEncoding;
232 }
233
234
235
236
237
238
239 public void setModelVersion( String modelVersion )
240 {
241 this.modelVersion = modelVersion;
242 }
243
244
245
246
247
248
249
250 public void setPlugins( java.util.List<Plugin> plugins )
251 {
252 this.plugins = plugins;
253 }
254
255
256
257
258
259
260
261
262 public void setVersion( String version )
263 {
264 this.version = version;
265 }
266
267
268
269
270
271
272
273 public void setVersioning( Versioning versioning )
274 {
275 this.versioning = versioning;
276 }
277
278
279 private String getSnapshotVersionKey( SnapshotVersion sv )
280 {
281 return sv.getClassifier() + ":" + sv.getExtension();
282 }
283
284 public boolean merge( Metadata sourceMetadata )
285 {
286 boolean changed = false;
287
288 for ( Plugin plugin : sourceMetadata.getPlugins() )
289 {
290 boolean found = false;
291
292 for ( Plugin preExisting : getPlugins() )
293 {
294 if ( preExisting.getPrefix().equals( plugin.getPrefix() ) )
295 {
296 found = true;
297 break;
298 }
299 }
300
301 if ( !found )
302 {
303 Plugin mappedPlugin = new Plugin();
304
305 mappedPlugin.setArtifactId( plugin.getArtifactId() );
306
307 mappedPlugin.setPrefix( plugin.getPrefix() );
308
309 mappedPlugin.setName( plugin.getName() );
310
311 addPlugin( mappedPlugin );
312
313 changed = true;
314 }
315 }
316
317 Versioning versioning = sourceMetadata.getVersioning();
318 if ( versioning != null )
319 {
320 Versioning v = getVersioning();
321 if ( v == null )
322 {
323 v = new Versioning();
324 setVersioning( v );
325 changed = true;
326 }
327
328 for ( String version : versioning.getVersions() )
329 {
330 if ( !v.getVersions().contains( version ) )
331 {
332 changed = true;
333 v.getVersions().add( version );
334 }
335 }
336
337 if ( "null".equals( versioning.getLastUpdated() ) )
338 {
339 versioning.setLastUpdated( null );
340 }
341
342 if ( "null".equals( v.getLastUpdated() ) )
343 {
344 v.setLastUpdated( null );
345 }
346
347 if ( versioning.getLastUpdated() == null || versioning.getLastUpdated().length() == 0 )
348 {
349
350 versioning.setLastUpdated( v.getLastUpdated() );
351 }
352
353 if ( v.getLastUpdated() == null || v.getLastUpdated().length() == 0
354 || versioning.getLastUpdated().compareTo( v.getLastUpdated() ) >= 0 )
355 {
356 changed = true;
357 v.setLastUpdated( versioning.getLastUpdated() );
358
359 if ( versioning.getRelease() != null )
360 {
361 changed = true;
362 v.setRelease( versioning.getRelease() );
363 }
364 if ( versioning.getLatest() != null )
365 {
366 changed = true;
367 v.setLatest( versioning.getLatest() );
368 }
369
370 Snapshot s = v.getSnapshot();
371 Snapshot snapshot = versioning.getSnapshot();
372 if ( snapshot != null )
373 {
374 boolean updateSnapshotVersions = false;
375 if ( s == null )
376 {
377 s = new Snapshot();
378 v.setSnapshot( s );
379 changed = true;
380 updateSnapshotVersions = true;
381 }
382
383
384 if ( s.getTimestamp() == null ? snapshot.getTimestamp() != null
385 : !s.getTimestamp().equals( snapshot.getTimestamp() ) )
386 {
387 s.setTimestamp( snapshot.getTimestamp() );
388 changed = true;
389 updateSnapshotVersions = true;
390 }
391 if ( s.getBuildNumber() != snapshot.getBuildNumber() )
392 {
393 s.setBuildNumber( snapshot.getBuildNumber() );
394 changed = true;
395 }
396 if ( s.isLocalCopy() != snapshot.isLocalCopy() )
397 {
398 s.setLocalCopy( snapshot.isLocalCopy() );
399 changed = true;
400 }
401 if ( updateSnapshotVersions )
402 {
403 java.util.Map<String, SnapshotVersion> versions = new java.util.LinkedHashMap<>();
404
405 if ( !v.getSnapshotVersions().isEmpty() )
406 {
407 for ( SnapshotVersion sv : versioning.getSnapshotVersions() )
408 {
409 String key = getSnapshotVersionKey( sv );
410 versions.put( key, sv );
411 }
412
413 if ( !versions.isEmpty() )
414 {
415 for ( SnapshotVersion sv : v.getSnapshotVersions() )
416 {
417 String key = getSnapshotVersionKey( sv );
418 if ( !versions.containsKey( key ) )
419 {
420 versions.put( key, sv );
421 }
422 }
423 }
424 v.setSnapshotVersions( new java.util.ArrayList<SnapshotVersion>( versions.values() ) );
425 }
426
427 changed = true;
428 }
429 }
430 }
431 }
432 return changed;
433 }
434
435 }