1 package org.apache.maven.archiva.model;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import java.util.ArrayList;
23 import java.util.Enumeration;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Properties;
29 * Utility methods for cloning various Archiva Model objects.
33 public class ArchivaModelCloner
35 public static ArchivaProjectModel clone( ArchivaProjectModel model )
42 ArchivaProjectModel cloned = new ArchivaProjectModel();
44 cloned.setGroupId( model.getGroupId() );
45 cloned.setArtifactId( model.getArtifactId() );
46 cloned.setVersion( model.getVersion() );
48 cloned.setParentProject( clone( model.getParentProject() ) );
50 cloned.setName( model.getName() );
51 cloned.setDescription( model.getDescription() );
52 cloned.setUrl( model.getUrl() );
53 cloned.setPackaging( model.getPackaging() );
54 cloned.setOrigin( model.getOrigin() );
56 cloned.setMailingLists( cloneMailingLists( model.getMailingLists() ) );
57 cloned.setCiManagement( clone( model.getCiManagement() ) );
58 cloned.setIndividuals( cloneIndividuals( model.getIndividuals() ) );
59 cloned.setIssueManagement( clone( model.getIssueManagement() ) );
60 cloned.setLicenses( cloneLicenses( model.getLicenses() ) );
61 cloned.setOrganization( clone( model.getOrganization() ) );
62 cloned.setScm( clone( model.getScm() ) );
63 cloned.setRepositories( cloneRepositories( model.getRepositories() ) );
64 cloned.setDependencies( cloneDependencies( model.getDependencies() ) );
65 cloned.setPlugins( clonePlugins( model.getPlugins() ) );
66 cloned.setReports( cloneReports( model.getReports() ) );
67 cloned.setDependencyManagement( cloneDependencies( model.getDependencyManagement() ) );
72 public static ArtifactReference clone( ArtifactReference artifactReference )
74 if ( artifactReference == null )
79 ArtifactReference cloned = new ArtifactReference();
81 cloned.setGroupId( artifactReference.getGroupId() );
82 cloned.setArtifactId( artifactReference.getArtifactId() );
83 cloned.setVersion( artifactReference.getVersion() );
84 cloned.setClassifier( artifactReference.getClassifier() );
85 cloned.setType( artifactReference.getType() );
90 public static CiManagement clone( CiManagement ciManagement )
92 if ( ciManagement == null )
97 CiManagement cloned = new CiManagement();
99 cloned.setSystem( ciManagement.getSystem() );
100 cloned.setUrl( ciManagement.getUrl() );
105 public static Dependency clone( Dependency dependency )
107 if ( dependency == null )
112 Dependency cloned = new Dependency();
115 cloned.setGroupId( dependency.getGroupId() );
116 cloned.setArtifactId( dependency.getArtifactId() );
117 cloned.setVersion( dependency.getVersion() );
118 cloned.setClassifier( dependency.getClassifier() );
119 cloned.setType( dependency.getType() );
122 cloned.setTransitive( dependency.isTransitive() );
123 cloned.setScope( dependency.getScope() );
124 cloned.setOptional( dependency.isOptional() );
125 cloned.setSystemPath( dependency.getSystemPath() );
126 cloned.setUrl( dependency.getUrl() );
127 cloned.setExclusions( cloneExclusions( dependency.getExclusions() ) );
132 public static IssueManagement clone( IssueManagement issueManagement )
134 if ( issueManagement == null )
139 IssueManagement cloned = new IssueManagement();
141 cloned.setSystem( issueManagement.getSystem() );
142 cloned.setUrl( issueManagement.getUrl() );
147 public static MailingList clone( MailingList mailingList )
149 if ( mailingList == null )
154 MailingList cloned = new MailingList();
156 cloned.setName( mailingList.getName() );
157 cloned.setSubscribeAddress( mailingList.getSubscribeAddress() );
158 cloned.setUnsubscribeAddress( mailingList.getUnsubscribeAddress() );
159 cloned.setPostAddress( mailingList.getPostAddress() );
160 cloned.setMainArchiveUrl( mailingList.getMainArchiveUrl() );
161 cloned.setOtherArchives( cloneSimpleStringList( mailingList.getOtherArchives() ) );
166 public static Organization clone( Organization organization )
168 if ( organization == null )
173 Organization cloned = new Organization();
175 cloned.setFavicon( organization.getFavicon() );
176 cloned.setName( organization.getName() );
177 cloned.setUrl( organization.getUrl() );
182 public static Properties clone( Properties properties )
184 if ( properties == null )
189 Properties cloned = new Properties();
191 Enumeration keys = properties.propertyNames();
192 while ( keys.hasMoreElements() )
194 String key = (String) keys.nextElement();
195 String value = properties.getProperty( key );
196 cloned.setProperty( key, value );
202 public static Scm clone( Scm scm )
209 Scm cloned = new Scm();
211 cloned.setConnection( scm.getConnection() );
212 cloned.setDeveloperConnection( scm.getDeveloperConnection() );
213 cloned.setUrl( scm.getUrl() );
218 public static SnapshotVersion clone( SnapshotVersion snapshotVersion )
220 if ( snapshotVersion == null )
225 SnapshotVersion cloned = new SnapshotVersion();
227 cloned.setTimestamp( snapshotVersion.getTimestamp() );
228 cloned.setBuildNumber( snapshotVersion.getBuildNumber() );
233 public static VersionedReference clone( VersionedReference versionedReference )
235 if ( versionedReference == null )
240 VersionedReference cloned = new VersionedReference();
242 cloned.setGroupId( versionedReference.getGroupId() );
243 cloned.setArtifactId( versionedReference.getArtifactId() );
244 cloned.setVersion( versionedReference.getVersion() );
249 public static List cloneArtifactReferences( List artifactReferenceList )
251 if ( artifactReferenceList == null )
256 List ret = new ArrayList();
258 Iterator it = artifactReferenceList.iterator();
259 while ( it.hasNext() )
261 ArtifactReference artifactReference = (ArtifactReference) it.next();
262 ret.add( clone( artifactReference ) );
268 public static List cloneDependencies( List dependencies )
270 if ( dependencies == null )
275 List ret = new ArrayList();
277 Iterator it = dependencies.iterator();
278 while ( it.hasNext() )
280 Dependency dep = (Dependency) it.next();
284 // Skip null dependency.
288 ret.add( clone( dep ) );
294 public static List cloneExclusions( List exclusions )
296 if ( exclusions == null )
301 List ret = new ArrayList();
303 Iterator it = exclusions.iterator();
304 while ( it.hasNext() )
306 Exclusion exclusion = (Exclusion) it.next();
307 Exclusion cloned = new Exclusion();
309 cloned.setGroupId( exclusion.getGroupId() );
310 cloned.setArtifactId( exclusion.getArtifactId() );
318 public static List cloneIndividuals( List individuals )
320 if ( individuals == null )
325 List ret = new ArrayList();
327 Iterator it = individuals.iterator();
328 while ( it.hasNext() )
330 Individual individual = (Individual) it.next();
331 Individual cloned = new Individual();
333 cloned.setPrincipal( individual.getPrincipal() );
335 cloned.setEmail( individual.getEmail() );
336 cloned.setName( individual.getName() );
337 cloned.setOrganization( individual.getOrganization() );
338 cloned.setOrganizationUrl( individual.getOrganizationUrl() );
339 cloned.setUrl( individual.getUrl() );
340 cloned.setTimezone( individual.getTimezone() );
342 cloned.setRoles( cloneRoles( individual.getRoles() ) );
343 cloned.setProperties( clone( individual.getProperties() ) );
351 public static List cloneLicenses( List licenses )
353 if ( licenses == null )
358 List ret = new ArrayList();
360 Iterator it = licenses.iterator();
361 while ( it.hasNext() )
363 License license = (License) it.next();
364 License cloned = new License();
366 cloned.setId( license.getId() );
367 cloned.setName( license.getName() );
368 cloned.setUrl( license.getUrl() );
369 cloned.setComments( license.getComments() );
377 public static List cloneMailingLists( List mailingLists )
379 if ( mailingLists == null )
384 List ret = new ArrayList();
386 Iterator it = mailingLists.iterator();
387 while ( it.hasNext() )
389 MailingList mailingList = (MailingList) it.next();
391 if ( mailingList == null )
393 // Skip null mailing list.
397 ret.add( clone( mailingList ) );
403 public static List clonePlugins( List plugins )
405 return cloneArtifactReferences( plugins );
408 public static List cloneReports( List reports )
410 return cloneArtifactReferences( reports );
413 public static List cloneRepositories( List repositories )
415 if ( repositories == null )
420 List ret = new ArrayList();
422 Iterator it = repositories.iterator();
423 while ( it.hasNext() )
425 ProjectRepository repository = (ProjectRepository) it.next();
426 ProjectRepository cloned = new ProjectRepository();
428 cloned.setId( repository.getId() );
429 cloned.setName( repository.getName() );
430 cloned.setUrl( repository.getUrl() );
431 cloned.setLayout( repository.getLayout() );
432 cloned.setPlugins( repository.isPlugins() );
433 cloned.setReleases( repository.isReleases() );
434 cloned.setSnapshots( repository.isSnapshots() );
442 public static List cloneRoles( List roles )
444 return cloneSimpleStringList( roles );
447 private static List cloneSimpleStringList( List simple )
449 if ( simple == null )
454 List ret = new ArrayList();
456 Iterator it = simple.iterator();
458 while ( it.hasNext() )
460 String txt = (String) it.next();
467 public static List cloneAvailableVersions( List availableVersions )
469 return cloneSimpleStringList( availableVersions );