This project has retired. For details please refer to its Attic page.
LegacyRepositoryLayout xref
View Javadoc
1   package org.apache.archiva.converter.artifact;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with 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,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import org.apache.maven.artifact.Artifact;
22  import org.apache.maven.artifact.handler.ArtifactHandler;
23  import org.apache.maven.artifact.metadata.ArtifactMetadata;
24  import org.apache.maven.artifact.repository.ArtifactRepository;
25  import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
26  import org.codehaus.plexus.component.annotations.Component;
27  
28  /**
29   * @author jdcasey
30   */
31  @Component( role = ArtifactRepositoryLayout.class, hint = "legacy")
32  public class LegacyRepositoryLayout
33      implements ArtifactRepositoryLayout
34  {
35  
36      private static final String PATH_SEPARATOR = "/";
37  
38      public String getId()
39      {
40          return "legacy";
41      }
42  
43      @Override
44      public String pathOf( Artifact artifact )
45      {
46          ArtifactHandler artifactHandler = artifact.getArtifactHandler();
47  
48          StringBuilder path = new StringBuilder( 128 );
49  
50          path.append( artifact.getGroupId() ).append( '/' );
51          path.append( artifactHandler.getDirectory() ).append( '/' );
52          path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() );
53  
54          if ( artifact.hasClassifier() )
55          {
56              path.append( '-' ).append( artifact.getClassifier() );
57          }
58  
59          if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 )
60          {
61              path.append( '.' ).append( artifactHandler.getExtension() );
62          }
63  
64          return path.toString();
65      }
66  
67      @Override
68      public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
69      {
70          return pathOfRepositoryMetadata( metadata, metadata.getLocalFilename( repository ) );
71      }
72  
73      private String pathOfRepositoryMetadata( ArtifactMetadata metadata, String filename )
74      {
75          StringBuilder path = new StringBuilder( 128 );
76  
77          path.append( metadata.getGroupId() ).append( PATH_SEPARATOR ).append( "poms" ).append( PATH_SEPARATOR );
78  
79          path.append( filename );
80  
81          return path.toString();
82      }
83  
84      @Override
85      public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata )
86      {
87          return pathOfRepositoryMetadata( metadata, metadata.getRemoteFilename() );
88      }
89  
90  }