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.maven.artifact.InvalidArtifactRTException;
23 import org.apache.maven.artifact.repository.ArtifactRepository;
24 import org.codehaus.plexus.util.StringUtils;
31 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
34 * @plexus.component role="org.apache.maven.archiva.model.ArchivaArtifact"
36 public class ArchivaArtifact
37 implements RepositoryContent
41 private String classifier;
43 private RepositoryContentKey key;
47 public ArchivaArtifact( ArtifactRepository repository, String groupId, String artifactId, String version, String classifier, String type )
49 this.key = new RepositoryContentKey( repository, groupId, artifactId, version );
51 this.classifier = classifier;
58 public void addAttached( ArchivaArtifact attachedArtifact )
60 attached.put( attachedArtifact.getClassifier(), attachedArtifact );
61 // Naughty, Attached shouldn't have it's own attached artifacts!
62 attachedArtifact.clearAttached();
65 public void clearAttached()
70 public Map getAttached()
75 public String getClassifier()
80 public RepositoryContentKey getRepositoryContentKey()
85 public String getType()
90 public boolean hasClassifier()
92 return StringUtils.isNotEmpty( classifier );
95 public void setAttached( Map attached )
97 this.attached = attached;
100 public void setRepositoryContentKey( RepositoryContentKey key )
105 public String toString()
107 StringBuffer sb = new StringBuffer();
108 if ( key.getGroupId() != null )
110 sb.append( key.getGroupId() );
113 appendArtifactTypeClassifierString( sb );
115 if ( key.getVersion() != null )
117 sb.append( key.getVersion() );
120 return sb.toString();
123 private void appendArtifactTypeClassifierString( StringBuffer sb )
125 sb.append( key.getArtifactId() );
127 sb.append( getType() );
128 if ( hasClassifier() )
131 sb.append( getClassifier() );
135 private boolean empty( String value )
137 return value == null || value.trim().length() < 1;
140 private void validateIdentity()
142 if ( empty( key.getGroupId() ) )
144 throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
145 "The groupId cannot be empty." );
148 if ( key.getArtifactId() == null )
150 throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
151 "The artifactId cannot be empty." );
156 throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
157 "The type cannot be empty." );
160 if ( key.getVersion() == null )
162 throw new InvalidArtifactRTException( key.getGroupId(), key.getArtifactId(), key.getVersion(), type,
163 "The version cannot be empty." );