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