1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.internal;
20
21 import org.apache.maven.model.Repository;
22 import org.eclipse.aether.artifact.Artifact;
23 import org.eclipse.aether.artifact.DefaultArtifact;
24 import org.eclipse.aether.repository.RemoteRepository;
25 import org.eclipse.aether.repository.RepositoryPolicy;
26
27
28
29
30
31
32
33 @Deprecated(since = "4.0.0")
34 public class ArtifactDescriptorUtils {
35
36 public static Artifact toPomArtifact(Artifact artifact) {
37 Artifact pomArtifact = artifact;
38
39 if (!pomArtifact.getClassifier().isEmpty() || !"pom".equals(pomArtifact.getExtension())) {
40 pomArtifact =
41 new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion());
42 }
43
44 return pomArtifact;
45 }
46
47
48
49
50
51
52
53
54 public static Artifact toPomArtifactUnconditionally(Artifact artifact) {
55 return new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion());
56 }
57
58 public static RemoteRepository toRemoteRepository(Repository repository) {
59 RemoteRepository.Builder builder =
60 new RemoteRepository.Builder(repository.getId(), repository.getLayout(), repository.getUrl());
61 builder.setSnapshotPolicy(toRepositoryPolicy(repository.getSnapshots()));
62 builder.setReleasePolicy(toRepositoryPolicy(repository.getReleases()));
63 return builder.build();
64 }
65
66 public static RepositoryPolicy toRepositoryPolicy(org.apache.maven.model.RepositoryPolicy policy) {
67 boolean enabled = true;
68 String checksums = toRepositoryChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_WARN);
69 String updates = RepositoryPolicy.UPDATE_POLICY_DAILY;
70
71 if (policy != null) {
72 enabled = policy.isEnabled();
73 if (policy.getUpdatePolicy() != null) {
74 updates = policy.getUpdatePolicy();
75 }
76 if (policy.getChecksumPolicy() != null) {
77 checksums = policy.getChecksumPolicy();
78 }
79 }
80
81 return new RepositoryPolicy(enabled, updates, checksums);
82 }
83
84 public static String toRepositoryChecksumPolicy(final String artifactRepositoryPolicy) {
85 switch (artifactRepositoryPolicy) {
86 case RepositoryPolicy.CHECKSUM_POLICY_FAIL:
87 return RepositoryPolicy.CHECKSUM_POLICY_FAIL;
88 case RepositoryPolicy.CHECKSUM_POLICY_IGNORE:
89 return RepositoryPolicy.CHECKSUM_POLICY_IGNORE;
90 case RepositoryPolicy.CHECKSUM_POLICY_WARN:
91 return RepositoryPolicy.CHECKSUM_POLICY_WARN;
92 default:
93 throw new IllegalArgumentException("unknown repository checksum policy: " + artifactRepositoryPolicy);
94 }
95 }
96 }