001 package org.apache.maven.artifact.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.io.File;
023 import java.util.Collections;
024 import java.util.List;
025
026 import org.apache.maven.artifact.Artifact;
027 import org.apache.maven.artifact.metadata.ArtifactMetadata;
028 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
029 import org.apache.maven.repository.Proxy;
030 import org.apache.maven.wagon.repository.Repository;
031
032 /**
033 * This class is an abstraction of the location from/to resources can be
034 * transfered.
035 *
036 * @author <a href="michal.maczka@dimatics.com">Michal Maczka </a>
037 */
038 @Deprecated
039 public class DefaultArtifactRepository
040 extends Repository
041 implements ArtifactRepository
042 {
043 private ArtifactRepositoryLayout layout;
044
045 private ArtifactRepositoryPolicy snapshots;
046
047 private ArtifactRepositoryPolicy releases;
048
049 private boolean blacklisted;
050
051 private Authentication authentication;
052
053 private Proxy proxy;
054
055 private List<ArtifactRepository> mirroredRepositories = Collections.emptyList();
056
057 /**
058 * Create a local repository or a test repository.
059 *
060 * @param id the unique identifier of the repository
061 * @param url the URL of the repository
062 * @param layout the layout of the repository
063 */
064 public DefaultArtifactRepository( String id, String url, ArtifactRepositoryLayout layout )
065 {
066 this( id, url, layout, null, null );
067 }
068
069 /**
070 * Create a remote deployment repository.
071 *
072 * @param id the unique identifier of the repository
073 * @param url the URL of the repository
074 * @param layout the layout of the repository
075 * @param uniqueVersion whether to assign each snapshot a unique version
076 */
077 public DefaultArtifactRepository( String id, String url, ArtifactRepositoryLayout layout, boolean uniqueVersion )
078 {
079 super( id, url );
080 this.layout = layout;
081 }
082
083 /**
084 * Create a remote download repository.
085 *
086 * @param id the unique identifier of the repository
087 * @param url the URL of the repository
088 * @param layout the layout of the repository
089 * @param snapshots the policies to use for snapshots
090 * @param releases the policies to use for releases
091 */
092 public DefaultArtifactRepository( String id, String url, ArtifactRepositoryLayout layout,
093 ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases )
094 {
095 super( id, url );
096
097 this.layout = layout;
098
099 if ( snapshots == null )
100 {
101 snapshots = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
102 ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
103 }
104
105 this.snapshots = snapshots;
106
107 if ( releases == null )
108 {
109 releases = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
110 ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
111 }
112
113 this.releases = releases;
114 }
115
116 public String pathOf( Artifact artifact )
117 {
118 return layout.pathOf( artifact );
119 }
120
121 public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata )
122 {
123 return layout.pathOfRemoteRepositoryMetadata( artifactMetadata );
124 }
125
126 public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
127 {
128 return layout.pathOfLocalRepositoryMetadata( metadata, repository );
129 }
130
131 public void setLayout( ArtifactRepositoryLayout layout )
132 {
133 this.layout = layout;
134 }
135
136 public ArtifactRepositoryLayout getLayout()
137 {
138 return layout;
139 }
140
141 public void setSnapshotUpdatePolicy( ArtifactRepositoryPolicy snapshots )
142 {
143 this.snapshots = snapshots;
144 }
145
146 public ArtifactRepositoryPolicy getSnapshots()
147 {
148 return snapshots;
149 }
150
151 public void setReleaseUpdatePolicy( ArtifactRepositoryPolicy releases )
152 {
153 this.releases = releases;
154 }
155
156 public ArtifactRepositoryPolicy getReleases()
157 {
158 return releases;
159 }
160
161 public String getKey()
162 {
163 return getId();
164 }
165
166 public boolean isBlacklisted()
167 {
168 return blacklisted;
169 }
170
171 public void setBlacklisted( boolean blacklisted )
172 {
173 this.blacklisted = blacklisted;
174 }
175
176 public String toString()
177 {
178 StringBuilder sb = new StringBuilder();
179
180 sb.append( " id: " ).append( getId() ).append( "\n" );
181 sb.append( " url: " ).append( getUrl() ).append( "\n" );
182 sb.append( " layout: " ).append( layout != null ? layout : "none" ).append( "\n" );
183
184 if ( snapshots != null )
185 {
186 sb.append( "snapshots: [enabled => " ).append( snapshots.isEnabled() );
187 sb.append( ", update => " ).append( snapshots.getUpdatePolicy() ).append( "]\n" );
188 }
189
190 if ( releases != null )
191 {
192 sb.append( " releases: [enabled => " ).append( releases.isEnabled() );
193 sb.append( ", update => " ).append( releases.getUpdatePolicy() ).append( "]\n" );
194 }
195
196 return sb.toString();
197 }
198
199 public Artifact find( Artifact artifact )
200 {
201 File artifactFile = new File( getBasedir(), pathOf( artifact ) );
202
203 // We need to set the file here or the resolver will fail with an NPE, not fully equipped to deal
204 // with multiple local repository implementations yet.
205 artifact.setFile( artifactFile );
206
207 if ( artifactFile.exists() )
208 {
209 artifact.setResolved( true );
210 }
211
212 return artifact;
213 }
214
215 public List<String> findVersions( Artifact artifact )
216 {
217 return Collections.emptyList();
218 }
219
220 public boolean isProjectAware()
221 {
222 return false;
223 }
224
225 public Authentication getAuthentication()
226 {
227 return authentication;
228 }
229
230 public void setAuthentication( Authentication authentication )
231 {
232 this.authentication = authentication;
233 }
234
235 public Proxy getProxy()
236 {
237 return proxy;
238 }
239
240 public void setProxy( Proxy proxy )
241 {
242 this.proxy = proxy;
243 }
244
245 public boolean isUniqueVersion()
246 {
247 return true;
248 }
249
250 public List<ArtifactRepository> getMirroredRepositories()
251 {
252 return mirroredRepositories;
253 }
254
255 public void setMirroredRepositories( List<ArtifactRepository> mirroredRepositories )
256 {
257 if ( mirroredRepositories != null )
258 {
259 this.mirroredRepositories = mirroredRepositories;
260 }
261 else
262 {
263 this.mirroredRepositories = Collections.emptyList();
264 }
265 }
266
267 }