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