1
2
3
4
5
6
7
8 package org.apache.maven.artifact.repository.metadata;
9
10
11
12
13
14
15 public class Metadata
16 implements java.io.Serializable
17 {
18
19
20
21
22
23
24
25
26 private String groupId;
27
28
29
30
31 private String artifactId;
32
33
34
35
36 private String version;
37
38
39
40
41 private Versioning versioning;
42
43
44
45
46 private java.util.List<Plugin> plugins;
47
48
49
50
51 private String modelEncoding = "UTF-8";
52
53
54
55
56
57
58
59
60
61
62
63 public void addPlugin( Plugin plugin )
64 {
65 if ( !(plugin instanceof Plugin) )
66 {
67 throw new ClassCastException( "Metadata.addPlugins(plugin) parameter must be instanceof " + Plugin.class.getName() );
68 }
69 getPlugins().add( plugin );
70 }
71
72
73
74
75
76
77 public String getArtifactId()
78 {
79 return this.artifactId;
80 }
81
82
83
84
85
86
87 public String getGroupId()
88 {
89 return this.groupId;
90 }
91
92
93
94
95
96
97
98 public String getModelEncoding()
99 {
100 return modelEncoding;
101 }
102
103
104
105
106
107
108 public java.util.List<Plugin> getPlugins()
109 {
110 if ( this.plugins == null )
111 {
112 this.plugins = new java.util.ArrayList<Plugin>();
113 }
114
115 return this.plugins;
116 }
117
118
119
120
121
122
123 public String getVersion()
124 {
125 return this.version;
126 }
127
128
129
130
131
132
133 public Versioning getVersioning()
134 {
135 return this.versioning;
136 }
137
138
139
140
141
142
143 public void removePlugin( Plugin plugin )
144 {
145 if ( !(plugin instanceof Plugin) )
146 {
147 throw new ClassCastException( "Metadata.removePlugins(plugin) parameter must be instanceof " + Plugin.class.getName() );
148 }
149 getPlugins().remove( plugin );
150 }
151
152
153
154
155
156
157 public void setArtifactId( String artifactId )
158 {
159 this.artifactId = artifactId;
160 }
161
162
163
164
165
166
167 public void setGroupId( String groupId )
168 {
169 this.groupId = groupId;
170 }
171
172
173
174
175
176
177 public void setModelEncoding( String modelEncoding )
178 {
179 this.modelEncoding = modelEncoding;
180 }
181
182
183
184
185
186
187 public void setPlugins( java.util.List<Plugin> plugins )
188 {
189 this.plugins = plugins;
190 }
191
192
193
194
195
196
197 public void setVersion( String version )
198 {
199 this.version = version;
200 }
201
202
203
204
205
206
207 public void setVersioning( Versioning versioning )
208 {
209 this.versioning = versioning;
210 }
211
212
213 public boolean merge( Metadata sourceMetadata )
214 {
215 boolean changed = false;
216
217 for ( java.util.Iterator i = sourceMetadata.getPlugins().iterator(); i.hasNext(); )
218 {
219 Plugin plugin = (Plugin) i.next();
220 boolean found = false;
221
222 for ( java.util.Iterator it = getPlugins().iterator(); it.hasNext() && !found; )
223 {
224 Plugin preExisting = (Plugin) it.next();
225
226 if ( preExisting.getPrefix().equals( plugin.getPrefix() ) )
227 {
228 found = true;
229 }
230 }
231
232 if ( !found )
233 {
234 Plugin mappedPlugin = new Plugin();
235
236 mappedPlugin.setArtifactId( plugin.getArtifactId() );
237
238 mappedPlugin.setPrefix( plugin.getPrefix() );
239
240 mappedPlugin.setName( plugin.getName() );
241
242 addPlugin( mappedPlugin );
243
244 changed = true;
245 }
246 }
247
248 Versioning versioning = sourceMetadata.getVersioning();
249 if ( versioning != null )
250 {
251 Versioning v = getVersioning();
252 if ( v == null )
253 {
254 v = new Versioning();
255 setVersioning( v );
256 changed = true;
257 }
258
259 for ( java.util.Iterator i = versioning.getVersions().iterator(); i.hasNext(); )
260 {
261 String version = (String) i.next();
262 if ( !v.getVersions().contains( version ) )
263 {
264 changed = true;
265 v.getVersions().add( version );
266 }
267 }
268
269 if ( "null".equals( versioning.getLastUpdated() ) )
270 {
271 versioning.setLastUpdated( null );
272 }
273
274 if ( "null".equals( v.getLastUpdated() ) )
275 {
276 v.setLastUpdated( null );
277 }
278
279 if ( versioning.getLastUpdated() == null || versioning.getLastUpdated().length() == 0 )
280 {
281
282 versioning.setLastUpdated( v.getLastUpdated() );
283 }
284
285 if ( v.getLastUpdated() == null || v.getLastUpdated().length() == 0 ||
286 versioning.getLastUpdated().compareTo( v.getLastUpdated() ) >= 0 )
287 {
288 changed = true;
289 v.setLastUpdated( versioning.getLastUpdated() );
290
291 if ( versioning.getRelease() != null )
292 {
293 changed = true;
294 v.setRelease( versioning.getRelease() );
295 }
296 if ( versioning.getLatest() != null )
297 {
298 changed = true;
299 v.setLatest( versioning.getLatest() );
300 }
301
302 Snapshot s = v.getSnapshot();
303 Snapshot snapshot = versioning.getSnapshot();
304 if ( snapshot != null )
305 {
306 if ( s == null )
307 {
308 s = new Snapshot();
309 v.setSnapshot( s );
310 changed = true;
311 }
312
313
314 if ( s.getTimestamp() == null ? snapshot.getTimestamp() != null
315 : !s.getTimestamp().equals( snapshot.getTimestamp() ) )
316 {
317 s.setTimestamp( snapshot.getTimestamp() );
318 changed = true;
319 }
320 if ( s.getBuildNumber() != snapshot.getBuildNumber() )
321 {
322 s.setBuildNumber( snapshot.getBuildNumber() );
323 changed = true;
324 }
325 if ( s.isLocalCopy() != snapshot.isLocalCopy() )
326 {
327 s.setLocalCopy( snapshot.isLocalCopy() );
328 changed = true;
329 }
330 }
331 }
332 }
333 return changed;
334 }
335
336 }