1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.internal;
20
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.Date;
24 import java.util.LinkedHashMap;
25 import java.util.Map;
26
27 import org.eclipse.aether.RepositorySystemSession;
28 import org.eclipse.aether.artifact.Artifact;
29 import org.eclipse.aether.impl.MetadataGenerator;
30 import org.eclipse.aether.installation.InstallRequest;
31 import org.eclipse.aether.metadata.Metadata;
32 import org.eclipse.aether.util.ConfigUtils;
33
34
35
36
37
38
39 class LocalSnapshotMetadataGenerator implements MetadataGenerator {
40
41 private Map<Object, LocalSnapshotMetadata> snapshots;
42
43 private final boolean legacyFormat;
44
45 private final Date timestamp;
46
47 LocalSnapshotMetadataGenerator(RepositorySystemSession session, InstallRequest request) {
48 legacyFormat = ConfigUtils.getBoolean(session.getConfigProperties(), false, "maven.metadata.legacy");
49
50 timestamp = (Date) ConfigUtils.getObject(session, new Date(), "maven.startTime");
51
52 snapshots = new LinkedHashMap<>();
53 }
54
55 @Override
56 public Collection<? extends Metadata> prepare(Collection<? extends Artifact> artifacts) {
57 for (Artifact artifact : artifacts) {
58 if (artifact.isSnapshot()) {
59 Object key = LocalSnapshotMetadata.getKey(artifact);
60 LocalSnapshotMetadata snapshotMetadata = snapshots.get(key);
61 if (snapshotMetadata == null) {
62 snapshotMetadata = new LocalSnapshotMetadata(artifact, legacyFormat, timestamp);
63 snapshots.put(key, snapshotMetadata);
64 }
65 snapshotMetadata.bind(artifact);
66 }
67 }
68
69 return Collections.emptyList();
70 }
71
72 @Override
73 public Artifact transformArtifact(Artifact artifact) {
74 return artifact;
75 }
76
77 @Override
78 public Collection<? extends Metadata> finish(Collection<? extends Artifact> artifacts) {
79 return snapshots.values();
80 }
81 }