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.Date;
25 import java.util.LinkedHashMap;
26 import java.util.List;
27
28 import org.apache.maven.api.annotations.Nonnull;
29 import org.apache.maven.api.annotations.Nullable;
30 import org.apache.maven.artifact.repository.metadata.Metadata;
31 import org.apache.maven.artifact.repository.metadata.Plugin;
32
33
34
35
36
37
38 @Deprecated(since = "4.0.0")
39 final class PluginsMetadata extends MavenMetadata {
40 static final class PluginInfo {
41 @Nonnull
42 final String groupId;
43
44 @Nonnull
45 private final String artifactId;
46
47 @Nullable
48 private final String goalPrefix;
49
50 @Nullable
51 private final String name;
52
53 PluginInfo(String groupId, String artifactId, String goalPrefix, String name) {
54 this.groupId = groupId;
55 this.artifactId = artifactId;
56 this.goalPrefix = goalPrefix;
57 this.name = name;
58 }
59 }
60
61 private final PluginInfo pluginInfo;
62
63 PluginsMetadata(PluginInfo pluginInfo, Date timestamp) {
64 super(createRepositoryMetadata(pluginInfo), (Path) null, timestamp);
65 this.pluginInfo = pluginInfo;
66 }
67
68 PluginsMetadata(PluginInfo pluginInfo, Path path, Date timestamp) {
69 super(createRepositoryMetadata(pluginInfo), path, timestamp);
70 this.pluginInfo = pluginInfo;
71 }
72
73 private static Metadata createRepositoryMetadata(PluginInfo pluginInfo) {
74 Metadata result = new Metadata();
75 Plugin plugin = new Plugin();
76 plugin.setPrefix(pluginInfo.goalPrefix);
77 plugin.setArtifactId(pluginInfo.artifactId);
78 plugin.setName(pluginInfo.name);
79 result.getPlugins().add(plugin);
80 return result;
81 }
82
83 @Override
84 protected void merge(Metadata recessive) {
85 List<Plugin> recessivePlugins = recessive.getPlugins();
86 List<Plugin> plugins = metadata.getPlugins();
87 if (!recessivePlugins.isEmpty() || !plugins.isEmpty()) {
88 LinkedHashMap<String, Plugin> mergedPlugins = new LinkedHashMap<>();
89 recessivePlugins.forEach(p -> mergedPlugins.put(p.getPrefix(), p));
90 plugins.forEach(p -> mergedPlugins.put(p.getPrefix(), p));
91 metadata.setPlugins(new ArrayList<>(mergedPlugins.values()));
92 }
93
94
95 if (recessive.getVersioning() != null) {
96 metadata.setVersioning(recessive.getVersioning());
97 }
98 }
99
100 @Deprecated
101 @Override
102 public MavenMetadata setFile(File file) {
103 return new PluginsMetadata(pluginInfo, file.toPath(), timestamp);
104 }
105
106 @Override
107 public MavenMetadata setPath(Path path) {
108 return new PluginsMetadata(pluginInfo, path, timestamp);
109 }
110
111 @Override
112 public String getGroupId() {
113 return pluginInfo.groupId;
114 }
115
116 @Override
117 public String getArtifactId() {
118 return "";
119 }
120
121 @Override
122 public String getVersion() {
123 return "";
124 }
125
126 @Override
127 public Nature getNature() {
128 return Nature.RELEASE_OR_SNAPSHOT;
129 }
130 }