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.util.ArrayList;
23  import java.util.Collection;
24  import java.util.Collections;
25  import java.util.LinkedHashSet;
26  import java.util.List;
27  
28  import org.apache.maven.artifact.Artifact;
29  import org.apache.maven.artifact.metadata.ArtifactMetadata;
30  import org.apache.maven.artifact.repository.ArtifactRepository;
31  import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
32  import org.apache.maven.artifact.repository.MavenArtifactRepository;
33  import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
34  
35  /**
36   * Delegating local artifact repository chains the reactor, IDE workspace
37   * and user local repository.
38   */
39  @Deprecated
40  public class DelegatingLocalArtifactRepository
41      extends MavenArtifactRepository
42  {
43      private LocalArtifactRepository buildReactor;
44  
45      private LocalArtifactRepository ideWorkspace;
46  
47      private ArtifactRepository userLocalArtifactRepository;
48  
49      public DelegatingLocalArtifactRepository( ArtifactRepository artifactRepository )
50      {
51          this.userLocalArtifactRepository = artifactRepository;
52      }
53  
54      public void setBuildReactor( LocalArtifactRepository localRepository )
55      {
56          this.buildReactor = localRepository;
57      }
58  
59      public void setIdeWorkspace( LocalArtifactRepository localRepository )
60      {
61          this.ideWorkspace = localRepository;
62      }
63  
64      public LocalArtifactRepository getIdeWorspace()
65      {
66          return ideWorkspace;
67      }
68  
69      @Override
70      public Artifact find( Artifact artifact )
71      {
72          if ( !artifact.isRelease() && buildReactor != null )
73          {
74              artifact = buildReactor.find( artifact );
75          }
76  
77          if ( !artifact.isResolved() && ideWorkspace != null )
78          {
79              artifact = ideWorkspace.find( artifact );
80          }
81  
82          if ( !artifact.isResolved() )
83          {
84              artifact = userLocalArtifactRepository.find( artifact );
85          }
86  
87          return artifact;
88      }
89  
90      @Override
91      public List<String> findVersions( Artifact artifact )
92      {
93          Collection<String> versions = new LinkedHashSet<String>();
94  
95          if ( buildReactor != null )
96          {
97              versions.addAll( buildReactor.findVersions( artifact ) );
98          }
99  
100         if ( ideWorkspace != null )
101         {
102             versions.addAll( ideWorkspace.findVersions( artifact ) );
103         }
104 
105         versions.addAll( userLocalArtifactRepository.findVersions( artifact ) );
106 
107         return Collections.unmodifiableList( new ArrayList<String>( versions ) );
108     }
109 
110     public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
111     {
112         return userLocalArtifactRepository.pathOfLocalRepositoryMetadata( metadata, repository );
113     }
114 
115     public String getId()
116     {
117         return userLocalArtifactRepository.getId();
118     }
119 
120     @Override
121     public String pathOf( Artifact artifact )
122     {
123         return userLocalArtifactRepository.pathOf( artifact );
124     }
125 
126     @Override
127     public String getBasedir()
128     {
129         return ( userLocalArtifactRepository != null ) ? userLocalArtifactRepository.getBasedir() : null;
130     }
131 
132     @Override
133     public ArtifactRepositoryLayout getLayout()
134     {
135         return userLocalArtifactRepository.getLayout();
136     }
137 
138     @Override
139     public ArtifactRepositoryPolicy getReleases()
140     {
141         return userLocalArtifactRepository.getReleases();
142     }
143 
144     @Override
145     public ArtifactRepositoryPolicy getSnapshots()
146     {
147         return userLocalArtifactRepository.getSnapshots();
148     }
149 
150     @Override
151     public String getKey()
152     {
153         return userLocalArtifactRepository.getKey();
154     }
155 
156     @Override
157     public String getUrl()
158     {
159         return userLocalArtifactRepository.getUrl();
160     }
161 
162     @Override
163     public int hashCode()
164     {
165         int hash = 17;
166         hash = hash * 31 + ( buildReactor == null ? 0 : buildReactor.hashCode() );
167         hash = hash * 31 + ( ideWorkspace == null ? 0 : ideWorkspace.hashCode() );
168         hash = hash * 31 + ( userLocalArtifactRepository == null ? 0 : userLocalArtifactRepository.hashCode() );
169 
170         return hash;
171     }
172 
173     @Override
174     public boolean equals( Object obj )
175     {
176         if ( this == obj )
177         {
178             return true;
179         }
180         if ( obj == null )
181         {
182             return false;
183         }
184         if ( getClass() != obj.getClass() )
185         {
186             return false;
187         }
188 
189         DelegatingLocalArtifactRepository other = (DelegatingLocalArtifactRepository) obj;
190 
191         return eq( buildReactor, other.buildReactor )
192             && eq( ideWorkspace, other.ideWorkspace )
193             && eq( userLocalArtifactRepository, other.userLocalArtifactRepository );
194     }
195 }