View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 1.8.3,
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: 965443 $ $Date: 2015-09-14 22:18:52 +0000 (Mon, 14 Sep 2015) $
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 that this directory represents, if any.
29       */
30      private String groupId;
31  
32      /**
33       * The artifactId that this directory represents, if any.
34       */
35      private String artifactId;
36  
37      /**
38       * The version that this directory represents, if any. It is
39       * used for artifact snapshots only.
40       */
41      private String version;
42  
43      /**
44       * Versioning information for the artifact.
45       */
46      private Versioning versioning;
47  
48      /**
49       * Field plugins.
50       */
51      private java.util.List<Plugin> plugins;
52  
53      /**
54       * Field modelEncoding.
55       */
56      private String modelEncoding = "UTF-8";
57  
58  
59        //-----------/
60       //- Methods -/
61      //-----------/
62  
63      /**
64       * Method addPlugin.
65       * 
66       * @param plugin
67       */
68      public void addPlugin( Plugin plugin )
69      {
70          getPlugins().add( plugin );
71      } //-- void addPlugin( Plugin )
72  
73      /**
74       * Method clone.
75       * 
76       * @return Metadata
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     } //-- Metadata clone()
106 
107     /**
108      * Get the artifactId that this directory represents, if any.
109      * 
110      * @return String
111      */
112     public String getArtifactId()
113     {
114         return this.artifactId;
115     } //-- String getArtifactId()
116 
117     /**
118      * Get the groupId that this directory represents, if any.
119      * 
120      * @return String
121      */
122     public String getGroupId()
123     {
124         return this.groupId;
125     } //-- String getGroupId()
126 
127     /**
128      * Get the modelEncoding field.
129      * 
130      * @return String
131      */
132     public String getModelEncoding()
133     {
134         return this.modelEncoding;
135     } //-- String getModelEncoding()
136 
137     /**
138      * Get the version of the underlying metadata model.
139      * 
140      * @return String
141      */
142     public String getModelVersion()
143     {
144         return this.modelVersion;
145     } //-- String getModelVersion()
146 
147     /**
148      * Method getPlugins.
149      * 
150      * @return List
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     } //-- java.util.List<Plugin> getPlugins()
161 
162     /**
163      * Get the version that this directory represents, if any. It
164      * is used for artifact snapshots only.
165      * 
166      * @return String
167      */
168     public String getVersion()
169     {
170         return this.version;
171     } //-- String getVersion()
172 
173     /**
174      * Get versioning information for the artifact.
175      * 
176      * @return Versioning
177      */
178     public Versioning getVersioning()
179     {
180         return this.versioning;
181     } //-- Versioning getVersioning()
182 
183     /**
184      * Method removePlugin.
185      * 
186      * @param plugin
187      */
188     public void removePlugin( Plugin plugin )
189     {
190         getPlugins().remove( plugin );
191     } //-- void removePlugin( Plugin )
192 
193     /**
194      * Set the artifactId that this directory represents, if any.
195      * 
196      * @param artifactId
197      */
198     public void setArtifactId( String artifactId )
199     {
200         this.artifactId = artifactId;
201     } //-- void setArtifactId( String )
202 
203     /**
204      * Set the groupId that this directory represents, if any.
205      * 
206      * @param groupId
207      */
208     public void setGroupId( String groupId )
209     {
210         this.groupId = groupId;
211     } //-- void setGroupId( String )
212 
213     /**
214      * Set the modelEncoding field.
215      * 
216      * @param modelEncoding
217      */
218     public void setModelEncoding( String modelEncoding )
219     {
220         this.modelEncoding = modelEncoding;
221     } //-- void setModelEncoding( String )
222 
223     /**
224      * Set the version of the underlying metadata model.
225      * 
226      * @param modelVersion
227      */
228     public void setModelVersion( String modelVersion )
229     {
230         this.modelVersion = modelVersion;
231     } //-- void setModelVersion( String )
232 
233     /**
234      * Set the set of plugin mappings for the group represented by
235      * this directory.
236      * 
237      * @param plugins
238      */
239     public void setPlugins( java.util.List<Plugin> plugins )
240     {
241         this.plugins = plugins;
242     } //-- void setPlugins( java.util.List )
243 
244     /**
245      * Set the version that this directory represents, if any. It
246      * is used for artifact snapshots only.
247      * 
248      * @param version
249      */
250     public void setVersion( String version )
251     {
252         this.version = version;
253     } //-- void setVersion( String )
254 
255     /**
256      * Set versioning information for the artifact.
257      * 
258      * @param versioning
259      */
260     public void setVersioning( Versioning versioning )
261     {
262         this.versioning = versioning;
263     } //-- void setVersioning( Versioning )
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                 // this should only be for historical reasons - we assume local is newer
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                     // overwrite
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 }