View Javadoc

1   /*
2    =================== DO NOT EDIT THIS FILE ====================
3    Generated by Modello 1.0.1 on 2009-09-09 03:30:24,
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  public class Metadata
16      implements java.io.Serializable
17  {
18  
19        //--------------------------/
20       //- Class/Member Variables -/
21      //--------------------------/
22  
23      /**
24       * The groupId that this directory represents, if any.
25       */
26      private String groupId;
27  
28      /**
29       * The artifactId that this directory represents, if any.
30       */
31      private String artifactId;
32  
33      /**
34       * The version that this directory represents, if any.
35       */
36      private String version;
37  
38      /**
39       * Versioning information for the artifact.
40       */
41      private Versioning versioning;
42  
43      /**
44       * Field plugins.
45       */
46      private java.util.List<Plugin> plugins;
47  
48      /**
49       * Field modelEncoding.
50       */
51      private String modelEncoding = "UTF-8";
52  
53  
54        //-----------/
55       //- Methods -/
56      //-----------/
57  
58      /**
59       * Method addPlugin.
60       * 
61       * @param plugin
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      } //-- void addPlugin( Plugin )
71  
72      /**
73       * Get the artifactId that this directory represents, if any.
74       * 
75       * @return String
76       */
77      public String getArtifactId()
78      {
79          return this.artifactId;
80      } //-- String getArtifactId()
81  
82      /**
83       * Get the groupId that this directory represents, if any.
84       * 
85       * @return String
86       */
87      public String getGroupId()
88      {
89          return this.groupId;
90      } //-- String getGroupId()
91  
92      /**
93       * Method getModelEncoding.
94       * 
95       * @return the current encoding used when reading/writing this
96       * model
97       */
98      public String getModelEncoding()
99      {
100         return modelEncoding;
101     } //-- String getModelEncoding()
102 
103     /**
104      * Method getPlugins.
105      * 
106      * @return List
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     } //-- java.util.List<Plugin> getPlugins()
117 
118     /**
119      * Get the version that this directory represents, if any.
120      * 
121      * @return String
122      */
123     public String getVersion()
124     {
125         return this.version;
126     } //-- String getVersion()
127 
128     /**
129      * Get versioning information for the artifact.
130      * 
131      * @return Versioning
132      */
133     public Versioning getVersioning()
134     {
135         return this.versioning;
136     } //-- Versioning getVersioning()
137 
138     /**
139      * Method removePlugin.
140      * 
141      * @param plugin
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     } //-- void removePlugin( Plugin )
151 
152     /**
153      * Set the artifactId that this directory represents, if any.
154      * 
155      * @param artifactId
156      */
157     public void setArtifactId( String artifactId )
158     {
159         this.artifactId = artifactId;
160     } //-- void setArtifactId( String )
161 
162     /**
163      * Set the groupId that this directory represents, if any.
164      * 
165      * @param groupId
166      */
167     public void setGroupId( String groupId )
168     {
169         this.groupId = groupId;
170     } //-- void setGroupId( String )
171 
172     /**
173      * Set an encoding used for reading/writing the model.
174      * 
175      * @param modelEncoding
176      */
177     public void setModelEncoding( String modelEncoding )
178     {
179         this.modelEncoding = modelEncoding;
180     } //-- void setModelEncoding( String )
181 
182     /**
183      * Set the set of plugin mappings for the group.
184      * 
185      * @param plugins
186      */
187     public void setPlugins( java.util.List<Plugin> plugins )
188     {
189         this.plugins = plugins;
190     } //-- void setPlugins( java.util.List )
191 
192     /**
193      * Set the version that this directory represents, if any.
194      * 
195      * @param version
196      */
197     public void setVersion( String version )
198     {
199         this.version = version;
200     } //-- void setVersion( String )
201 
202     /**
203      * Set versioning information for the artifact.
204      * 
205      * @param versioning
206      */
207     public void setVersioning( Versioning versioning )
208     {
209         this.versioning = versioning;
210     } //-- void setVersioning( Versioning )
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                 // this should only be for historical reasons - we assume local is newer
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                     // overwrite
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 }