1 package org.apache.archiva.repository.content.base;
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.archiva.repository.content.Artifact;
23 import org.apache.archiva.repository.content.ArtifactType;
24 import org.apache.archiva.repository.content.BaseArtifactTypes;
25 import org.apache.archiva.repository.content.Version;
26 import org.apache.archiva.repository.content.base.builder.ArtifactOptBuilder;
27 import org.apache.archiva.repository.content.base.builder.ArtifactVersionBuilder;
28 import org.apache.archiva.repository.content.base.builder.ArtifactWithIdBuilder;
29 import org.apache.archiva.repository.content.base.builder.WithVersionObjectBuilder;
30 import org.apache.archiva.repository.storage.StorageAsset;
31 import org.apache.commons.lang3.StringUtils;
34 * Base implementation of artifact.
36 * You have to use the builder method {@link #withAsset(StorageAsset)} to create a instance.
37 * The build() method can be called after the required attributes are set.
39 * Artifacts are equal if the following coordinates match:
45 * <li>artifactVersion</li>
48 * <li>artifactType</li>
51 * @author Martin Stockhammer <martin_s@apache.org>
53 public class ArchivaArtifact extends ArchivaContentItem implements Artifact
56 private String artifactVersion;
57 private Version version;
59 private String classifier;
60 private String remainder;
61 private String contentType;
62 private ArtifactType artifactType;
64 private ArchivaArtifact( )
71 public String getId( )
77 public String getArtifactVersion( )
79 return artifactVersion;
83 public Version getVersion( )
89 public String getType( )
95 public String getClassifier( )
101 public String getRemainder( )
107 public String getContentType( )
113 public ArtifactType getArtifactType( )
120 * Returns the builder for creating a new artifact instance. You have to fill the
121 * required attributes before the build() method is available.
123 * @param asset the storage asset representing the artifact
124 * @return a builder for creating new artifact instance
126 public static WithVersionObjectBuilder withAsset( StorageAsset asset )
128 return new Builder( ).withAsset( asset );
133 public boolean equals( Object o )
135 if ( this == o ) return true;
136 if ( o == null || getClass( ) != o.getClass( ) ) return false;
137 if ( !super.equals( o ) ) return false;
139 ArchivaArtifact that = (ArchivaArtifact) o;
141 if ( !id.equals( that.id ) ) return false;
142 if ( !artifactVersion.equals( that.artifactVersion ) ) return false;
143 if ( !version.equals( that.version ) ) return false;
144 if ( !type.equals( that.type ) ) return false;
145 if ( !artifactType.equals(that.artifactType)) return false;
146 return classifier.equals( that.classifier );
150 public int hashCode( )
152 int result = super.hashCode( );
153 result = 31 * result + id.hashCode( );
154 result = 31 * result + artifactVersion.hashCode( );
155 result = 31 * result + version.hashCode( );
156 result = 31 * result + type.hashCode( );
157 result = 31 * result + classifier.hashCode( );
158 result = 31 * result + artifactType.hashCode( );
163 public String toString( )
165 final StringBuilder sb = new StringBuilder( "ArchivaArtifact{" );
166 sb.append( "id='" ).append( id ).append( '\'' );
167 sb.append( ", artifactVersion='" ).append( artifactVersion ).append( '\'' );
168 sb.append( ", version=" ).append( version );
169 sb.append( ", type='" ).append( type ).append( '\'' );
170 sb.append( ", classifier='" ).append( classifier ).append( '\'' );
171 sb.append( ", remainder='" ).append( remainder ).append( '\'' );
172 sb.append( ", contentType='" ).append( contentType ).append( '\'' );
173 sb.append( ", artifactType=" ).append( artifactType );
175 return sb.toString( );
178 private static class Builder
179 extends ContentItemBuilder<ArchivaArtifact, ArtifactOptBuilder, WithVersionObjectBuilder>
180 implements ArtifactVersionBuilder, WithVersionObjectBuilder, ArtifactWithIdBuilder, ArtifactOptBuilder
185 super( new ArchivaArtifact( ) );
189 protected ArtifactOptBuilder getOptBuilder( )
195 protected WithVersionObjectBuilder getNextBuilder( )
201 public ArtifactWithIdBuilder withVersion( Version version )
203 if ( version == null )
205 throw new IllegalArgumentException( "version may not be null" );
207 item.version = version;
208 super.setRepository( version.getRepository( ) );
213 public ArtifactOptBuilder withId( String id )
215 if ( StringUtils.isEmpty( id ) )
217 throw new IllegalArgumentException( "Artifact id may not be null or empty" );
225 public ArtifactOptBuilder withArtifactVersion( String version )
227 if ( version == null )
229 throw new IllegalArgumentException( "version may not be null" );
231 item.artifactVersion = version;
236 public ArtifactOptBuilder withType( String type )
243 public ArtifactOptBuilder withClassifier( String classifier )
245 item.classifier = classifier;
250 public ArtifactOptBuilder withRemainder( String remainder )
252 item.remainder = remainder;
257 public ArtifactOptBuilder withContentType( String contentType )
259 item.contentType = contentType;
264 public ArtifactOptBuilder withArtifactType( ArtifactType type )
266 item.artifactType = type;
271 public ArchivaArtifact build( )
274 if ( item.artifactVersion == null )
276 item.artifactVersion = "";
278 if ( item.classifier == null )
280 item.classifier = "";
282 if ( item.type == null )
286 if ( item.contentType == null )
288 item.contentType = "";
290 if ( item.remainder == null )
294 if (item.artifactType==null) {
295 item.artifactType = BaseArtifactTypes.MAIN;