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.

ArchivaArtifact.java 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 org.apache.commons.lang.StringUtils;
  21. import org.apache.archiva.common.utils.VersionUtil;
  22. /**
  23. * ArchivaArtifact - Mutable artifact object.
  24. *
  25. *
  26. */
  27. public class ArchivaArtifact
  28. {
  29. private ArchivaArtifactModel model;
  30. private ArchivaArtifactPlatformDetails platformDetails;
  31. private String baseVersion;
  32. public ArchivaArtifact( String groupId, String artifactId, String version,
  33. String classifier, String type, String repositoryId )
  34. {
  35. if ( empty( groupId ) )
  36. {
  37. throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty groupId ["
  38. + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
  39. }
  40. if ( empty( artifactId ) )
  41. {
  42. throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty artifactId ["
  43. + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
  44. }
  45. if ( empty( version ) )
  46. {
  47. throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty version ["
  48. + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
  49. }
  50. if ( empty( type ) )
  51. {
  52. throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty type ["
  53. + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
  54. }
  55. if ( empty( repositoryId ) )
  56. {
  57. throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty repositoryId ["
  58. + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
  59. }
  60. model = new ArchivaArtifactModel();
  61. model.setGroupId( groupId );
  62. model.setArtifactId( artifactId );
  63. model.setVersion( version );
  64. model.setClassifier( StringUtils.defaultString( classifier ) );
  65. model.setType( type );
  66. model.setSnapshot( VersionUtil.isSnapshot( version ) );
  67. model.setRepositoryId(repositoryId);
  68. this.baseVersion = VersionUtil.getBaseVersion( version );
  69. }
  70. public ArchivaArtifact( ArchivaArtifactModel artifactModel )
  71. {
  72. this.model = artifactModel;
  73. model.setSnapshot( VersionUtil.isSnapshot( model.getVersion() ) );
  74. this.baseVersion = VersionUtil.getBaseVersion( model.getVersion() );
  75. }
  76. public ArchivaArtifact( ArtifactReference ref, String repositoryId )
  77. {
  78. this( ref.getGroupId(), ref.getArtifactId(), ref.getVersion(), ref.getClassifier(), ref.getType(), repositoryId );
  79. }
  80. public ArchivaArtifactModel getModel()
  81. {
  82. return model;
  83. }
  84. public String getGroupId()
  85. {
  86. return model.getGroupId();
  87. }
  88. public String getArtifactId()
  89. {
  90. return model.getArtifactId();
  91. }
  92. public String getVersion()
  93. {
  94. return model.getVersion();
  95. }
  96. public String getBaseVersion()
  97. {
  98. return baseVersion;
  99. }
  100. public boolean isSnapshot()
  101. {
  102. return model.isSnapshot();
  103. }
  104. public String getClassifier()
  105. {
  106. return model.getClassifier();
  107. }
  108. public String getType()
  109. {
  110. return model.getType();
  111. }
  112. public boolean hasClassifier()
  113. {
  114. return StringUtils.isNotEmpty( model.getClassifier() );
  115. }
  116. public String getRepositoryId()
  117. {
  118. return model.getRepositoryId();
  119. }
  120. @Override
  121. public int hashCode()
  122. {
  123. final int PRIME = 31;
  124. int result = 1;
  125. if ( model != null )
  126. {
  127. result = PRIME * result + ( ( model.getGroupId() == null ) ? 0 : model.getGroupId().hashCode() );
  128. result = PRIME * result + ( ( model.getArtifactId() == null ) ? 0 : model.getArtifactId().hashCode() );
  129. result = PRIME * result + ( ( model.getVersion() == null ) ? 0 : model.getVersion().hashCode() );
  130. result = PRIME * result + ( ( model.getClassifier() == null ) ? 0 : model.getClassifier().hashCode() );
  131. result = PRIME * result + ( ( model.getType() == null ) ? 0 : model.getType().hashCode() );
  132. }
  133. return result;
  134. }
  135. @Override
  136. public boolean equals( Object obj )
  137. {
  138. if ( this == obj )
  139. {
  140. return true;
  141. }
  142. if ( obj == null )
  143. {
  144. return false;
  145. }
  146. if ( getClass() != obj.getClass() )
  147. {
  148. return false;
  149. }
  150. final ArchivaArtifact other = (ArchivaArtifact) obj;
  151. if ( model == null )
  152. {
  153. if ( other.model != null )
  154. {
  155. return false;
  156. }
  157. }
  158. if ( !model.equals( other.model ) )
  159. {
  160. return false;
  161. }
  162. return true;
  163. }
  164. @Override
  165. public String toString()
  166. {
  167. StringBuffer sb = new StringBuffer();
  168. if ( model.getGroupId() != null )
  169. {
  170. sb.append( model.getGroupId() );
  171. sb.append( ":" );
  172. }
  173. appendArtifactTypeClassifierString( sb );
  174. sb.append( ":" );
  175. if ( model.getVersion() != null )
  176. {
  177. sb.append( model.getVersion() );
  178. }
  179. return sb.toString();
  180. }
  181. private void appendArtifactTypeClassifierString( StringBuffer sb )
  182. {
  183. sb.append( model.getArtifactId() );
  184. sb.append( ":" );
  185. sb.append( getType() );
  186. if ( hasClassifier() )
  187. {
  188. sb.append( ":" );
  189. sb.append( getClassifier() );
  190. }
  191. }
  192. private boolean empty( String value )
  193. {
  194. return ( value == null ) || ( value.trim().length() < 1 );
  195. }
  196. public ArchivaArtifactPlatformDetails getPlatformDetails()
  197. {
  198. return platformDetails;
  199. }
  200. public void setPlatformDetails( ArchivaArtifactPlatformDetails platformDetails )
  201. {
  202. this.platformDetails = platformDetails;
  203. }
  204. }