KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > artifact > repository > DefaultArtifactRepositoryFactory


1 package org.apache.maven.artifact.repository;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * @author jdcasey
26  */

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