1 package org.apache.maven.artifact.deployer;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import org.apache.maven.project.Project;
22 import org.apache.maven.repository.DefaultArtifactTypeHandler;
23
24 /**
25 * This handler allows the default artifactId to be overridden.
26 *
27 * @author <a href="mailto:neilc@strate.co.za">Neil Crow</a>
28 */
29 public class NamedArtifactTypeHandler
30 extends DefaultArtifactTypeHandler
31 {
32 /** The artifactId. */
33 private String artifactId = null;
34
35 /**
36 * @return String
37 */
38 public String getArtifactId()
39 {
40 return this.artifactId;
41 }
42
43 /**
44 * @param newId - The artifactId which overides the pom default.
45 */
46 public void setArtifactId( final String newId )
47 {
48 this.artifactId = newId;
49 }
50
51 /**
52 * Map an artifact to a repository path.
53 *
54 * @param project the project for the artifact
55 * @param type The type of the artifact
56 * @param version The version of the artifact (may be a snapshot)
57 * @return the path
58 */
59 public String constructRepositoryFullPath( final String type, final Project project, final String version )
60 {
61 if ( this.artifactId == null )
62 {
63 this.artifactId = project.getArtifactId();
64 }
65 final StringBuffer path = new StringBuffer( this.constructRepositoryDirectoryPath( type, project ) );
66 path.append( this.artifactId );
67 path.append( "-" );
68 path.append( version );
69 path.append( this.extensionForType( type ) );
70 return path.toString();
71 }
72
73 /** plugin, ejb and uberjar should provide their own implementation.
74 * @param type type
75 * @return extension
76 */
77 private String extensionForType( final String type )
78 {
79 if ( type.equals( "uberjar" ) || type.equals( "ejb" ) || type.equals( "plugin" ) )
80 {
81 return ".jar";
82 }
83 else
84 {
85 return "." + type;
86 }
87 }
88
89 }