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   * @author <a href="michal.maczka@dimatics.com">Michal Maczka </a>
36   */
37  @Deprecated
38  public class DefaultArtifactRepository extends Repository implements ArtifactRepository {
39      private ArtifactRepositoryLayout layout;
40  
41      private ArtifactRepositoryPolicy snapshots;
42  
43      private ArtifactRepositoryPolicy releases;
44  
45      private boolean blacklisted;
46  
47      private Authentication authentication;
48  
49      private Proxy proxy;
50  
51      private List<ArtifactRepository> mirroredRepositories = Collections.emptyList();
52  
53      private boolean blocked;
54  
55      /**
56       * Create a local repository or a test repository.
57       *
58       * @param id     the unique identifier of the repository
59       * @param url    the URL of the repository
60       * @param layout the layout of the repository
61       */
62      public DefaultArtifactRepository(String id, String url, ArtifactRepositoryLayout layout) {
63          this(id, url, layout, null, null);
64      }
65  
66      /**
67       * Create a remote deployment repository.
68       *
69       * @param id            the unique identifier of the repository
70       * @param url           the URL of the repository
71       * @param layout        the layout of the repository
72       * @param uniqueVersion whether to assign each snapshot a unique version
73       */
74      public DefaultArtifactRepository(String id, String url, ArtifactRepositoryLayout layout, boolean uniqueVersion) {
75          super(id, url);
76          this.layout = layout;
77      }
78  
79      /**
80       * Create a remote download repository.
81       *
82       * @param id        the unique identifier of the repository
83       * @param url       the URL of the repository
84       * @param layout    the layout of the repository
85       * @param snapshots the policies to use for snapshots
86       * @param releases  the policies to use for releases
87       */
88      public DefaultArtifactRepository(
89              String id,
90              String url,
91              ArtifactRepositoryLayout layout,
92              ArtifactRepositoryPolicy snapshots,
93              ArtifactRepositoryPolicy releases) {
94          super(id, url);
95  
96          this.layout = layout;
97  
98          if (snapshots == null) {
99              snapshots = new ArtifactRepositoryPolicy(
100                     true,
101                     ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
102                     ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE);
103         }
104 
105         this.snapshots = snapshots;
106 
107         if (releases == null) {
108             releases = new ArtifactRepositoryPolicy(
109                     true,
110                     ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
111                     ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE);
112         }
113 
114         this.releases = releases;
115     }
116 
117     public String pathOf(Artifact artifact) {
118         return layout.pathOf(artifact);
119     }
120 
121     public String pathOfRemoteRepositoryMetadata(ArtifactMetadata artifactMetadata) {
122         return layout.pathOfRemoteRepositoryMetadata(artifactMetadata);
123     }
124 
125     public String pathOfLocalRepositoryMetadata(ArtifactMetadata metadata, ArtifactRepository repository) {
126         return layout.pathOfLocalRepositoryMetadata(metadata, repository);
127     }
128 
129     public void setLayout(ArtifactRepositoryLayout layout) {
130         this.layout = layout;
131     }
132 
133     public ArtifactRepositoryLayout getLayout() {
134         return layout;
135     }
136 
137     public void setSnapshotUpdatePolicy(ArtifactRepositoryPolicy snapshots) {
138         this.snapshots = snapshots;
139     }
140 
141     public ArtifactRepositoryPolicy getSnapshots() {
142         return snapshots;
143     }
144 
145     public void setReleaseUpdatePolicy(ArtifactRepositoryPolicy releases) {
146         this.releases = releases;
147     }
148 
149     public ArtifactRepositoryPolicy getReleases() {
150         return releases;
151     }
152 
153     public String getKey() {
154         return getId();
155     }
156 
157     public boolean isBlacklisted() {
158         return blacklisted;
159     }
160 
161     public void setBlacklisted(boolean blacklisted) {
162         this.blacklisted = blacklisted;
163     }
164 
165     public String toString() {
166         StringBuilder sb = new StringBuilder(256);
167 
168         sb.append("       id: ").append(getId()).append('\n');
169         sb.append("      url: ").append(getUrl()).append('\n');
170         sb.append("   layout: ").append(layout != null ? layout : "none").append('\n');
171 
172         if (snapshots != null) {
173             sb.append("snapshots: [enabled => ").append(snapshots.isEnabled());
174             sb.append(", update => ").append(snapshots.getUpdatePolicy()).append("]\n");
175         }
176 
177         if (releases != null) {
178             sb.append(" releases: [enabled => ").append(releases.isEnabled());
179             sb.append(", update => ").append(releases.getUpdatePolicy()).append("]\n");
180         }
181 
182         return sb.toString();
183     }
184 
185     public Artifact find(Artifact artifact) {
186         File artifactFile = new File(getBasedir(), pathOf(artifact));
187 
188         // We need to set the file here or the resolver will fail with an NPE, not fully equipped to deal
189         // with multiple local repository implementations yet.
190         artifact.setFile(artifactFile);
191 
192         if (artifactFile.exists()) {
193             artifact.setResolved(true);
194         }
195 
196         return artifact;
197     }
198 
199     public List<String> findVersions(Artifact artifact) {
200         return Collections.emptyList();
201     }
202 
203     public boolean isProjectAware() {
204         return false;
205     }
206 
207     public Authentication getAuthentication() {
208         return authentication;
209     }
210 
211     public void setAuthentication(Authentication authentication) {
212         this.authentication = authentication;
213     }
214 
215     public Proxy getProxy() {
216         return proxy;
217     }
218 
219     public void setProxy(Proxy proxy) {
220         this.proxy = proxy;
221     }
222 
223     public boolean isUniqueVersion() {
224         return true;
225     }
226 
227     public List<ArtifactRepository> getMirroredRepositories() {
228         return mirroredRepositories;
229     }
230 
231     public void setMirroredRepositories(List<ArtifactRepository> mirroredRepositories) {
232         if (mirroredRepositories != null) {
233             this.mirroredRepositories = Collections.unmodifiableList(mirroredRepositories);
234         } else {
235             this.mirroredRepositories = Collections.emptyList();
236         }
237     }
238 
239     public boolean isBlocked() {
240         return blocked;
241     }
242 
243     public void setBlocked(boolean blocked) {
244         this.blocked = blocked;
245     }
246 }