1 package org.apache.maven.repository;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
37
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
65
66
67 @Deprecated
68 public LocalArtifactRepository getIdeWorspace()
69 {
70 return ideWorkspace;
71 }
72
73 public LocalArtifactRepository getIdeWorkspace()
74 {
75 return getIdeWorspace();
76 }
77
78 @Override
79 public Artifact find( Artifact artifact )
80 {
81 if ( !artifact.isRelease() && buildReactor != null )
82 {
83 artifact = buildReactor.find( artifact );
84 }
85
86 if ( !artifact.isResolved() && ideWorkspace != null )
87 {
88 artifact = ideWorkspace.find( artifact );
89 }
90
91 if ( !artifact.isResolved() )
92 {
93 artifact = userLocalArtifactRepository.find( artifact );
94 }
95
96 return artifact;
97 }
98
99 @Override
100 public List<String> findVersions( Artifact artifact )
101 {
102 Collection<String> versions = new LinkedHashSet<>();
103
104 if ( buildReactor != null )
105 {
106 versions.addAll( buildReactor.findVersions( artifact ) );
107 }
108
109 if ( ideWorkspace != null )
110 {
111 versions.addAll( ideWorkspace.findVersions( artifact ) );
112 }
113
114 versions.addAll( userLocalArtifactRepository.findVersions( artifact ) );
115
116 return Collections.unmodifiableList( new ArrayList<>( versions ) );
117 }
118
119 public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
120 {
121 return userLocalArtifactRepository.pathOfLocalRepositoryMetadata( metadata, repository );
122 }
123
124 public String getId()
125 {
126 return userLocalArtifactRepository.getId();
127 }
128
129 @Override
130 public String pathOf( Artifact artifact )
131 {
132 return userLocalArtifactRepository.pathOf( artifact );
133 }
134
135 @Override
136 public String getBasedir()
137 {
138 return ( userLocalArtifactRepository != null ) ? userLocalArtifactRepository.getBasedir() : null;
139 }
140
141 @Override
142 public ArtifactRepositoryLayout getLayout()
143 {
144 return userLocalArtifactRepository.getLayout();
145 }
146
147 @Override
148 public ArtifactRepositoryPolicy getReleases()
149 {
150 return userLocalArtifactRepository.getReleases();
151 }
152
153 @Override
154 public ArtifactRepositoryPolicy getSnapshots()
155 {
156 return userLocalArtifactRepository.getSnapshots();
157 }
158
159 @Override
160 public String getKey()
161 {
162 return userLocalArtifactRepository.getKey();
163 }
164
165 @Override
166 public String getUrl()
167 {
168 return userLocalArtifactRepository.getUrl();
169 }
170
171 @Override
172 public int hashCode()
173 {
174 int hash = 17;
175 hash = hash * 31 + ( buildReactor == null ? 0 : buildReactor.hashCode() );
176 hash = hash * 31 + ( ideWorkspace == null ? 0 : ideWorkspace.hashCode() );
177 hash = hash * 31 + ( userLocalArtifactRepository == null ? 0 : userLocalArtifactRepository.hashCode() );
178
179 return hash;
180 }
181
182 @Override
183 public boolean equals( Object obj )
184 {
185 if ( this == obj )
186 {
187 return true;
188 }
189 if ( obj == null )
190 {
191 return false;
192 }
193 if ( getClass() != obj.getClass() )
194 {
195 return false;
196 }
197
198 DelegatingLocalArtifactRepository other = (DelegatingLocalArtifactRepository) obj;
199
200 return eq( buildReactor, other.buildReactor )
201 && eq( ideWorkspace, other.ideWorkspace )
202 && eq( userLocalArtifactRepository, other.userLocalArtifactRepository );
203 }
204 }