1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
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 }