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 @SuppressWarnings("unchecked")
183 public static Properties clone( Properties properties )
185 if ( properties == null )
190 Properties cloned = new Properties();
192 Enumeration<String> keys = (Enumeration<String>) properties.propertyNames();
193 while ( keys.hasMoreElements() )
195 String key = (String) keys.nextElement();
196 String value = properties.getProperty( key );
197 cloned.setProperty( key, value );
203 public static Scm clone( Scm scm )
210 Scm cloned = new Scm();
212 cloned.setConnection( scm.getConnection() );
213 cloned.setDeveloperConnection( scm.getDeveloperConnection() );
214 cloned.setUrl( scm.getUrl() );
219 public static SnapshotVersion clone( SnapshotVersion snapshotVersion )
221 if ( snapshotVersion == null )
226 SnapshotVersion cloned = new SnapshotVersion();
228 cloned.setTimestamp( snapshotVersion.getTimestamp() );
229 cloned.setBuildNumber( snapshotVersion.getBuildNumber() );
234 public static VersionedReference clone( VersionedReference versionedReference )
236 if ( versionedReference == null )
241 VersionedReference cloned = new VersionedReference();
243 cloned.setGroupId( versionedReference.getGroupId() );
244 cloned.setArtifactId( versionedReference.getArtifactId() );
245 cloned.setVersion( versionedReference.getVersion() );
250 public static List<ArtifactReference> cloneArtifactReferences( List<ArtifactReference> artifactReferenceList )
252 if ( artifactReferenceList == null )
257 List<ArtifactReference> ret = new ArrayList<ArtifactReference>();
259 for ( ArtifactReference ref : artifactReferenceList )
261 ret.add( clone( ref ) );
267 public static List<Dependency> cloneDependencies( List<Dependency> dependencies )
269 if ( dependencies == null )
274 List<Dependency> ret = new ArrayList<Dependency>();
276 for ( Dependency dep : dependencies )
280 // Skip null dependency.
284 ret.add( clone( dep ) );
290 public static List<Exclusion> cloneExclusions( List<Exclusion> exclusions )
292 if ( exclusions == null )
297 List<Exclusion> ret = new ArrayList<Exclusion>();
299 for ( Exclusion exclusion : exclusions )
301 Exclusion cloned = new Exclusion();
303 cloned.setGroupId( exclusion.getGroupId() );
304 cloned.setArtifactId( exclusion.getArtifactId() );
312 public static List<Individual> cloneIndividuals( List<Individual> individuals )
314 if ( individuals == null )
319 List<Individual> ret = new ArrayList<Individual>();
321 Iterator<Individual> it = individuals.iterator();
322 while ( it.hasNext() )
324 Individual individual = it.next();
325 Individual cloned = new Individual();
327 cloned.setPrincipal( individual.getPrincipal() );
329 cloned.setEmail( individual.getEmail() );
330 cloned.setName( individual.getName() );
331 cloned.setOrganization( individual.getOrganization() );
332 cloned.setOrganizationUrl( individual.getOrganizationUrl() );
333 cloned.setUrl( individual.getUrl() );
334 cloned.setTimezone( individual.getTimezone() );
336 cloned.setRoles( cloneRoles( individual.getRoles() ) );
337 cloned.setProperties( clone( individual.getProperties() ) );
345 public static List<License> cloneLicenses( List<License> licenses )
347 if ( licenses == null )
352 List<License> ret = new ArrayList<License>();
354 for ( License license : licenses )
356 License cloned = new License();
358 cloned.setId( license.getId() );
359 cloned.setName( license.getName() );
360 cloned.setUrl( license.getUrl() );
361 cloned.setComments( license.getComments() );
369 public static List<MailingList> cloneMailingLists( List<MailingList> mailingLists )
371 if ( mailingLists == null )
376 List<MailingList> ret = new ArrayList<MailingList>();
378 for ( MailingList mailingList : mailingLists )
380 if ( mailingList == null )
382 // Skip null mailing list.
386 ret.add( clone( mailingList ) );
392 public static List<ArtifactReference> clonePlugins( List<ArtifactReference> plugins )
394 return cloneArtifactReferences( plugins );
397 public static List<ArtifactReference> cloneReports( List<ArtifactReference> reports )
399 return cloneArtifactReferences( reports );
402 public static List<ProjectRepository> cloneRepositories( List<ProjectRepository> repositories )
404 if ( repositories == null )
409 List<ProjectRepository> ret = new ArrayList<ProjectRepository>();
411 for ( ProjectRepository repository : repositories )
413 ProjectRepository cloned = new ProjectRepository();
415 cloned.setId( repository.getId() );
416 cloned.setName( repository.getName() );
417 cloned.setUrl( repository.getUrl() );
418 cloned.setLayout( repository.getLayout() );
419 cloned.setPlugins( repository.isPlugins() );
420 cloned.setReleases( repository.isReleases() );
421 cloned.setSnapshots( repository.isSnapshots() );
429 public static List<String> cloneRoles( List<String> roles )
431 return cloneSimpleStringList( roles );
434 private static List<String> cloneSimpleStringList( List<String> simple )
436 if ( simple == null )
441 List<String> ret = new ArrayList<String>();
443 for ( String txt : simple )
451 public static List<String> cloneAvailableVersions( List<String> availableVersions )
453 return cloneSimpleStringList( availableVersions );