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