1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.internal;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import org.apache.maven.execution.MavenSession;
26 import org.apache.maven.plugin.PluginValidationManager;
27 import org.apache.maven.plugin.descriptor.MojoDescriptor;
28 import org.apache.maven.plugin.descriptor.Parameter;
29 import org.apache.maven.shared.utils.logging.MessageUtils;
30 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
31 import org.codehaus.plexus.configuration.PlexusConfiguration;
32
33
34
35
36
37
38 @Singleton
39 @Named
40 class DeprecatedPluginValidator extends AbstractMavenPluginDescriptorSourcedParametersValidator {
41
42 @Inject
43 DeprecatedPluginValidator(PluginValidationManager pluginValidationManager) {
44 super(pluginValidationManager);
45 }
46
47 @Override
48 protected String getParameterLogReason(Parameter parameter) {
49 return "is deprecated: " + parameter.getDeprecated();
50 }
51
52 @Override
53 protected void doValidate(
54 MavenSession mavenSession,
55 MojoDescriptor mojoDescriptor,
56 Class<?> mojoClass,
57 PlexusConfiguration pomConfiguration,
58 ExpressionEvaluator expressionEvaluator) {
59 if (mojoDescriptor.getDeprecated() != null) {
60 pluginValidationManager.reportPluginMojoValidationIssue(
61 PluginValidationManager.IssueLocality.INTERNAL,
62 mavenSession,
63 mojoDescriptor,
64 mojoClass,
65 logDeprecatedMojo(mojoDescriptor));
66 }
67
68 if (mojoDescriptor.getParameters() != null) {
69 mojoDescriptor.getParameters().stream()
70 .filter(parameter -> parameter.getDeprecated() != null)
71 .filter(Parameter::isEditable)
72 .forEach(parameter -> checkParameter(
73 mavenSession, mojoDescriptor, mojoClass, parameter, pomConfiguration, expressionEvaluator));
74 }
75 }
76
77 private void checkParameter(
78 MavenSession mavenSession,
79 MojoDescriptor mojoDescriptor,
80 Class<?> mojoClass,
81 Parameter parameter,
82 PlexusConfiguration pomConfiguration,
83 ExpressionEvaluator expressionEvaluator) {
84 PlexusConfiguration config = pomConfiguration.getChild(parameter.getName(), false);
85
86 if (isValueSet(config, expressionEvaluator)) {
87 pluginValidationManager.reportPluginMojoValidationIssue(
88 PluginValidationManager.IssueLocality.INTERNAL,
89 mavenSession,
90 mojoDescriptor,
91 mojoClass,
92 formatParameter(parameter));
93 }
94 }
95
96 private String logDeprecatedMojo(MojoDescriptor mojoDescriptor) {
97 return MessageUtils.buffer()
98 .warning("Goal '")
99 .warning(mojoDescriptor.getGoal())
100 .warning("' is deprecated: ")
101 .warning(mojoDescriptor.getDeprecated())
102 .toString();
103 }
104 }