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 public class ArtifactDescriptorUtils {
33
34 public static Artifact toPomArtifact(Artifact artifact) {
35 Artifact pomArtifact = artifact;
36
37 if (!pomArtifact.getClassifier().isEmpty() || !"pom".equals(pomArtifact.getExtension())) {
38 pomArtifact =
39 new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion());
40 }
41
42 return pomArtifact;
43 }
44
45
46
47
48
49
50
51
52 public static Artifact toPomArtifactUnconditionally(Artifact artifact) {
53 return new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion());
54 }
55
56 public static RemoteRepository toRemoteRepository(Repository repository) {
57 RemoteRepository.Builder builder =
58 new RemoteRepository.Builder(repository.getId(), repository.getLayout(), repository.getUrl());
59 builder.setSnapshotPolicy(toRepositoryPolicy(repository.getSnapshots()));
60 builder.setReleasePolicy(toRepositoryPolicy(repository.getReleases()));
61 return builder.build();
62 }
63
64 public static RepositoryPolicy toRepositoryPolicy(org.apache.maven.model.RepositoryPolicy policy) {
65 boolean enabled = true;
66 String checksums = toRepositoryChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_WARN);
67 String updates = RepositoryPolicy.UPDATE_POLICY_DAILY;
68
69 if (policy != null) {
70 enabled = policy.isEnabled();
71 if (policy.getUpdatePolicy() != null) {
72 updates = policy.getUpdatePolicy();
73 }
74 if (policy.getChecksumPolicy() != null) {
75 checksums = policy.getChecksumPolicy();
76 }
77 }
78
79 return new RepositoryPolicy(enabled, updates, checksums);
80 }
81
82 public static String toRepositoryChecksumPolicy(final String artifactRepositoryPolicy) {
83 switch (artifactRepositoryPolicy) {
84 case RepositoryPolicy.CHECKSUM_POLICY_FAIL:
85 return RepositoryPolicy.CHECKSUM_POLICY_FAIL;
86 case RepositoryPolicy.CHECKSUM_POLICY_IGNORE:
87 return RepositoryPolicy.CHECKSUM_POLICY_IGNORE;
88 case RepositoryPolicy.CHECKSUM_POLICY_WARN:
89 return RepositoryPolicy.CHECKSUM_POLICY_WARN;
90 default:
91 throw new IllegalArgumentException("unknown repository checksum policy: " + artifactRepositoryPolicy);
92 }
93 }
94 }