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