You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ArchivaModelCloner.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package org.apache.archiva.model;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import java.util.ArrayList;
  21. import java.util.Enumeration;
  22. import java.util.List;
  23. import java.util.Properties;
  24. /**
  25. * Utility methods for cloning various Archiva Model objects.
  26. *
  27. *
  28. */
  29. public class ArchivaModelCloner
  30. {
  31. public static ArtifactReference clone( ArtifactReference artifactReference )
  32. {
  33. if ( artifactReference == null )
  34. {
  35. return null;
  36. }
  37. ArtifactReference cloned = new ArtifactReference();
  38. cloned.setGroupId( artifactReference.getGroupId() );
  39. cloned.setArtifactId( artifactReference.getArtifactId() );
  40. cloned.setVersion( artifactReference.getVersion() );
  41. cloned.setClassifier( artifactReference.getClassifier() );
  42. cloned.setType( artifactReference.getType() );
  43. return cloned;
  44. }
  45. @SuppressWarnings( "unchecked" )
  46. public static Properties clone( Properties properties )
  47. {
  48. if ( properties == null )
  49. {
  50. return null;
  51. }
  52. Properties cloned = new Properties();
  53. Enumeration<String> keys = (Enumeration<String>) properties.propertyNames();
  54. while ( keys.hasMoreElements() )
  55. {
  56. String key = (String) keys.nextElement();
  57. String value = properties.getProperty( key );
  58. cloned.setProperty( key, value );
  59. }
  60. return cloned;
  61. }
  62. public static SnapshotVersion clone( SnapshotVersion snapshotVersion )
  63. {
  64. if ( snapshotVersion == null )
  65. {
  66. return null;
  67. }
  68. SnapshotVersion cloned = new SnapshotVersion();
  69. cloned.setTimestamp( snapshotVersion.getTimestamp() );
  70. cloned.setBuildNumber( snapshotVersion.getBuildNumber() );
  71. return cloned;
  72. }
  73. public static VersionedReference clone( VersionedReference versionedReference )
  74. {
  75. if ( versionedReference == null )
  76. {
  77. return null;
  78. }
  79. VersionedReference cloned = new VersionedReference();
  80. cloned.setGroupId( versionedReference.getGroupId() );
  81. cloned.setArtifactId( versionedReference.getArtifactId() );
  82. cloned.setVersion( versionedReference.getVersion() );
  83. return cloned;
  84. }
  85. public static List<ArtifactReference> cloneArtifactReferences( List<ArtifactReference> artifactReferenceList )
  86. {
  87. if ( artifactReferenceList == null )
  88. {
  89. return null;
  90. }
  91. List<ArtifactReference> ret = new ArrayList<>( artifactReferenceList.size() );
  92. for ( ArtifactReference ref : artifactReferenceList )
  93. {
  94. ret.add( clone( ref ) );
  95. }
  96. return ret;
  97. }
  98. private static List<String> cloneSimpleStringList( List<String> simple )
  99. {
  100. if ( simple == null )
  101. {
  102. return null;
  103. }
  104. List<String> ret = new ArrayList<>( simple.size() );
  105. for ( String txt : simple )
  106. {
  107. ret.add( txt );
  108. }
  109. return ret;
  110. }
  111. public static List<String> cloneAvailableVersions( List<String> availableVersions )
  112. {
  113. return cloneSimpleStringList( availableVersions );
  114. }
  115. }