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