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