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