1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.internal.impl.resolver;
20
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.Date;
24 import java.util.Iterator;
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.installation.InstallRequest;
33 import org.eclipse.aether.metadata.Metadata;
34 import org.eclipse.aether.util.ConfigUtils;
35
36
37
38
39
40
41 class VersionsMetadataGenerator implements MetadataGenerator {
42
43 private final Map<Object, VersionsMetadata> versions;
44
45 private final Map<Object, VersionsMetadata> processedVersions;
46
47 private final Date timestamp;
48
49 VersionsMetadataGenerator(RepositorySystemSession session, InstallRequest request) {
50 this(session, request.getMetadata());
51 }
52
53 VersionsMetadataGenerator(RepositorySystemSession session, DeployRequest request) {
54 this(session, request.getMetadata());
55 }
56
57 private VersionsMetadataGenerator(RepositorySystemSession session, Collection<? extends Metadata> metadatas) {
58 versions = new LinkedHashMap<>();
59 processedVersions = new LinkedHashMap<>();
60 timestamp = (Date) ConfigUtils.getObject(session, new Date(), "maven.startTime");
61
62
63
64
65
66
67
68 for (Iterator<? extends Metadata> it = metadatas.iterator(); it.hasNext(); ) {
69 Metadata metadata = it.next();
70 if (metadata instanceof VersionsMetadata) {
71 it.remove();
72 VersionsMetadata versionsMetadata = (VersionsMetadata) metadata;
73 processedVersions.put(versionsMetadata.getKey(), versionsMetadata);
74 }
75 }
76 }
77
78 @Override
79 public Collection<? extends Metadata> prepare(Collection<? extends Artifact> artifacts) {
80 return Collections.emptyList();
81 }
82
83 @Override
84 public Artifact transformArtifact(Artifact artifact) {
85 return artifact;
86 }
87
88 @Override
89 public Collection<? extends Metadata> finish(Collection<? extends Artifact> artifacts) {
90 for (Artifact artifact : artifacts) {
91 Object key = VersionsMetadata.getKey(artifact);
92 if (processedVersions.get(key) == null) {
93 VersionsMetadata versionsMetadata = versions.get(key);
94 if (versionsMetadata == null) {
95 versionsMetadata = new VersionsMetadata(artifact, timestamp);
96 versions.put(key, versionsMetadata);
97 }
98 }
99 }
100
101 return versions.values();
102 }
103 }