1 package org.apache.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.List;
25 import java.util.Properties;
28 * Utility methods for cloning various Archiva Model objects.
32 public class ArchivaModelCloner
35 public static ArtifactReference clone( ArtifactReference artifactReference )
37 if ( artifactReference == null )
42 ArtifactReference cloned = new ArtifactReference();
44 cloned.setGroupId( artifactReference.getGroupId() );
45 cloned.setArtifactId( artifactReference.getArtifactId() );
46 cloned.setVersion( artifactReference.getVersion() );
47 cloned.setClassifier( artifactReference.getClassifier() );
48 cloned.setType( artifactReference.getType() );
53 @SuppressWarnings( "unchecked" )
54 public static Properties clone( Properties properties )
56 if ( properties == null )
61 Properties cloned = new Properties();
63 Enumeration<String> keys = (Enumeration<String>) properties.propertyNames();
64 while ( keys.hasMoreElements() )
66 String key = (String) keys.nextElement();
67 String value = properties.getProperty( key );
68 cloned.setProperty( key, value );
74 public static SnapshotVersion clone( SnapshotVersion snapshotVersion )
76 if ( snapshotVersion == null )
81 SnapshotVersion cloned = new SnapshotVersion();
83 cloned.setTimestamp( snapshotVersion.getTimestamp() );
84 cloned.setBuildNumber( snapshotVersion.getBuildNumber() );
89 public static VersionedReference clone( VersionedReference versionedReference )
91 if ( versionedReference == null )
96 VersionedReference cloned = new VersionedReference();
98 cloned.setGroupId( versionedReference.getGroupId() );
99 cloned.setArtifactId( versionedReference.getArtifactId() );
100 cloned.setVersion( versionedReference.getVersion() );
105 public static List<ArtifactReference> cloneArtifactReferences( List<ArtifactReference> artifactReferenceList )
107 if ( artifactReferenceList == null )
112 List<ArtifactReference> ret = new ArrayList<ArtifactReference>( artifactReferenceList.size() );
114 for ( ArtifactReference ref : artifactReferenceList )
116 ret.add( clone( ref ) );
122 private static List<String> cloneSimpleStringList( List<String> simple )
124 if ( simple == null )
129 List<String> ret = new ArrayList<String>( simple.size() );
131 for ( String txt : simple )
139 public static List<String> cloneAvailableVersions( List<String> availableVersions )
141 return cloneSimpleStringList( availableVersions );