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 org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  /**
28   * @author jdcasey
29   */
30  public class DefaultArtifactRepositoryFactory
31      implements ArtifactRepositoryFactory
32  {
33      // TODO: use settings?
34      private String globalUpdatePolicy;
35  
36      private String globalChecksumPolicy;
37  
38      private final Map artifactRepositories = new HashMap();
39  
40      public ArtifactRepository createDeploymentArtifactRepository( String id, String url,
41                                                                    ArtifactRepositoryLayout repositoryLayout,
42                                                                    boolean uniqueVersion )
43      {
44          return new DefaultArtifactRepository( id, url, repositoryLayout, uniqueVersion );
45      }
46  
47      public ArtifactRepository createArtifactRepository( String id, String url,
48                                                          ArtifactRepositoryLayout repositoryLayout,
49                                                          ArtifactRepositoryPolicy snapshots,
50                                                          ArtifactRepositoryPolicy releases )
51      {
52          boolean blacklisted = false;
53          if ( artifactRepositories.containsKey( id ) )
54          {
55              ArtifactRepository repository = (ArtifactRepository) artifactRepositories.get( id );
56              // TODO: this should be an if there are duplicates?
57              if ( repository.getUrl().equals( url ) )
58              {
59                  blacklisted = repository.isBlacklisted();
60              }
61          }
62  
63          if ( snapshots == null )
64          {
65              snapshots = new ArtifactRepositoryPolicy();
66          }
67  
68          if ( releases == null )
69          {
70              releases = new ArtifactRepositoryPolicy();
71          }
72  
73          if ( globalUpdatePolicy != null )
74          {
75              snapshots.setUpdatePolicy( globalUpdatePolicy );
76              releases.setUpdatePolicy( globalUpdatePolicy );
77          }
78  
79          if ( globalChecksumPolicy != null )
80          {
81              snapshots.setChecksumPolicy( globalChecksumPolicy );
82              releases.setChecksumPolicy( globalChecksumPolicy );
83          }
84  
85          DefaultArtifactRepository repository = new DefaultArtifactRepository( id, url, repositoryLayout, snapshots,
86                                                                                releases );
87          repository.setBlacklisted( blacklisted );
88  
89          artifactRepositories.put( id, repository );
90  
91          return repository;
92      }
93  
94      public void setGlobalUpdatePolicy( String updatePolicy )
95      {
96          this.globalUpdatePolicy = updatePolicy;
97      }
98  
99      public void setGlobalChecksumPolicy( String checksumPolicy )
100     {
101         this.globalChecksumPolicy = checksumPolicy;
102     }
103 }