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