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 public String pathOfLocalRepositoryMetadata(ArtifactMetadata metadata, ArtifactRepository repository) {
105 return userLocalArtifactRepository.pathOfLocalRepositoryMetadata(metadata, repository);
106 }
107
108 public String getId() {
109 return userLocalArtifactRepository.getId();
110 }
111
112 @Override
113 public String pathOf(Artifact artifact) {
114 return userLocalArtifactRepository.pathOf(artifact);
115 }
116
117 @Override
118 public String getBasedir() {
119 return (userLocalArtifactRepository != null) ? userLocalArtifactRepository.getBasedir() : null;
120 }
121
122 @Override
123 public ArtifactRepositoryLayout getLayout() {
124 return userLocalArtifactRepository.getLayout();
125 }
126
127 @Override
128 public ArtifactRepositoryPolicy getReleases() {
129 return userLocalArtifactRepository.getReleases();
130 }
131
132 @Override
133 public ArtifactRepositoryPolicy getSnapshots() {
134 return userLocalArtifactRepository.getSnapshots();
135 }
136
137 @Override
138 public String getKey() {
139 return userLocalArtifactRepository.getKey();
140 }
141
142 @Override
143 public String getUrl() {
144 return userLocalArtifactRepository.getUrl();
145 }
146
147 @Override
148 public int hashCode() {
149 int hash = 17;
150 hash = hash * 31 + (buildReactor == null ? 0 : buildReactor.hashCode());
151 hash = hash * 31 + (ideWorkspace == null ? 0 : ideWorkspace.hashCode());
152 hash = hash * 31 + (userLocalArtifactRepository == null ? 0 : userLocalArtifactRepository.hashCode());
153
154 return hash;
155 }
156
157 @Override
158 public boolean equals(Object obj) {
159 if (this == obj) {
160 return true;
161 }
162 if (obj == null) {
163 return false;
164 }
165 if (getClass() != obj.getClass()) {
166 return false;
167 }
168
169 DelegatingLocalArtifactRepository other = (DelegatingLocalArtifactRepository) obj;
170
171 return eq(buildReactor, other.buildReactor)
172 && eq(ideWorkspace, other.ideWorkspace)
173 && eq(userLocalArtifactRepository, other.userLocalArtifactRepository);
174 }
175 }