001    // =================== DO NOT EDIT THIS FILE ====================
002    // Generated by Modello 1.7,
003    // any modifications will be overwritten.
004    // ==============================================================
005    
006    package org.apache.maven.artifact.repository.metadata;
007    
008    /**
009     * Class Metadata.
010     * 
011     * @version $Revision$ $Date$
012     */
013    @SuppressWarnings( "all" )
014    public class Metadata
015        implements java.io.Serializable, java.lang.Cloneable
016    {
017    
018          //--------------------------/
019         //- Class/Member Variables -/
020        //--------------------------/
021    
022        /**
023         * The version of the underlying metadata model.
024         */
025        private String modelVersion;
026    
027        /**
028         * The groupId that this directory represents, if any.
029         */
030        private String groupId;
031    
032        /**
033         * The artifactId that this directory represents, if any.
034         */
035        private String artifactId;
036    
037        /**
038         * The version that this directory represents, if any. It is
039         * used for artifact snapshots only.
040         */
041        private String version;
042    
043        /**
044         * Versioning information for the artifact.
045         */
046        private Versioning versioning;
047    
048        /**
049         * Field plugins.
050         */
051        private java.util.List<Plugin> plugins;
052    
053        /**
054         * Field modelEncoding.
055         */
056        private String modelEncoding = "UTF-8";
057    
058    
059          //-----------/
060         //- Methods -/
061        //-----------/
062    
063        /**
064         * Method addPlugin.
065         * 
066         * @param plugin
067         */
068        public void addPlugin( Plugin plugin )
069        {
070            getPlugins().add( plugin );
071        } //-- void addPlugin( Plugin )
072    
073        /**
074         * Method clone.
075         * 
076         * @return Metadata
077         */
078        public Metadata clone()
079        {
080            try
081            {
082                Metadata copy = (Metadata) super.clone();
083    
084                if ( this.versioning != null )
085                {
086                    copy.versioning = (Versioning) this.versioning.clone();
087                }
088    
089                if ( this.plugins != null )
090                {
091                    copy.plugins = new java.util.ArrayList<Plugin>();
092                    for ( Plugin item : this.plugins )
093                    {
094                        copy.plugins.add( ( (Plugin) item).clone() );
095                    }
096                }
097    
098                return copy;
099            }
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    }