View Javadoc
1   package org.apache.maven.repository;
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.apache.maven.artifact.Artifact;
25  import org.apache.maven.artifact.metadata.ArtifactMetadata;
26  import org.apache.maven.artifact.repository.ArtifactRepository;
27  
28  /**
29   * UserLocalArtifactRepository
30   */
31  public class UserLocalArtifactRepository
32      extends LocalArtifactRepository
33  {
34      private ArtifactRepository localRepository;
35  
36      public UserLocalArtifactRepository( ArtifactRepository localRepository )
37      {
38          this.localRepository = localRepository;
39          setLayout( localRepository.getLayout() );
40      }
41  
42      @Override
43      public Artifact find( Artifact artifact )
44      {
45          File artifactFile = new File( localRepository.getBasedir(), pathOf( artifact ) );
46  
47          // We need to set the file here or the resolver will fail with an NPE, not fully equipped to deal
48          // with multiple local repository implementations yet.
49          artifact.setFile( artifactFile );
50  
51          return artifact;
52      }
53  
54      @Override
55      public String getId()
56      {
57          return localRepository.getId();
58      }
59  
60      @Override
61      public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
62      {
63          return localRepository.pathOfLocalRepositoryMetadata( metadata, repository );
64      }
65  
66      @Override
67      public String pathOf( Artifact artifact )
68      {
69          return localRepository.pathOf( artifact );
70      }
71  
72      @Override
73      public boolean hasLocalMetadata()
74      {
75          return true;
76      }
77  }