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