1 package org.apache.maven.repository.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
37 public static Artifact toPomArtifact( Artifact artifact )
38 {
39 Artifact pomArtifact = artifact;
40
41 if ( pomArtifact.getClassifier().length() > 0 || !"pom".equals( pomArtifact.getExtension() ) )
42 {
43 pomArtifact =
44 new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion() );
45 }
46
47 return pomArtifact;
48 }
49
50 public static RemoteRepository toRemoteRepository( Repository repository )
51 {
52 RemoteRepository.Builder builder =
53 new RemoteRepository.Builder( repository.getId(), repository.getLayout(), repository.getUrl() );
54 builder.setSnapshotPolicy( toRepositoryPolicy( repository.getSnapshots() ) );
55 builder.setReleasePolicy( toRepositoryPolicy( repository.getReleases() ) );
56 return builder.build();
57 }
58
59 public static RepositoryPolicy toRepositoryPolicy( org.apache.maven.model.RepositoryPolicy policy )
60 {
61 boolean enabled = true;
62 String checksums = RepositoryPolicy.CHECKSUM_POLICY_WARN;
63 String updates = RepositoryPolicy.UPDATE_POLICY_DAILY;
64
65 if ( policy != null )
66 {
67 enabled = policy.isEnabled();
68 if ( policy.getUpdatePolicy() != null )
69 {
70 updates = policy.getUpdatePolicy();
71 }
72 if ( policy.getChecksumPolicy() != null )
73 {
74 checksums = policy.getChecksumPolicy();
75 }
76 }
77
78 return new RepositoryPolicy( enabled, updates, checksums );
79 }
80
81 }