View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.repository.legacy.repository;
20  
21  import javax.inject.Inject;
22  import javax.inject.Named;
23  import javax.inject.Singleton;
24  
25  import java.util.Map;
26  
27  import org.apache.maven.artifact.UnknownRepositoryLayoutException;
28  import org.apache.maven.artifact.repository.ArtifactRepository;
29  import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
30  import org.apache.maven.artifact.repository.MavenArtifactRepository;
31  import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
32  import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout2;
33  
34  /**
35   */
36  @Named
37  @Singleton
38  @Deprecated
39  public class DefaultArtifactRepositoryFactory implements ArtifactRepositoryFactory {
40      // TODO use settings?
41      private String globalUpdatePolicy;
42  
43      private String globalChecksumPolicy;
44  
45      @Inject
46      private Map<String, ArtifactRepositoryLayout> repositoryLayouts;
47  
48      public ArtifactRepositoryLayout getLayout(String layoutId) throws UnknownRepositoryLayoutException {
49          return repositoryLayouts.get(layoutId);
50      }
51  
52      public ArtifactRepository createDeploymentArtifactRepository(
53              String id, String url, String layoutId, boolean uniqueVersion) throws UnknownRepositoryLayoutException {
54          ArtifactRepositoryLayout layout = repositoryLayouts.get(layoutId);
55  
56          checkLayout(id, layoutId, layout);
57  
58          return createDeploymentArtifactRepository(id, url, layout, uniqueVersion);
59      }
60  
61      private void checkLayout(String repositoryId, String layoutId, ArtifactRepositoryLayout layout)
62              throws UnknownRepositoryLayoutException {
63          if (layout == null) {
64              throw new UnknownRepositoryLayoutException(repositoryId, layoutId);
65          }
66      }
67  
68      public ArtifactRepository createDeploymentArtifactRepository(
69              String id, String url, ArtifactRepositoryLayout repositoryLayout, boolean uniqueVersion) {
70          return createArtifactRepository(id, url, repositoryLayout, null, null);
71      }
72  
73      public ArtifactRepository createArtifactRepository(
74              String id,
75              String url,
76              String layoutId,
77              ArtifactRepositoryPolicy snapshots,
78              ArtifactRepositoryPolicy releases)
79              throws UnknownRepositoryLayoutException {
80          ArtifactRepositoryLayout layout = repositoryLayouts.get(layoutId);
81  
82          checkLayout(id, layoutId, layout);
83  
84          return createArtifactRepository(id, url, layout, snapshots, releases);
85      }
86  
87      public ArtifactRepository createArtifactRepository(
88              String id,
89              String url,
90              ArtifactRepositoryLayout repositoryLayout,
91              ArtifactRepositoryPolicy snapshots,
92              ArtifactRepositoryPolicy releases) {
93          if (snapshots == null) {
94              snapshots = new ArtifactRepositoryPolicy();
95          }
96  
97          if (releases == null) {
98              releases = new ArtifactRepositoryPolicy();
99          }
100 
101         if (globalUpdatePolicy != null) {
102             snapshots.setUpdatePolicy(globalUpdatePolicy);
103             releases.setUpdatePolicy(globalUpdatePolicy);
104         }
105 
106         if (globalChecksumPolicy != null) {
107             snapshots.setChecksumPolicy(globalChecksumPolicy);
108             releases.setChecksumPolicy(globalChecksumPolicy);
109         }
110 
111         ArtifactRepository repository;
112         if (repositoryLayout instanceof ArtifactRepositoryLayout2) {
113             repository = ((ArtifactRepositoryLayout2) repositoryLayout)
114                     .newMavenArtifactRepository(id, url, snapshots, releases);
115         } else {
116             repository = new MavenArtifactRepository(id, url, repositoryLayout, snapshots, releases);
117         }
118 
119         return repository;
120     }
121 
122     public void setGlobalUpdatePolicy(String updatePolicy) {
123         globalUpdatePolicy = updatePolicy;
124     }
125 
126     public void setGlobalChecksumPolicy(String checksumPolicy) {
127         globalChecksumPolicy = checksumPolicy;
128     }
129 }