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