1 package org.apache.maven.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.maven.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 )
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 model = new ArchivaArtifactModel();
67 model.setGroupId( groupId );
68 model.setArtifactId( artifactId );
69 model.setVersion( version );
70 model.setClassifier( StringUtils.defaultString( classifier ) );
71 model.setType( type );
72 model.setSnapshot( VersionUtil.isSnapshot( version ) );
74 this.baseVersion = VersionUtil.getBaseVersion( version );
77 public ArchivaArtifact( ArchivaArtifactModel artifactModel )
79 this.model = artifactModel;
80 model.setSnapshot( VersionUtil.isSnapshot( model.getVersion() ) );
81 this.baseVersion = VersionUtil.getBaseVersion( model.getVersion() );
84 public ArchivaArtifact( ArtifactReference ref )
86 this( ref.getGroupId(), ref.getArtifactId(), ref.getVersion(), ref.getClassifier(), ref.getType() );
89 public ArchivaArtifactModel getModel()
94 public String getGroupId()
96 return model.getGroupId();
99 public String getArtifactId()
101 return model.getArtifactId();
104 public String getVersion()
106 return model.getVersion();
109 public String getBaseVersion()
114 public boolean isSnapshot()
116 return model.isSnapshot();
119 public String getClassifier()
121 return model.getClassifier();
124 public String getType()
126 return model.getType();
129 public boolean hasClassifier()
131 return StringUtils.isNotEmpty( model.getClassifier() );
134 public int hashCode()
136 final int PRIME = 31;
140 result = PRIME * result + ( ( model.getGroupId() == null ) ? 0 : model.getGroupId().hashCode() );
141 result = PRIME * result + ( ( model.getArtifactId() == null ) ? 0 : model.getArtifactId().hashCode() );
142 result = PRIME * result + ( ( model.getVersion() == null ) ? 0 : model.getVersion().hashCode() );
143 result = PRIME * result + ( ( model.getClassifier() == null ) ? 0 : model.getClassifier().hashCode() );
144 result = PRIME * result + ( ( model.getType() == null ) ? 0 : model.getType().hashCode() );
149 public boolean equals( Object obj )
161 if ( getClass() != obj.getClass() )
166 final ArchivaArtifact other = (ArchivaArtifact) obj;
170 if ( other.model != null )
175 if ( !model.equals( other.model ) )
183 public String toString()
185 StringBuffer sb = new StringBuffer();
186 if ( model.getGroupId() != null )
188 sb.append( model.getGroupId() );
191 appendArtifactTypeClassifierString( sb );
193 if ( model.getVersion() != null )
195 sb.append( model.getVersion() );
198 return sb.toString();
201 private void appendArtifactTypeClassifierString( StringBuffer sb )
203 sb.append( model.getArtifactId() );
205 sb.append( getType() );
206 if ( hasClassifier() )
209 sb.append( getClassifier() );
213 private boolean empty( String value )
215 return ( value == null ) || ( value.trim().length() < 1 );
218 public ArchivaArtifactPlatformDetails getPlatformDetails()
220 return platformDetails;
223 public void setPlatformDetails( ArchivaArtifactPlatformDetails platformDetails )
225 this.platformDetails = platformDetails;