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