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     public String pathOf(Artifact artifact) {
117         return layout.pathOf(artifact);
118     }
119 
120     public String pathOfRemoteRepositoryMetadata(ArtifactMetadata artifactMetadata) {
121         return layout.pathOfRemoteRepositoryMetadata(artifactMetadata);
122     }
123 
124     public String pathOfLocalRepositoryMetadata(ArtifactMetadata metadata, ArtifactRepository repository) {
125         return layout.pathOfLocalRepositoryMetadata(metadata, repository);
126     }
127 
128     public void setLayout(ArtifactRepositoryLayout layout) {
129         this.layout = layout;
130     }
131 
132     public ArtifactRepositoryLayout getLayout() {
133         return layout;
134     }
135 
136     public void setSnapshotUpdatePolicy(ArtifactRepositoryPolicy snapshots) {
137         this.snapshots = snapshots;
138     }
139 
140     public ArtifactRepositoryPolicy getSnapshots() {
141         return snapshots;
142     }
143 
144     public void setReleaseUpdatePolicy(ArtifactRepositoryPolicy releases) {
145         this.releases = releases;
146     }
147 
148     public ArtifactRepositoryPolicy getReleases() {
149         return releases;
150     }
151 
152     public String getKey() {
153         return getId();
154     }
155 
156     public boolean isBlacklisted() {
157         return blacklisted;
158     }
159 
160     public void setBlacklisted(boolean blacklisted) {
161         this.blacklisted = blacklisted;
162     }
163 
164     public String toString() {
165         StringBuilder sb = new StringBuilder(256);
166 
167         sb.append("       id: ").append(getId()).append('\n');
168         sb.append("      url: ").append(getUrl()).append('\n');
169         sb.append("   layout: ").append(layout != null ? layout : "none").append('\n');
170 
171         if (snapshots != null) {
172             sb.append("snapshots: [enabled => ").append(snapshots.isEnabled());
173             sb.append(", update => ").append(snapshots.getUpdatePolicy()).append("]\n");
174         }
175 
176         if (releases != null) {
177             sb.append(" releases: [enabled => ").append(releases.isEnabled());
178             sb.append(", update => ").append(releases.getUpdatePolicy()).append("]\n");
179         }
180 
181         return sb.toString();
182     }
183 
184     public Artifact find(Artifact artifact) {
185         File artifactFile = new File(getBasedir(), pathOf(artifact));
186 
187         // We need to set the file here or the resolver will fail with an NPE, not fully equipped to deal
188         // with multiple local repository implementations yet.
189         artifact.setFile(artifactFile);
190 
191         if (artifactFile.exists()) {
192             artifact.setResolved(true);
193         }
194 
195         return artifact;
196     }
197 
198     public List<String> findVersions(Artifact artifact) {
199         return Collections.emptyList();
200     }
201 
202     public boolean isProjectAware() {
203         return false;
204     }
205 
206     public Authentication getAuthentication() {
207         return authentication;
208     }
209 
210     public void setAuthentication(Authentication authentication) {
211         this.authentication = authentication;
212     }
213 
214     public Proxy getProxy() {
215         return proxy;
216     }
217 
218     public void setProxy(Proxy proxy) {
219         this.proxy = proxy;
220     }
221 
222     public boolean isUniqueVersion() {
223         return true;
224     }
225 
226     public List<ArtifactRepository> getMirroredRepositories() {
227         return mirroredRepositories;
228     }
229 
230     public void setMirroredRepositories(List<ArtifactRepository> mirroredRepositories) {
231         if (mirroredRepositories != null) {
232             this.mirroredRepositories = Collections.unmodifiableList(mirroredRepositories);
233         } else {
234             this.mirroredRepositories = Collections.emptyList();
235         }
236     }
237 
238     public boolean isBlocked() {
239         return blocked;
240     }
241 
242     public void setBlocked(boolean blocked) {
243         this.blocked = blocked;
244     }
245 }