View Javadoc

1   /**
2    * The MIT License
3    *
4    * Copyright 2006-2012 The Codehaus.
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy of
7    * this software and associated documentation files (the "Software"), to deal in
8    * the Software without restriction, including without limitation the rights to
9    * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10   * of the Software, and to permit persons to whom the Software is furnished to do
11   * so, subject to the following conditions:
12   *
13   * The above copyright notice and this permission notice shall be included in all
14   * copies or substantial portions of the Software.
15   *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22   * SOFTWARE.
23   */
24  package org.codehaus.mojo.appassembler.repository;
25  
26  import org.apache.maven.artifact.Artifact;
27  import org.apache.maven.artifact.handler.ArtifactHandler;
28  import org.apache.maven.artifact.metadata.ArtifactMetadata;
29  import org.apache.maven.artifact.repository.ArtifactRepository;
30  import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
31  
32  /**
33   * The code in this class is taken from DefaultRepositorylayout, located at:
34   * http://svn.apache.org/viewvc/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/repository
35   * /layout/DefaultRepositoryLayout.java
36   * 
37   * @version $Id: FlatRepositoryLayout.java 16448 2012-04-22 15:47:18Z khmarbaise $
38   * @plexus.component role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" role-hint="flat"
39   */
40  public class FlatRepositoryLayout
41          implements ArtifactRepositoryLayout
42  {
43      private static final char ARTIFACT_SEPARATOR = '-';
44  
45      private static final char GROUP_SEPARATOR = '.';
46  
47      public String pathOf ( Artifact artifact )
48      {
49          ArtifactHandler artifactHandler = artifact.getArtifactHandler ( );
50  
51          StringBuffer path = new StringBuffer ( );
52  
53          path.append ( artifact.getArtifactId ( ) ).append ( ARTIFACT_SEPARATOR ).append ( artifact.getVersion ( ) );
54  
55          if ( artifact.hasClassifier ( ) )
56          {
57              path.append ( ARTIFACT_SEPARATOR ).append ( artifact.getClassifier ( ) );
58          }
59  
60          if ( artifactHandler.getExtension ( ) != null && artifactHandler.getExtension ( ).length ( ) > 0 )
61          {
62              path.append ( GROUP_SEPARATOR ).append ( artifactHandler.getExtension ( ) );
63          }
64  
65          return path.toString ( );
66      }
67  
68      public String pathOfLocalRepositoryMetadata ( ArtifactMetadata metadata, ArtifactRepository repository )
69      {
70          return pathOfRepositoryMetadata ( metadata.getLocalFilename ( repository ) );
71      }
72  
73      private String pathOfRepositoryMetadata ( String filename )
74      {
75          StringBuffer path = new StringBuffer ( );
76  
77          path.append ( filename );
78  
79          return path.toString ( );
80      }
81  
82      public String pathOfRemoteRepositoryMetadata ( ArtifactMetadata metadata )
83      {
84          return pathOfRepositoryMetadata ( metadata.getRemoteFilename ( ) );
85      }
86  }