001 package org.apache.maven.repository;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.util.ArrayList;
023 import java.util.Collection;
024 import java.util.Collections;
025 import java.util.LinkedHashSet;
026 import java.util.List;
027
028 import org.apache.maven.artifact.Artifact;
029 import org.apache.maven.artifact.metadata.ArtifactMetadata;
030 import org.apache.maven.artifact.repository.ArtifactRepository;
031 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
032 import org.apache.maven.artifact.repository.MavenArtifactRepository;
033 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
034
035 /**
036 * Delegating local artifact repository chains the reactor, IDE workspace
037 * and user local repository.
038 */
039 @Deprecated
040 public class DelegatingLocalArtifactRepository
041 extends MavenArtifactRepository
042 {
043 private LocalArtifactRepository buildReactor;
044
045 private LocalArtifactRepository ideWorkspace;
046
047 private ArtifactRepository userLocalArtifactRepository;
048
049 public DelegatingLocalArtifactRepository( ArtifactRepository artifactRepository )
050 {
051 this.userLocalArtifactRepository = artifactRepository;
052 }
053
054 public void setBuildReactor( LocalArtifactRepository localRepository )
055 {
056 this.buildReactor = localRepository;
057 }
058
059 public void setIdeWorkspace( LocalArtifactRepository localRepository )
060 {
061 this.ideWorkspace = localRepository;
062 }
063
064 public LocalArtifactRepository getIdeWorspace()
065 {
066 return ideWorkspace;
067 }
068
069 @Override
070 public Artifact find( Artifact artifact )
071 {
072 if ( !artifact.isRelease() && buildReactor != null )
073 {
074 artifact = buildReactor.find( artifact );
075 }
076
077 if ( !artifact.isResolved() && ideWorkspace != null )
078 {
079 artifact = ideWorkspace.find( artifact );
080 }
081
082 if ( !artifact.isResolved() )
083 {
084 artifact = userLocalArtifactRepository.find( artifact );
085 }
086
087 return artifact;
088 }
089
090 @Override
091 public List<String> findVersions( Artifact artifact )
092 {
093 Collection<String> versions = new LinkedHashSet<String>();
094
095 if ( buildReactor != null )
096 {
097 versions.addAll( buildReactor.findVersions( artifact ) );
098 }
099
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 }