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