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