001package org.apache.archiva.model; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.ArrayList; 023import java.util.Enumeration; 024import java.util.List; 025import java.util.Properties; 026 027/** 028 * Utility methods for cloning various Archiva Model objects. 029 * 030 * 031 */ 032public class ArchivaModelCloner 033{ 034 035 public static ArtifactReference clone( ArtifactReference artifactReference ) 036 { 037 if ( artifactReference == null ) 038 { 039 return null; 040 } 041 042 ArtifactReference cloned = new ArtifactReference(); 043 044 cloned.setGroupId( artifactReference.getGroupId() ); 045 cloned.setArtifactId( artifactReference.getArtifactId() ); 046 cloned.setVersion( artifactReference.getVersion() ); 047 cloned.setClassifier( artifactReference.getClassifier() ); 048 cloned.setType( artifactReference.getType() ); 049 050 return cloned; 051 } 052 053 @SuppressWarnings( "unchecked" ) 054 public static Properties clone( Properties properties ) 055 { 056 if ( properties == null ) 057 { 058 return null; 059 } 060 061 Properties cloned = new Properties(); 062 063 Enumeration<String> keys = (Enumeration<String>) properties.propertyNames(); 064 while ( keys.hasMoreElements() ) 065 { 066 String key = (String) keys.nextElement(); 067 String value = properties.getProperty( key ); 068 cloned.setProperty( key, value ); 069 } 070 071 return cloned; 072 } 073 074 public static SnapshotVersion clone( SnapshotVersion snapshotVersion ) 075 { 076 if ( snapshotVersion == null ) 077 { 078 return null; 079 } 080 081 SnapshotVersion cloned = new SnapshotVersion(); 082 083 cloned.setTimestamp( snapshotVersion.getTimestamp() ); 084 cloned.setBuildNumber( snapshotVersion.getBuildNumber() ); 085 086 return cloned; 087 } 088 089 public static VersionedReference clone( VersionedReference versionedReference ) 090 { 091 if ( versionedReference == null ) 092 { 093 return null; 094 } 095 096 VersionedReference cloned = new VersionedReference(); 097 098 cloned.setGroupId( versionedReference.getGroupId() ); 099 cloned.setArtifactId( versionedReference.getArtifactId() ); 100 cloned.setVersion( versionedReference.getVersion() ); 101 102 return cloned; 103 } 104 105 public static List<ArtifactReference> cloneArtifactReferences( List<ArtifactReference> artifactReferenceList ) 106 { 107 if ( artifactReferenceList == null ) 108 { 109 return null; 110 } 111 112 List<ArtifactReference> ret = new ArrayList<>( artifactReferenceList.size() ); 113 114 for ( ArtifactReference ref : artifactReferenceList ) 115 { 116 ret.add( clone( ref ) ); 117 } 118 119 return ret; 120 } 121 122 private static List<String> cloneSimpleStringList( List<String> simple ) 123 { 124 if ( simple == null ) 125 { 126 return null; 127 } 128 129 List<String> ret = new ArrayList<>( simple.size() ); 130 131 for ( String txt : simple ) 132 { 133 ret.add( txt ); 134 } 135 136 return ret; 137 } 138 139 public static List<String> cloneAvailableVersions( List<String> availableVersions ) 140 { 141 return cloneSimpleStringList( availableVersions ); 142 } 143}