View Javadoc

1   package org.apache.maven.dist;
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.MavenException;
22  import org.apache.maven.project.Project;
23  import org.apache.maven.repository.ArtifactTypeHandler;
24  
25  /**
26   *  This will do until wagon debuts.
27   *
28   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
29   * @version $Id: DistributionArtifactTypeHandler.java 532339 2007-04-25 12:28:56Z ltheussl $
30   */
31  public class DistributionArtifactTypeHandler 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 MavenException
40       */
41      public String constructRepositoryDirectoryPath( String type, Project project )
42          throws MavenException
43      {
44          StringBuffer path = new StringBuffer();
45  
46          path.append( project.getArtifactDirectory() );
47          path.append( "/distributions/" );
48  
49          return path.toString();
50      }
51  
52      /**
53       * Map an artifact to a repository path.
54       *
55       * @param project the project for the artifact
56       * @param type  The type of the artifact
57       * @param version  The version of the artifact (may be a snapshot)
58       * @return the path
59       * @throws MavenException MavenException
60       */
61      public String constructRepositoryFullPath( String type, Project project,
62          String version ) throws MavenException
63      {
64          StringBuffer path =
65              new StringBuffer( constructRepositoryDirectoryPath( type, project ) );
66  
67          path.append( project.getArtifactId() );
68          path.append( "-" );
69          path.append( version );
70  
71          if ( !type.startsWith( "distribution" ) )
72          {
73              throw new MavenException( "Type is not a distribution (is " + type
74                  + ")" );
75          }
76  
77          String subtype = type.substring( 12 );
78  
79          if ( subtype.startsWith( "-src" ) )
80          {
81              path.append( "-src" );
82              subtype = subtype.substring( 4 );
83          }
84  
85          if ( subtype.equals( "-targz" ) )
86          {
87              path.append( ".tar.gz" );
88          }
89          else if ( subtype.equals( "-tarbz2" ) )
90          {
91              path.append( ".tar.bz2" );
92          }
93          else if ( subtype.equals( "-zip" ) )
94          {
95              path.append( ".zip" );
96          }
97          else
98          {
99              throw new MavenException( "Unrecognised distribution type (is "
100                 + type + ")" );
101         }
102 
103         return path.toString();
104     }
105 }