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