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.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
30 import org.codehaus.plexus.configuration.PlexusConfiguration;
31
32
33
34
35
36
37 @Named
38 @Singleton
39 class ReadOnlyPluginParametersValidator extends AbstractMavenPluginDescriptorSourcedParametersValidator {
40
41 @Inject
42 ReadOnlyPluginParametersValidator(PluginValidationManager pluginValidationManager) {
43 super(pluginValidationManager);
44 }
45
46 @Override
47 protected String getParameterLogReason(Parameter parameter) {
48 return "is read-only, must not be used in configuration";
49 }
50
51 @Override
52 protected void doValidate(
53 MavenSession mavenSession,
54 MojoDescriptor mojoDescriptor,
55 Class<?> mojoClass,
56 PlexusConfiguration pomConfiguration,
57 ExpressionEvaluator expressionEvaluator) {
58 if (mojoDescriptor.getParameters() == null) {
59 return;
60 }
61
62 mojoDescriptor.getParameters().stream()
63 .filter(parameter -> !parameter.isEditable())
64 .forEach(parameter -> checkParameter(
65 mavenSession, mojoDescriptor, mojoClass, parameter, pomConfiguration, expressionEvaluator));
66 }
67
68 private void checkParameter(
69 MavenSession mavenSession,
70 MojoDescriptor mojoDescriptor,
71 Class<?> mojoClass,
72 Parameter parameter,
73 PlexusConfiguration pomConfiguration,
74 ExpressionEvaluator expressionEvaluator) {
75 PlexusConfiguration config = pomConfiguration.getChild(parameter.getName(), false);
76
77 if (isValueSet(config, expressionEvaluator)) {
78 pluginValidationManager.reportPluginMojoValidationIssue(
79 PluginValidationManager.IssueLocality.INTERNAL,
80 mavenSession,
81 mojoDescriptor,
82 mojoClass,
83 formatParameter(parameter));
84 }
85 }
86 }