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.impl.MetadataGenerator;
31 import org.eclipse.aether.installation.InstallRequest;
32 import org.eclipse.aether.metadata.Metadata;
33 import org.eclipse.aether.util.ConfigUtils;
34
35
36
37
38
39
40 class LocalSnapshotMetadataGenerator
41 implements MetadataGenerator
42 {
43
44 private Map<Object, LocalSnapshotMetadata> snapshots;
45
46 private final boolean legacyFormat;
47
48 private final Date timestamp;
49
50 LocalSnapshotMetadataGenerator( RepositorySystemSession session, InstallRequest request )
51 {
52 legacyFormat = ConfigUtils.getBoolean( session.getConfigProperties(), false, "maven.metadata.legacy" );
53
54 timestamp = (Date) ConfigUtils.getObject( session, new Date(), "maven.startTime" );
55
56 snapshots = new LinkedHashMap<>();
57 }
58
59 public Collection<? extends Metadata> prepare( Collection<? extends Artifact> artifacts )
60 {
61 for ( Artifact artifact : artifacts )
62 {
63 if ( artifact.isSnapshot() )
64 {
65 Object key = LocalSnapshotMetadata.getKey( artifact );
66 LocalSnapshotMetadata snapshotMetadata = snapshots.get( key );
67 if ( snapshotMetadata == null )
68 {
69 snapshotMetadata = new LocalSnapshotMetadata( artifact, legacyFormat, timestamp );
70 snapshots.put( key, snapshotMetadata );
71 }
72 snapshotMetadata.bind( artifact );
73 }
74 }
75
76 return Collections.emptyList();
77 }
78
79 public Artifact transformArtifact( Artifact artifact )
80 {
81 return artifact;
82 }
83
84 public Collection<? extends Metadata> finish( Collection<? extends Artifact> artifacts )
85 {
86 return snapshots.values();
87 }
88
89 }