View Javadoc

1   package org.apache.maven.artifact.deployer;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
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  }