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