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 org.apache.commons.lang.StringUtils;
23 import org.apache.archiva.common.utils.VersionUtil;
26 * ArchivaArtifact - Mutable artifact object.
30 public class ArchivaArtifact
32 private ArchivaArtifactModel model;
34 private ArchivaArtifactPlatformDetails platformDetails;
36 private String baseVersion;
38 public ArchivaArtifact( String groupId, String artifactId, String version,
39 String classifier, String type, String repositoryId )
41 if ( empty( groupId ) )
43 throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty groupId ["
44 + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
47 if ( empty( artifactId ) )
49 throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty artifactId ["
50 + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
53 if ( empty( version ) )
55 throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty version ["
56 + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
61 throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty type ["
62 + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
65 if ( empty( repositoryId ) )
67 throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty repositoryId ["
68 + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
71 model = new ArchivaArtifactModel();
73 model.setGroupId( groupId );
74 model.setArtifactId( artifactId );
75 model.setVersion( version );
76 model.setClassifier( StringUtils.defaultString( classifier ) );
77 model.setType( type );
78 model.setSnapshot( VersionUtil.isSnapshot( version ) );
79 model.setRepositoryId(repositoryId);
81 this.baseVersion = VersionUtil.getBaseVersion( version );
84 public ArchivaArtifact( ArchivaArtifactModel artifactModel )
86 this.model = artifactModel;
87 model.setSnapshot( VersionUtil.isSnapshot( model.getVersion() ) );
88 this.baseVersion = VersionUtil.getBaseVersion( model.getVersion() );
91 public ArchivaArtifact( ArtifactReference ref, String repositoryId )
93 this( ref.getGroupId(), ref.getArtifactId(), ref.getVersion(), ref.getClassifier(), ref.getType(), repositoryId );
96 public ArchivaArtifactModel getModel()
101 public String getGroupId()
103 return model.getGroupId();
106 public String getArtifactId()
108 return model.getArtifactId();
111 public String getVersion()
113 return model.getVersion();
116 public String getBaseVersion()
121 public boolean isSnapshot()
123 return model.isSnapshot();
126 public String getClassifier()
128 return model.getClassifier();
131 public String getType()
133 return model.getType();
136 public boolean hasClassifier()
138 return StringUtils.isNotEmpty( model.getClassifier() );
141 public String getRepositoryId()
143 return model.getRepositoryId();
147 public int hashCode()
149 final int PRIME = 31;
153 result = PRIME * result + ( ( model.getGroupId() == null ) ? 0 : model.getGroupId().hashCode() );
154 result = PRIME * result + ( ( model.getArtifactId() == null ) ? 0 : model.getArtifactId().hashCode() );
155 result = PRIME * result + ( ( model.getVersion() == null ) ? 0 : model.getVersion().hashCode() );
156 result = PRIME * result + ( ( model.getClassifier() == null ) ? 0 : model.getClassifier().hashCode() );
157 result = PRIME * result + ( ( model.getType() == null ) ? 0 : model.getType().hashCode() );
163 public boolean equals( Object obj )
175 if ( getClass() != obj.getClass() )
180 final ArchivaArtifact other = (ArchivaArtifact) obj;
184 if ( other.model != null )
189 if ( !model.equals( other.model ) )
198 public String toString()
200 StringBuffer sb = new StringBuffer();
201 if ( model.getGroupId() != null )
203 sb.append( model.getGroupId() );
206 appendArtifactTypeClassifierString( sb );
208 if ( model.getVersion() != null )
210 sb.append( model.getVersion() );
213 return sb.toString();
216 private void appendArtifactTypeClassifierString( StringBuffer sb )
218 sb.append( model.getArtifactId() );
220 sb.append( getType() );
221 if ( hasClassifier() )
224 sb.append( getClassifier() );
228 private boolean empty( String value )
230 return ( value == null ) || ( value.trim().length() < 1 );
233 public ArchivaArtifactPlatformDetails getPlatformDetails()
235 return platformDetails;
238 public void setPlatformDetails( ArchivaArtifactPlatformDetails platformDetails )
240 this.platformDetails = platformDetails;