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.sonatype.aether.artifact.Artifact;
24 import org.sonatype.aether.repository.RemoteRepository;
25 import org.sonatype.aether.repository.RepositoryPolicy;
26 import org.sonatype.aether.util.artifact.DefaultArtifact;
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 result =
53 new RemoteRepository( repository.getId(), repository.getLayout(), repository.getUrl() );
54 result.setPolicy( true, toRepositoryPolicy( repository.getSnapshots() ) );
55 result.setPolicy( false, toRepositoryPolicy( repository.getReleases() ) );
56 return result;
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 }