View Javadoc

1   package org.apache.maven.project;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  
24  import org.sonatype.aether.RepositorySystemSession;
25  import org.sonatype.aether.artifact.Artifact;
26  import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
27  import org.sonatype.aether.repository.LocalArtifactRequest;
28  import org.sonatype.aether.repository.LocalArtifactResult;
29  
30  /**
31   * @author Benjamin Bentmann
32   */
33  public class LegacyLocalRepositoryManager
34      extends SimpleLocalRepositoryManager
35  {
36  
37      public LegacyLocalRepositoryManager( File basedir )
38      {
39          super( basedir );
40      }
41  
42      public String getPathForLocalArtifact( Artifact artifact )
43      {
44          StringBuilder path = new StringBuilder( 128 );
45  
46          path.append( artifact.getGroupId() ).append( '/' );
47  
48          path.append( artifact.getExtension() ).append( 's' ).append( '/' );
49  
50          path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() );
51  
52          if ( artifact.getClassifier().length() > 0 )
53          {
54              path.append( '-' ).append( artifact.getClassifier() );
55          }
56  
57          path.append( '.' ).append( artifact.getExtension() );
58  
59          return path.toString();
60      }
61  
62      public LocalArtifactResult find( RepositorySystemSession session, LocalArtifactRequest request )
63      {
64   	    String path = getPathForLocalArtifact( request.getArtifact() );
65   	    File file = new File( getRepository().getBasedir(), path );
66          LocalArtifactResult result = new LocalArtifactResult( request );
67   	    if ( file.isFile() )
68          {
69   	        result.setFile( file );
70   	        result.setAvailable( true );
71   	    }
72   	    return result;
73   	}
74  
75  }