View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.artifact.repository;
20  
21  import java.io.File;
22  import java.util.Collections;
23  import java.util.List;
24  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.artifact.metadata.ArtifactMetadata;
27  import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
28  import org.apache.maven.repository.Proxy;
29  import org.apache.maven.wagon.repository.Repository;
30  
31  /**
32   * This class is an abstraction of the location from/to resources can be
33   * transferred.
34   *
35   */
36  @Deprecated
37  public class DefaultArtifactRepository extends Repository implements ArtifactRepository {
38      private ArtifactRepositoryLayout layout;
39  
40      private ArtifactRepositoryPolicy snapshots;
41  
42      private ArtifactRepositoryPolicy releases;
43  
44      private boolean blacklisted;
45  
46      private Authentication authentication;
47  
48      private Proxy proxy;
49  
50      private List<ArtifactRepository> mirroredRepositories = Collections.emptyList();
51  
52      private boolean blocked;
53  
54      /**
55       * Create a local repository or a test repository.
56       *
57       * @param id     the unique identifier of the repository
58       * @param url    the URL of the repository
59       * @param layout the layout of the repository
60       */
61      public DefaultArtifactRepository(String id, String url, ArtifactRepositoryLayout layout) {
62          this(id, url, layout, null, null);
63      }
64  
65      /**
66       * Create a remote deployment repository.
67       *
68       * @param id            the unique identifier of the repository
69       * @param url           the URL of the repository
70       * @param layout        the layout of the repository
71       * @param uniqueVersion whether to assign each snapshot a unique version
72       */
73      public DefaultArtifactRepository(String id, String url, ArtifactRepositoryLayout layout, boolean uniqueVersion) {
74          super(id, url);
75          this.layout = layout;
76      }
77  
78      /**
79       * Create a remote download repository.
80       *
81       * @param id        the unique identifier of the repository
82       * @param url       the URL of the repository
83       * @param layout    the layout of the repository
84       * @param snapshots the policies to use for snapshots
85       * @param releases  the policies to use for releases
86       */
87      public DefaultArtifactRepository(
88              String id,
89              String url,
90              ArtifactRepositoryLayout layout,
91              ArtifactRepositoryPolicy snapshots,
92              ArtifactRepositoryPolicy releases) {
93          super(id, url);
94  
95          this.layout = layout;
96  
97          if (snapshots == null) {
98              snapshots = new ArtifactRepositoryPolicy(
99                      true,
100                     ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
101                     ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE);
102         }
103 
104         this.snapshots = snapshots;
105 
106         if (releases == null) {
107             releases = new ArtifactRepositoryPolicy(
108                     true,
109                     ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
110                     ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE);
111         }
112 
113         this.releases = releases;
114     }
115 
116     @Override
117     public String pathOf(Artifact artifact) {
118         return layout.pathOf(artifact);
119     }
120 
121     @Override
122     public String pathOfRemoteRepositoryMetadata(ArtifactMetadata artifactMetadata) {
123         return layout.pathOfRemoteRepositoryMetadata(artifactMetadata);
124     }
125 
126     @Override
127     public String pathOfLocalRepositoryMetadata(ArtifactMetadata metadata, ArtifactRepository repository) {
128         return layout.pathOfLocalRepositoryMetadata(metadata, repository);
129     }
130 
131     @Override
132     public void setLayout(ArtifactRepositoryLayout layout) {
133         this.layout = layout;
134     }
135 
136     @Override
137     public ArtifactRepositoryLayout getLayout() {
138         return layout;
139     }
140 
141     @Override
142     public void setSnapshotUpdatePolicy(ArtifactRepositoryPolicy snapshots) {
143         this.snapshots = snapshots;
144     }
145 
146     @Override
147     public ArtifactRepositoryPolicy getSnapshots() {
148         return snapshots;
149     }
150 
151     @Override
152     public void setReleaseUpdatePolicy(ArtifactRepositoryPolicy releases) {
153         this.releases = releases;
154     }
155 
156     @Override
157     public ArtifactRepositoryPolicy getReleases() {
158         return releases;
159     }
160 
161     @Override
162     public String getKey() {
163         return getId();
164     }
165 
166     @Override
167     public boolean isBlacklisted() {
168         return blacklisted;
169     }
170 
171     @Override
172     public void setBlacklisted(boolean blacklisted) {
173         this.blacklisted = blacklisted;
174     }
175 
176     @Override
177     public String toString() {
178         StringBuilder sb = new StringBuilder(256);
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             sb.append("snapshots: [enabled => ").append(snapshots.isEnabled());
186             sb.append(", update => ").append(snapshots.getUpdatePolicy()).append("]\n");
187         }
188 
189         if (releases != null) {
190             sb.append(" releases: [enabled => ").append(releases.isEnabled());
191             sb.append(", update => ").append(releases.getUpdatePolicy()).append("]\n");
192         }
193 
194         return sb.toString();
195     }
196 
197     @Override
198     public Artifact find(Artifact artifact) {
199         File artifactFile = new File(getBasedir(), pathOf(artifact));
200 
201         // We need to set the file here or the resolver will fail with an NPE, not fully equipped to deal
202         // with multiple local repository implementations yet.
203         artifact.setFile(artifactFile);
204 
205         if (artifactFile.exists()) {
206             artifact.setResolved(true);
207         }
208 
209         return artifact;
210     }
211 
212     @Override
213     public List<String> findVersions(Artifact artifact) {
214         return Collections.emptyList();
215     }
216 
217     @Override
218     public boolean isProjectAware() {
219         return false;
220     }
221 
222     @Override
223     public Authentication getAuthentication() {
224         return authentication;
225     }
226 
227     @Override
228     public void setAuthentication(Authentication authentication) {
229         this.authentication = authentication;
230     }
231 
232     @Override
233     public Proxy getProxy() {
234         return proxy;
235     }
236 
237     @Override
238     public void setProxy(Proxy proxy) {
239         this.proxy = proxy;
240     }
241 
242     @Override
243     public boolean isUniqueVersion() {
244         return true;
245     }
246 
247     @Override
248     public List<ArtifactRepository> getMirroredRepositories() {
249         return mirroredRepositories;
250     }
251 
252     @Override
253     public void setMirroredRepositories(List<ArtifactRepository> mirroredRepositories) {
254         if (mirroredRepositories != null) {
255             this.mirroredRepositories = Collections.unmodifiableList(mirroredRepositories);
256         } else {
257             this.mirroredRepositories = Collections.emptyList();
258         }
259     }
260 
261     @Override
262     public boolean isBlocked() {
263         return blocked;
264     }
265 
266     @Override
267     public void setBlocked(boolean blocked) {
268         this.blocked = blocked;
269     }
270 }