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