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  
27  /**
28   * @author jdcasey
29   */
30  public class LegacyRepositoryLayout
31      implements ArtifactRepositoryLayout
32  {
33  
34      private static final String PATH_SEPARATOR = "/";
35  
36      public String getId()
37      {
38          return "legacy";
39      }
40  
41      @Override
42      public String pathOf( Artifact artifact )
43      {
44          ArtifactHandler artifactHandler = artifact.getArtifactHandler();
45  
46          StringBuilder path = new StringBuilder( 128 );
47  
48          path.append( artifact.getGroupId() ).append( '/' );
49          path.append( artifactHandler.getDirectory() ).append( '/' );
50          path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() );
51  
52          if ( artifact.hasClassifier() )
53          {
54              path.append( '-' ).append( artifact.getClassifier() );
55          }
56  
57          if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 )
58          {
59              path.append( '.' ).append( artifactHandler.getExtension() );
60          }
61  
62          return path.toString();
63      }
64  
65      @Override
66      public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
67      {
68          return pathOfRepositoryMetadata( metadata, metadata.getLocalFilename( repository ) );
69      }
70  
71      private String pathOfRepositoryMetadata( ArtifactMetadata metadata, String filename )
72      {
73          StringBuilder path = new StringBuilder( 128 );
74  
75          path.append( metadata.getGroupId() ).append( PATH_SEPARATOR ).append( "poms" ).append( PATH_SEPARATOR );
76  
77          path.append( filename );
78  
79          return path.toString();
80      }
81  
82      @Override
83      public String pathOfRemoteRepositoryMetadata( ArtifactMetadata metadata )
84      {
85          return pathOfRepositoryMetadata( metadata, metadata.getRemoteFilename() );
86      }
87  
88  }