View Javadoc

1   /*
2    =================== DO NOT EDIT THIS FILE ====================
3    Generated by Modello 1.4.1 on 2012-09-02 23:20:49,
4    any modifications will be overwritten.
5    ==============================================================
6    */
7   
8   package org.apache.maven.artifact.repository.metadata;
9   
10  /**
11   * Class Metadata.
12   * 
13   * @version $Revision$ $Date$
14   */
15  @SuppressWarnings( "all" )
16  public class Metadata
17      implements java.io.Serializable, java.lang.Cloneable
18  {
19  
20        //--------------------------/
21       //- Class/Member Variables -/
22      //--------------------------/
23  
24      /**
25       * The version of the underlying metadata model.
26       */
27      private String modelVersion;
28  
29      /**
30       * The groupId that this directory represents, if any.
31       */
32      private String groupId;
33  
34      /**
35       * The artifactId that this directory represents, if any.
36       */
37      private String artifactId;
38  
39      /**
40       * The version that this directory represents, if any.
41       */
42      private String version;
43  
44      /**
45       * Versioning information for the artifact.
46       */
47      private Versioning versioning;
48  
49      /**
50       * Field plugins.
51       */
52      private java.util.List<Plugin> plugins;
53  
54      /**
55       * Field modelEncoding.
56       */
57      private String modelEncoding = "UTF-8";
58  
59  
60        //-----------/
61       //- Methods -/
62      //-----------/
63  
64      /**
65       * Method addPlugin.
66       * 
67       * @param plugin
68       */
69      public void addPlugin( Plugin plugin )
70      {
71          getPlugins().add( plugin );
72      } //-- void addPlugin( Plugin )
73  
74      /**
75       * Method clone.
76       * 
77       * @return Metadata
78       */
79      public Metadata clone()
80      {
81          try
82          {
83              Metadata copy = (Metadata) super.clone();
84  
85              if ( this.versioning != null )
86              {
87                  copy.versioning = (Versioning) this.versioning.clone();
88              }
89  
90              if ( this.plugins != null )
91              {
92                  copy.plugins = new java.util.ArrayList<Plugin>();
93                  for ( Plugin item : this.plugins )
94                  {
95                      copy.plugins.add( ( (Plugin) item).clone() );
96                  }
97              }
98  
99              return copy;
100         }
101         catch ( java.lang.Exception ex )
102         {
103             throw (java.lang.RuntimeException) new java.lang.UnsupportedOperationException( getClass().getName()
104                 + " does not support clone()" ).initCause( ex );
105         }
106     } //-- Metadata clone()
107 
108     /**
109      * Get the artifactId that this directory represents, if any.
110      * 
111      * @return String
112      */
113     public String getArtifactId()
114     {
115         return this.artifactId;
116     } //-- String getArtifactId()
117 
118     /**
119      * Get the groupId that this directory represents, if any.
120      * 
121      * @return String
122      */
123     public String getGroupId()
124     {
125         return this.groupId;
126     } //-- String getGroupId()
127 
128     /**
129      * Get the modelEncoding field.
130      * 
131      * @return String
132      */
133     public String getModelEncoding()
134     {
135         return this.modelEncoding;
136     } //-- String getModelEncoding()
137 
138     /**
139      * Get the version of the underlying metadata model.
140      * 
141      * @return String
142      */
143     public String getModelVersion()
144     {
145         return this.modelVersion;
146     } //-- String getModelVersion()
147 
148     /**
149      * Method getPlugins.
150      * 
151      * @return List
152      */
153     public java.util.List<Plugin> getPlugins()
154     {
155         if ( this.plugins == null )
156         {
157             this.plugins = new java.util.ArrayList<Plugin>();
158         }
159 
160         return this.plugins;
161     } //-- java.util.List<Plugin> getPlugins()
162 
163     /**
164      * Get the version that this directory represents, if any.
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.
246      * 
247      * @param version
248      */
249     public void setVersion( String version )
250     {
251         this.version = version;
252     } //-- void setVersion( String )
253 
254     /**
255      * Set versioning information for the artifact.
256      * 
257      * @param versioning
258      */
259     public void setVersioning( Versioning versioning )
260     {
261         this.versioning = versioning;
262     } //-- void setVersioning( Versioning )
263 
264     
265     public boolean merge( Metadata sourceMetadata )
266     {
267         boolean changed = false;
268 
269         for ( Plugin plugin : sourceMetadata.getPlugins() )
270         {
271             boolean found = false;
272 
273             for ( Plugin preExisting : getPlugins() )
274             {
275                 if ( preExisting.getPrefix().equals( plugin.getPrefix() ) )
276                 {
277                     found = true;
278                     break;
279                 }
280             }
281 
282             if ( !found )
283             {
284                 Plugin mappedPlugin = new Plugin();
285 
286                 mappedPlugin.setArtifactId( plugin.getArtifactId() );
287 
288                 mappedPlugin.setPrefix( plugin.getPrefix() );
289 
290                 mappedPlugin.setName( plugin.getName() );
291 
292                 addPlugin( mappedPlugin );
293 
294                 changed = true;
295             }
296         }
297 
298         Versioning versioning = sourceMetadata.getVersioning();
299         if ( versioning != null )
300         {
301             Versioning v = getVersioning();
302             if ( v == null )
303             {
304                 v = new Versioning();
305                 setVersioning( v );
306                 changed = true;
307             }
308 
309             for ( String version : versioning.getVersions() )
310             {
311                 if ( !v.getVersions().contains( version ) )
312                 {
313                     changed = true;
314                     v.getVersions().add( version );
315                 }
316             }
317 
318             if ( "null".equals( versioning.getLastUpdated() ) )
319             {
320                 versioning.setLastUpdated( null );
321             }
322 
323             if ( "null".equals( v.getLastUpdated() ) )
324             {
325                 v.setLastUpdated( null );
326             }
327 
328             if ( versioning.getLastUpdated() == null || versioning.getLastUpdated().length() == 0 )
329             {
330                 // this should only be for historical reasons - we assume local is newer
331                 versioning.setLastUpdated( v.getLastUpdated() );
332             }
333 
334             if ( v.getLastUpdated() == null || v.getLastUpdated().length() == 0
335                  || versioning.getLastUpdated().compareTo( v.getLastUpdated() ) >= 0 )
336             {
337                 changed = true;
338                 v.setLastUpdated( versioning.getLastUpdated() );
339 
340                 if ( versioning.getRelease() != null )
341                 {
342                     changed = true;
343                     v.setRelease( versioning.getRelease() );
344                 }
345                 if ( versioning.getLatest() != null )
346                 {
347                     changed = true;
348                     v.setLatest( versioning.getLatest() );
349                 }
350 
351                 Snapshot s = v.getSnapshot();
352                 Snapshot snapshot = versioning.getSnapshot();
353                 if ( snapshot != null )
354                 {
355                     if ( s == null )
356                     {
357                         s = new Snapshot();
358                         v.setSnapshot( s );
359                         changed = true;
360                     }
361 
362                     // overwrite
363                     if ( s.getTimestamp() == null ? snapshot.getTimestamp() != null
364                         : !s.getTimestamp().equals( snapshot.getTimestamp() ) )
365                     {
366                         s.setTimestamp( snapshot.getTimestamp() );
367                         changed = true;
368                     }
369                     if ( s.getBuildNumber() != snapshot.getBuildNumber() )
370                     {
371                         s.setBuildNumber( snapshot.getBuildNumber() );
372                         changed = true;
373                     }
374                     if ( s.isLocalCopy() != snapshot.isLocalCopy() )
375                     {
376                         s.setLocalCopy( snapshot.isLocalCopy() );
377                         changed = true;
378                     }
379                 }
380             }
381         }
382         return changed;
383     }
384           
385 }