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