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() ) );
68 cloned.setProperties( clone(model.getProperties() ) );
73 public static ArtifactReference clone( ArtifactReference artifactReference )
75 if ( artifactReference == null )
80 ArtifactReference cloned = new ArtifactReference();
82 cloned.setGroupId( artifactReference.getGroupId() );
83 cloned.setArtifactId( artifactReference.getArtifactId() );
84 cloned.setVersion( artifactReference.getVersion() );
85 cloned.setClassifier( artifactReference.getClassifier() );
86 cloned.setType( artifactReference.getType() );
91 public static CiManagement clone( CiManagement ciManagement )
93 if ( ciManagement == null )
98 CiManagement cloned = new CiManagement();
100 cloned.setSystem( ciManagement.getSystem() );
101 cloned.setUrl( ciManagement.getUrl() );
106 public static Dependency clone( Dependency dependency )
108 if ( dependency == null )
113 Dependency cloned = new Dependency();
116 cloned.setGroupId( dependency.getGroupId() );
117 cloned.setArtifactId( dependency.getArtifactId() );
118 cloned.setVersion( dependency.getVersion() );
119 cloned.setClassifier( dependency.getClassifier() );
120 cloned.setType( dependency.getType() );
123 cloned.setTransitive( dependency.isTransitive() );
124 cloned.setScope( dependency.getScope() );
125 cloned.setOptional( dependency.isOptional() );
126 cloned.setSystemPath( dependency.getSystemPath() );
127 cloned.setUrl( dependency.getUrl() );
128 cloned.setExclusions( cloneExclusions( dependency.getExclusions() ) );
133 public static IssueManagement clone( IssueManagement issueManagement )
135 if ( issueManagement == null )
140 IssueManagement cloned = new IssueManagement();
142 cloned.setSystem( issueManagement.getSystem() );
143 cloned.setUrl( issueManagement.getUrl() );
148 public static MailingList clone( MailingList mailingList )
150 if ( mailingList == null )
155 MailingList cloned = new MailingList();
157 cloned.setName( mailingList.getName() );
158 cloned.setSubscribeAddress( mailingList.getSubscribeAddress() );
159 cloned.setUnsubscribeAddress( mailingList.getUnsubscribeAddress() );
160 cloned.setPostAddress( mailingList.getPostAddress() );
161 cloned.setMainArchiveUrl( mailingList.getMainArchiveUrl() );
162 cloned.setOtherArchives( cloneSimpleStringList( mailingList.getOtherArchives() ) );
167 public static Organization clone( Organization organization )
169 if ( organization == null )
174 Organization cloned = new Organization();
176 cloned.setFavicon( organization.getFavicon() );
177 cloned.setName( organization.getName() );
178 cloned.setUrl( organization.getUrl() );
183 @SuppressWarnings("unchecked")
184 public static Properties clone( Properties properties )
186 if ( properties == null )
191 Properties cloned = new Properties();
193 Enumeration<String> keys = (Enumeration<String>) properties.propertyNames();
194 while ( keys.hasMoreElements() )
196 String key = (String) keys.nextElement();
197 String value = properties.getProperty( key );
198 cloned.setProperty( key, value );
204 public static Scm clone( Scm scm )
211 Scm cloned = new Scm();
213 cloned.setConnection( scm.getConnection() );
214 cloned.setDeveloperConnection( scm.getDeveloperConnection() );
215 cloned.setUrl( scm.getUrl() );
220 public static SnapshotVersion clone( SnapshotVersion snapshotVersion )
222 if ( snapshotVersion == null )
227 SnapshotVersion cloned = new SnapshotVersion();
229 cloned.setTimestamp( snapshotVersion.getTimestamp() );
230 cloned.setBuildNumber( snapshotVersion.getBuildNumber() );
235 public static VersionedReference clone( VersionedReference versionedReference )
237 if ( versionedReference == null )
242 VersionedReference cloned = new VersionedReference();
244 cloned.setGroupId( versionedReference.getGroupId() );
245 cloned.setArtifactId( versionedReference.getArtifactId() );
246 cloned.setVersion( versionedReference.getVersion() );
251 public static List<ArtifactReference> cloneArtifactReferences( List<ArtifactReference> artifactReferenceList )
253 if ( artifactReferenceList == null )
258 List<ArtifactReference> ret = new ArrayList<ArtifactReference>();
260 for ( ArtifactReference ref : artifactReferenceList )
262 ret.add( clone( ref ) );
268 public static List<Dependency> cloneDependencies( List<Dependency> dependencies )
270 if ( dependencies == null )
275 List<Dependency> ret = new ArrayList<Dependency>();
277 for ( Dependency dep : dependencies )
281 // Skip null dependency.
285 ret.add( clone( dep ) );
291 public static List<Exclusion> cloneExclusions( List<Exclusion> exclusions )
293 if ( exclusions == null )
298 List<Exclusion> ret = new ArrayList<Exclusion>();
300 for ( Exclusion exclusion : exclusions )
302 Exclusion cloned = new Exclusion();
304 cloned.setGroupId( exclusion.getGroupId() );
305 cloned.setArtifactId( exclusion.getArtifactId() );
313 public static List<Individual> cloneIndividuals( List<Individual> individuals )
315 if ( individuals == null )
320 List<Individual> ret = new ArrayList<Individual>();
322 Iterator<Individual> it = individuals.iterator();
323 while ( it.hasNext() )
325 Individual individual = it.next();
326 Individual cloned = new Individual();
328 cloned.setPrincipal( individual.getPrincipal() );
330 cloned.setEmail( individual.getEmail() );
331 cloned.setName( individual.getName() );
332 cloned.setOrganization( individual.getOrganization() );
333 cloned.setOrganizationUrl( individual.getOrganizationUrl() );
334 cloned.setUrl( individual.getUrl() );
335 cloned.setTimezone( individual.getTimezone() );
337 cloned.setRoles( cloneRoles( individual.getRoles() ) );
338 cloned.setProperties( clone( individual.getProperties() ) );
346 public static List<License> cloneLicenses( List<License> licenses )
348 if ( licenses == null )
353 List<License> ret = new ArrayList<License>();
355 for ( License license : licenses )
357 License cloned = new License();
359 cloned.setId( license.getId() );
360 cloned.setName( license.getName() );
361 cloned.setUrl( license.getUrl() );
362 cloned.setComments( license.getComments() );
370 public static List<MailingList> cloneMailingLists( List<MailingList> mailingLists )
372 if ( mailingLists == null )
377 List<MailingList> ret = new ArrayList<MailingList>();
379 for ( MailingList mailingList : mailingLists )
381 if ( mailingList == null )
383 // Skip null mailing list.
387 ret.add( clone( mailingList ) );
393 public static List<ArtifactReference> clonePlugins( List<ArtifactReference> plugins )
395 return cloneArtifactReferences( plugins );
398 public static List<ArtifactReference> cloneReports( List<ArtifactReference> reports )
400 return cloneArtifactReferences( reports );
403 public static List<ProjectRepository> cloneRepositories( List<ProjectRepository> repositories )
405 if ( repositories == null )
410 List<ProjectRepository> ret = new ArrayList<ProjectRepository>();
412 for ( ProjectRepository repository : repositories )
414 ProjectRepository cloned = new ProjectRepository();
416 cloned.setId( repository.getId() );
417 cloned.setName( repository.getName() );
418 cloned.setUrl( repository.getUrl() );
419 cloned.setLayout( repository.getLayout() );
420 cloned.setPlugins( repository.isPlugins() );
421 cloned.setReleases( repository.isReleases() );
422 cloned.setSnapshots( repository.isSnapshots() );
430 public static List<String> cloneRoles( List<String> roles )
432 return cloneSimpleStringList( roles );
435 private static List<String> cloneSimpleStringList( List<String> simple )
437 if ( simple == null )
442 List<String> ret = new ArrayList<String>();
444 for ( String txt : simple )
452 public static List<String> cloneAvailableVersions( List<String> availableVersions )
454 return cloneSimpleStringList( availableVersions );