View Javadoc

1   package org.apache.maven.plugin.source;
2   
3   /* ====================================================================
4    *   Copyright 2001-2005 The Apache Software Foundation.
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
17   * ====================================================================
18   */
19  
20  import org.apache.maven.MavenException;
21  import org.apache.maven.project.Project;
22  import org.apache.maven.repository.ArtifactTypeHandler;
23  
24  /**
25   * Java sources artifact type handler.
26   *
27   * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
28   * @version $Id: JavaSourceArtifactTypeHandler.java 371078 2006-01-21 15:55:44Z snicoll $
29   */
30  public class JavaSourceArtifactTypeHandler
31      implements ArtifactTypeHandler
32  {
33      /**
34       * Map an artifact to a repository directory path.
35       *
36       * @param project the project for the artifact
37       * @param type    The type of the artifact
38       * @return the path
39       * @throws MavenException if an error occured while building the path
40       */
41      public String constructRepositoryDirectoryPath( String type, Project project )
42          throws MavenException
43      {
44          StringBuffer path = new StringBuffer();
45          path.append( project.getArtifactDirectory() );
46          path.append( "/java-sources/" );
47          return path.toString();
48      }
49  
50      /**
51       * Map an artifact to a repository path.
52       *
53       * @param project the project for the artifact
54       * @param type    The type of the artifact
55       * @param version The version of the artifact (may be a snapshot)
56       * @return the path
57       * @throws MavenException if an error occured while building the path
58       */
59      public String constructRepositoryFullPath( String type, Project project, String version )
60          throws MavenException
61      {
62          StringBuffer path = new StringBuffer( constructRepositoryDirectoryPath( type, project ) );
63          path.append( project.getArtifactId() );
64          path.append( "-" );
65          path.append( version );
66  
67          if ( type.equals( "java-source" ) )
68          {
69              path.append( "-sources.jar" );
70          }
71          else
72          {
73              throw new MavenException( "Unrecognised java-source type (is " + type + ")" );
74          }
75  
76          return path.toString();
77      }
78  }