View Javadoc

1   package org.sonatype.aether.util.layout;
2   
3   /*******************************************************************************
4    * Copyright (c) 2010-2011 Sonatype, Inc.
5    * All rights reserved. This program and the accompanying materials
6    * are made available under the terms of the Eclipse Public License v1.0
7    * which accompanies this distribution, and is available at
8    *   http://www.eclipse.org/legal/epl-v10.html
9    *******************************************************************************/
10  
11  import java.net.URI;
12  import java.net.URISyntaxException;
13  
14  import org.sonatype.aether.artifact.Artifact;
15  import org.sonatype.aether.metadata.Metadata;
16  
17  /**
18   * The layout for a Maven remote repository of type "default".
19   * 
20   * @author Benjamin Bentmann
21   */
22  public class MavenDefaultLayout
23      implements RepositoryLayout
24  {
25  
26      private URI toUri( String path )
27      {
28          try
29          {
30              return new URI( null, null, path, null );
31          }
32          catch ( URISyntaxException e )
33          {
34              throw new IllegalStateException( e );
35          }
36      }
37  
38      public URI getPath( Artifact artifact )
39      {
40          StringBuilder path = new StringBuilder( 128 );
41  
42          path.append( artifact.getGroupId().replace( '.', '/' ) ).append( '/' );
43  
44          path.append( artifact.getArtifactId() ).append( '/' );
45  
46          path.append( artifact.getBaseVersion() ).append( '/' );
47  
48          path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() );
49  
50          if ( artifact.getClassifier().length() > 0 )
51          {
52              path.append( '-' ).append( artifact.getClassifier() );
53          }
54  
55          if ( artifact.getExtension().length() > 0 )
56          {
57              path.append( '.' ).append( artifact.getExtension() );
58          }
59  
60          return toUri( path.toString() );
61      }
62  
63      public URI getPath( Metadata metadata )
64      {
65          StringBuilder path = new StringBuilder( 128 );
66  
67          if ( metadata.getGroupId().length() > 0 )
68          {
69              path.append( metadata.getGroupId().replace( '.', '/' ) ).append( '/' );
70  
71              if ( metadata.getArtifactId().length() > 0 )
72              {
73                  path.append( metadata.getArtifactId() ).append( '/' );
74  
75                  if ( metadata.getVersion().length() > 0 )
76                  {
77                      path.append( metadata.getVersion() ).append( '/' );
78                  }
79              }
80          }
81  
82          path.append( metadata.getType() );
83  
84          return toUri( path.toString() );
85      }
86  
87  }