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