123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- package org.apache.archiva.model;
-
- /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
- import org.apache.commons.lang.StringUtils;
- import org.apache.archiva.common.utils.VersionUtil;
-
- /**
- * ArchivaArtifact - Mutable artifact object.
- *
- *
- */
- public class ArchivaArtifact
- {
- private ArchivaArtifactModel model;
-
- private ArchivaArtifactPlatformDetails platformDetails;
-
- private String baseVersion;
-
- public ArchivaArtifact( String groupId, String artifactId, String version,
- String classifier, String type, String repositoryId )
- {
- if ( empty( groupId ) )
- {
- throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty groupId ["
- + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
- }
-
- if ( empty( artifactId ) )
- {
- throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty artifactId ["
- + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
- }
-
- if ( empty( version ) )
- {
- throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty version ["
- + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
- }
-
- if ( empty( type ) )
- {
- throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty type ["
- + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
- }
-
- if ( empty( repositoryId ) )
- {
- throw new IllegalArgumentException( "Unable to create ArchivaArtifact with empty repositoryId ["
- + Keys.toKey( groupId, artifactId, version, classifier, type ) + "]" );
- }
-
- model = new ArchivaArtifactModel();
-
- model.setGroupId( groupId );
- model.setArtifactId( artifactId );
- model.setVersion( version );
- model.setClassifier( StringUtils.defaultString( classifier ) );
- model.setType( type );
- model.setSnapshot( VersionUtil.isSnapshot( version ) );
- model.setRepositoryId(repositoryId);
-
- this.baseVersion = VersionUtil.getBaseVersion( version );
- }
-
- public ArchivaArtifact( ArchivaArtifactModel artifactModel )
- {
- this.model = artifactModel;
- model.setSnapshot( VersionUtil.isSnapshot( model.getVersion() ) );
- this.baseVersion = VersionUtil.getBaseVersion( model.getVersion() );
- }
-
- public ArchivaArtifact( ArtifactReference ref, String repositoryId )
- {
- this( ref.getGroupId(), ref.getArtifactId(), ref.getVersion(), ref.getClassifier(), ref.getType(), repositoryId );
- }
-
- public ArchivaArtifactModel getModel()
- {
- return model;
- }
-
- public String getGroupId()
- {
- return model.getGroupId();
- }
-
- public String getArtifactId()
- {
- return model.getArtifactId();
- }
-
- public String getVersion()
- {
- return model.getVersion();
- }
-
- public String getBaseVersion()
- {
- return baseVersion;
- }
-
- public boolean isSnapshot()
- {
- return model.isSnapshot();
- }
-
- public String getClassifier()
- {
- return model.getClassifier();
- }
-
- public String getType()
- {
- return model.getType();
- }
-
- public boolean hasClassifier()
- {
- return StringUtils.isNotEmpty( model.getClassifier() );
- }
-
- public String getRepositoryId()
- {
- return model.getRepositoryId();
- }
-
- @Override
- public int hashCode()
- {
- final int PRIME = 31;
- int result = 1;
- if ( model != null )
- {
- result = PRIME * result + ( ( model.getGroupId() == null ) ? 0 : model.getGroupId().hashCode() );
- result = PRIME * result + ( ( model.getArtifactId() == null ) ? 0 : model.getArtifactId().hashCode() );
- result = PRIME * result + ( ( model.getVersion() == null ) ? 0 : model.getVersion().hashCode() );
- result = PRIME * result + ( ( model.getClassifier() == null ) ? 0 : model.getClassifier().hashCode() );
- result = PRIME * result + ( ( model.getType() == null ) ? 0 : model.getType().hashCode() );
- }
- return result;
- }
-
- @Override
- public boolean equals( Object obj )
- {
- if ( this == obj )
- {
- return true;
- }
-
- if ( obj == null )
- {
- return false;
- }
-
- if ( getClass() != obj.getClass() )
- {
- return false;
- }
-
- final ArchivaArtifact other = (ArchivaArtifact) obj;
-
- if ( model == null )
- {
- if ( other.model != null )
- {
- return false;
- }
- }
- if ( !model.equals( other.model ) )
- {
- return false;
- }
-
- return true;
- }
-
- @Override
- public String toString()
- {
- StringBuffer sb = new StringBuffer();
- if ( model.getGroupId() != null )
- {
- sb.append( model.getGroupId() );
- sb.append( ":" );
- }
- appendArtifactTypeClassifierString( sb );
- sb.append( ":" );
- if ( model.getVersion() != null )
- {
- sb.append( model.getVersion() );
- }
-
- return sb.toString();
- }
-
- private void appendArtifactTypeClassifierString( StringBuffer sb )
- {
- sb.append( model.getArtifactId() );
- sb.append( ":" );
- sb.append( getType() );
- if ( hasClassifier() )
- {
- sb.append( ":" );
- sb.append( getClassifier() );
- }
- }
-
- private boolean empty( String value )
- {
- return ( value == null ) || ( value.trim().length() < 1 );
- }
-
- public ArchivaArtifactPlatformDetails getPlatformDetails()
- {
- return platformDetails;
- }
-
- public void setPlatformDetails( ArchivaArtifactPlatformDetails platformDetails )
- {
- this.platformDetails = platformDetails;
- }
- }
|