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 java.util.Collection;
23 import java.util.Collections;
24 import java.util.LinkedHashMap;
25 import java.util.Map;
26
27 import org.sonatype.aether.ConfigurationProperties;
28 import org.sonatype.aether.RepositorySystemSession;
29 import org.sonatype.aether.artifact.Artifact;
30 import org.sonatype.aether.deployment.DeployRequest;
31 import org.sonatype.aether.impl.MetadataGenerator;
32 import org.sonatype.aether.metadata.Metadata;
33
34
35
36
37 class RemoteSnapshotMetadataGenerator
38 implements MetadataGenerator
39 {
40
41 private final Map<Object, RemoteSnapshotMetadata> snapshots;
42
43 private final boolean legacyFormat;
44
45 public RemoteSnapshotMetadataGenerator( RepositorySystemSession session, DeployRequest request )
46 {
47 legacyFormat = ConfigurationProperties.get( session.getConfigProperties(), "maven.metadata.legacy", false );
48
49 snapshots = new LinkedHashMap<Object, RemoteSnapshotMetadata>();
50
51
52
53
54
55
56
57 for ( Metadata metadata : request.getMetadata() )
58 {
59 if ( metadata instanceof RemoteSnapshotMetadata )
60 {
61 RemoteSnapshotMetadata snapshotMetadata = (RemoteSnapshotMetadata) metadata;
62 snapshots.put( snapshotMetadata.getKey(), snapshotMetadata );
63 }
64 }
65 }
66
67 public Collection<? extends Metadata> prepare( Collection<? extends Artifact> artifacts )
68 {
69 for ( Artifact artifact : artifacts )
70 {
71 if ( artifact.isSnapshot() )
72 {
73 Object key = RemoteSnapshotMetadata.getKey( artifact );
74 RemoteSnapshotMetadata snapshotMetadata = snapshots.get( key );
75 if ( snapshotMetadata == null )
76 {
77 snapshotMetadata = new RemoteSnapshotMetadata( artifact, legacyFormat );
78 snapshots.put( key, snapshotMetadata );
79 }
80 snapshotMetadata.bind( artifact );
81 }
82 }
83
84 return snapshots.values();
85 }
86
87 public Artifact transformArtifact( Artifact artifact )
88 {
89 if ( artifact.isSnapshot() && artifact.getVersion().equals( artifact.getBaseVersion() ) )
90 {
91 Object key = RemoteSnapshotMetadata.getKey( artifact );
92 RemoteSnapshotMetadata snapshotMetadata = snapshots.get( key );
93 if ( snapshotMetadata != null )
94 {
95 artifact = artifact.setVersion( snapshotMetadata.getExpandedVersion( artifact ) );
96 }
97 }
98
99 return artifact;
100 }
101
102 public Collection<? extends Metadata> finish( Collection<? extends Artifact> artifacts )
103 {
104 return Collections.emptyList();
105 }
106
107 }