View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 1.11,
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      @Deprecated
56      private java.util.List<Plugin> plugins;
57  
58      /**
59       * Field modelEncoding.
60       */
61      private String modelEncoding = "UTF-8";
62  
63  
64        //-----------/
65       //- Methods -/
66      //-----------/
67  
68      /**
69       * Method addPlugin.
70       * 
71       * @param plugin
72       */
73      public void addPlugin( Plugin plugin )
74      {
75          getPlugins().add( plugin );
76      } //-- void addPlugin( Plugin )
77  
78      /**
79       * Method clone.
80       * 
81       * @return Metadata
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     } //-- Metadata clone()
111 
112     /**
113      * Get the artifactId when this directory represents
114      * "groupId/artifactId" or "groupId/artifactId/version".
115      * 
116      * @return String
117      */
118     public String getArtifactId()
119     {
120         return this.artifactId;
121     } //-- String getArtifactId()
122 
123     /**
124      * Get the groupId when this directory represents
125      * "groupId/artifactId" or "groupId/artifactId/version".
126      * 
127      * @return String
128      */
129     public String getGroupId()
130     {
131         return this.groupId;
132     } //-- String getGroupId()
133 
134     /**
135      * Get the modelEncoding field.
136      * 
137      * @return String
138      */
139     public String getModelEncoding()
140     {
141         return this.modelEncoding;
142     } //-- String getModelEncoding()
143 
144     /**
145      * Get the version of the underlying metadata model.
146      * 
147      * @return String
148      */
149     public String getModelVersion()
150     {
151         return this.modelVersion;
152     } //-- String getModelVersion()
153 
154     /**
155      * Method getPlugins.
156      * 
157      * @return List
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     } //-- java.util.List<Plugin> getPlugins()
168 
169     /**
170      * Get the base version (ie. ending in <code>-SNAPSHOT</code>)
171      * when this directory represents a
172      * "groupId/artifactId/version" for a SNAPSHOT.
173      * 
174      * @return String
175      */
176     public String getVersion()
177     {
178         return this.version;
179     } //-- String getVersion()
180 
181     /**
182      * Get versioning information when this directory represents
183      * "groupId/artifactId" or "groupId/artifactId/version".
184      * 
185      * @return Versioning
186      */
187     public Versioning getVersioning()
188     {
189         return this.versioning;
190     } //-- Versioning getVersioning()
191 
192     /**
193      * Method removePlugin.
194      * 
195      * @param plugin
196      */
197     public void removePlugin( Plugin plugin )
198     {
199         getPlugins().remove( plugin );
200     } //-- void removePlugin( Plugin )
201 
202     /**
203      * Set the artifactId when this directory represents
204      * "groupId/artifactId" or "groupId/artifactId/version".
205      * 
206      * @param artifactId
207      */
208     public void setArtifactId( String artifactId )
209     {
210         this.artifactId = artifactId;
211     } //-- void setArtifactId( String )
212 
213     /**
214      * Set the groupId when this directory represents
215      * "groupId/artifactId" or "groupId/artifactId/version".
216      * 
217      * @param groupId
218      */
219     public void setGroupId( String groupId )
220     {
221         this.groupId = groupId;
222     } //-- void setGroupId( String )
223 
224     /**
225      * Set the modelEncoding field.
226      * 
227      * @param modelEncoding
228      */
229     public void setModelEncoding( String modelEncoding )
230     {
231         this.modelEncoding = modelEncoding;
232     } //-- void setModelEncoding( String )
233 
234     /**
235      * Set the version of the underlying metadata model.
236      * 
237      * @param modelVersion
238      */
239     public void setModelVersion( String modelVersion )
240     {
241         this.modelVersion = modelVersion;
242     } //-- void setModelVersion( String )
243 
244     /**
245      * Set the set of plugins when this directory represents a
246      * "groupId" (deprecated).
247      * 
248      * @param plugins
249      */
250     public void setPlugins( java.util.List<Plugin> plugins )
251     {
252         this.plugins = plugins;
253     } //-- void setPlugins( java.util.List )
254 
255     /**
256      * Set the base version (ie. ending in <code>-SNAPSHOT</code>)
257      * when this directory represents a
258      * "groupId/artifactId/version" for a SNAPSHOT.
259      * 
260      * @param version
261      */
262     public void setVersion( String version )
263     {
264         this.version = version;
265     } //-- void setVersion( String )
266 
267     /**
268      * Set versioning information when this directory represents
269      * "groupId/artifactId" or "groupId/artifactId/version".
270      * 
271      * @param versioning
272      */
273     public void setVersioning( Versioning versioning )
274     {
275         this.versioning = versioning;
276     } //-- void setVersioning( Versioning )
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                 // this should only be for historical reasons - we assume local is newer
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                     // overwrite
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                         // never convert from legacy to new format if either source or target is legacy format
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                             // never convert from legacy format
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 }