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.io.File;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Date;
25 import java.util.LinkedHashSet;
26 import org.apache.maven.artifact.repository.metadata.Metadata;
27 import org.apache.maven.artifact.repository.metadata.Versioning;
28 import org.eclipse.aether.artifact.Artifact;
29 import org.eclipse.aether.artifact.ArtifactProperties;
30
31
32
33
34 final class VersionsMetadata extends MavenMetadata {
35
36 private final Artifact artifact;
37
38 VersionsMetadata(Artifact artifact, Date timestamp) {
39 super(createRepositoryMetadata(artifact), null, timestamp);
40 this.artifact = artifact;
41 }
42
43 VersionsMetadata(Artifact artifact, File file, Date timestamp) {
44 super(createRepositoryMetadata(artifact), file, timestamp);
45 this.artifact = artifact;
46 }
47
48 private static Metadata createRepositoryMetadata(Artifact artifact) {
49 Metadata metadata = new Metadata();
50 metadata.setGroupId(artifact.getGroupId());
51 metadata.setArtifactId(artifact.getArtifactId());
52
53 Versioning versioning = new Versioning();
54 versioning.addVersion(artifact.getBaseVersion());
55 if (!artifact.isSnapshot()) {
56 versioning.setRelease(artifact.getBaseVersion());
57 }
58 if ("maven-plugin".equals(artifact.getProperty(ArtifactProperties.TYPE, ""))) {
59 versioning.setLatest(artifact.getBaseVersion());
60 }
61
62 metadata.setVersioning(versioning);
63
64 return metadata;
65 }
66
67 @Override
68 protected void merge(Metadata recessive) {
69 Versioning versioning = metadata.getVersioning();
70 versioning.setLastUpdatedTimestamp(timestamp);
71
72 if (recessive.getVersioning() != null) {
73 if (versioning.getLatest() == null) {
74 versioning.setLatest(recessive.getVersioning().getLatest());
75 }
76 if (versioning.getRelease() == null) {
77 versioning.setRelease(recessive.getVersioning().getRelease());
78 }
79
80 Collection<String> versions =
81 new LinkedHashSet<>(recessive.getVersioning().getVersions());
82 versions.addAll(versioning.getVersions());
83 versioning.setVersions(new ArrayList<>(versions));
84 }
85 }
86
87 public Object getKey() {
88 return getGroupId() + ':' + getArtifactId();
89 }
90
91 public static Object getKey(Artifact artifact) {
92 return artifact.getGroupId() + ':' + artifact.getArtifactId();
93 }
94
95 public MavenMetadata setFile(File file) {
96 return new VersionsMetadata(artifact, file, timestamp);
97 }
98
99 public String getGroupId() {
100 return artifact.getGroupId();
101 }
102
103 public String getArtifactId() {
104 return artifact.getArtifactId();
105 }
106
107 public String getVersion() {
108 return "";
109 }
110
111 public Nature getNature() {
112 return artifact.isSnapshot() ? Nature.RELEASE_OR_SNAPSHOT : Nature.RELEASE;
113 }
114 }