1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.plugin.descriptor;
20
21 import java.io.Reader;
22 import java.net.URI;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.LinkedHashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Optional;
29
30 import org.apache.maven.plugin.descriptor.MojoDescriptor;
31 import org.apache.maven.plugin.descriptor.Parameter;
32 import org.apache.maven.plugin.descriptor.PluginDescriptor;
33 import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
34 import org.apache.maven.plugin.plugin.report.PluginReport;
35 import org.apache.maven.rtinfo.RuntimeInformation;
36 import org.apache.maven.tools.plugin.EnhancedParameterWrapper;
37 import org.apache.maven.tools.plugin.ExtendedPluginDescriptor;
38 import org.apache.maven.tools.plugin.generator.PluginDescriptorFilesGenerator;
39 import org.codehaus.plexus.configuration.PlexusConfiguration;
40 import org.codehaus.plexus.configuration.PlexusConfigurationException;
41
42
43
44
45
46
47
48 public class EnhancedPluginDescriptorBuilder extends PluginDescriptorBuilder {
49 private final boolean requireAddingMissingParameterSinceField;
50 private PlexusConfiguration configuration;
51
52 public EnhancedPluginDescriptorBuilder(RuntimeInformation rtInfo) {
53 this(rtInfo.isMavenVersion("[,3.3.9]"));
54 }
55
56 EnhancedPluginDescriptorBuilder(boolean requireAddingMissingParameterSinceField) {
57 this.requireAddingMissingParameterSinceField = requireAddingMissingParameterSinceField;
58 }
59
60
61
62
63 @Override
64 public PlexusConfiguration buildConfiguration(Reader reader) throws PlexusConfigurationException {
65 configuration = super.buildConfiguration(reader);
66 return configuration;
67 }
68
69 @Override
70 public PluginDescriptor build(Reader reader, String source) throws PlexusConfigurationException {
71 PluginDescriptor pluginDescriptor = super.build(reader, source);
72
73 ExtendedPluginDescriptor extendedPluginDescriptor = new ExtendedPluginDescriptor(pluginDescriptor);
74 extendedPluginDescriptor.setRequiredJavaVersion(
75 configuration.getChild("requiredJavaVersion").getValue());
76 extendedPluginDescriptor.setRequiredMavenVersion(
77 configuration.getChild("requiredMavenVersion").getValue());
78 return extendedPluginDescriptor;
79 }
80
81 @Override
82 public MojoDescriptor buildComponentDescriptor(PlexusConfiguration c, PluginDescriptor pluginDescriptor)
83 throws PlexusConfigurationException {
84 MojoDescriptor mojoDescriptor = super.buildComponentDescriptor(c, pluginDescriptor);
85
86
87
88
89
90 PlexusConfiguration[] parameterConfigurations = c.getChild("parameters").getChildren("parameter");
91
92 List<Parameter> parameters = new ArrayList<>(
93 Optional.ofNullable(mojoDescriptor.getParameters()).orElseGet(Collections::emptyList));
94 Map<String, Parameter> parameterMap = new LinkedHashMap<>(mojoDescriptor.getParameterMap());
95
96 for (PlexusConfiguration d : parameterConfigurations) {
97 String parameterName = d.getChild("name").getValue();
98
99 Parameter pd = parameterMap.get(parameterName);
100 if (requireAddingMissingParameterSinceField) {
101 addMissingParameterSinceField(pd, d);
102 }
103 PlexusConfiguration configTypeJavadocUrl = d.getChild("typeJavadocUrl", false);
104 if (configTypeJavadocUrl != null) {
105 String parameterTypeJavadocUrl = configTypeJavadocUrl.getValue();
106 EnhancedParameterWrapper enhancedParameter = new EnhancedParameterWrapper(pd);
107 enhancedParameter.setTypeJavadocUrl(URI.create(parameterTypeJavadocUrl));
108 parameters.set(mojoDescriptor.getParameters().indexOf(pd), enhancedParameter);
109 parameterMap.put(parameterName, enhancedParameter);
110 }
111 }
112
113
114 if (mojoDescriptor.getParameters() != null) {
115 mojoDescriptor.getParameters().clear();
116 }
117
118 mojoDescriptor.setParameters(parameters);
119 mojoDescriptor.getParameterMap().putAll(parameterMap);
120
121 return mojoDescriptor;
122 }
123
124
125
126
127
128
129
130
131
132
133
134 void addMissingParameterSinceField(Parameter pd, PlexusConfiguration d) throws PlexusConfigurationException {
135 String parameterSince = d.getChild("since").getValue();
136 pd.setSince(parameterSince);
137 }
138 }