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 org.apache.maven.plugin.descriptor.MojoDescriptor;
22 import org.apache.maven.plugin.descriptor.Parameter;
23 import org.apache.maven.shared.utils.logging.MessageBuilder;
24 import org.apache.maven.shared.utils.logging.MessageUtils;
25 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
26 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
27 import org.codehaus.plexus.configuration.PlexusConfiguration;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31
32
33
34
35
36 abstract class AbstractMavenPluginParametersValidator implements MavenPluginConfigurationValidator {
37
38 protected final Logger logger = LoggerFactory.getLogger(getClass());
39
40 protected boolean isValueSet(PlexusConfiguration config, ExpressionEvaluator expressionEvaluator) {
41 if (config == null) {
42 return false;
43 }
44
45
46 if (config.getChildCount() > 0) {
47 return true;
48 }
49
50 String strValue = config.getValue();
51
52 if (strValue == null || strValue.isEmpty()) {
53 return false;
54 }
55
56 if (isIgnoredProperty(strValue)) {
57 return false;
58 }
59
60
61
62
63 try {
64 return expressionEvaluator.evaluate(strValue) != null;
65 } catch (ExpressionEvaluationException e) {
66
67
68 }
69
70
71 return false;
72 }
73
74 @Override
75 public final void validate(
76 MojoDescriptor mojoDescriptor,
77 PlexusConfiguration pomConfiguration,
78 ExpressionEvaluator expressionEvaluator) {
79 if (!logger.isWarnEnabled()) {
80 return;
81 }
82
83 doValidate(mojoDescriptor, pomConfiguration, expressionEvaluator);
84 }
85
86 protected abstract void doValidate(
87 MojoDescriptor mojoDescriptor,
88 PlexusConfiguration pomConfiguration,
89 ExpressionEvaluator expressionEvaluator);
90
91 protected boolean isIgnoredProperty(String strValue) {
92 return false;
93 }
94
95 protected abstract String getParameterLogReason(Parameter parameter);
96
97 protected void logParameter(Parameter parameter) {
98 MessageBuilder messageBuilder = MessageUtils.buffer()
99 .warning("Parameter '")
100 .warning(parameter.getName())
101 .warning('\'');
102
103 if (parameter.getExpression() != null) {
104 String userProperty = parameter.getExpression().replace("${", "'").replace('}', '\'');
105 messageBuilder.warning(" (user property ").warning(userProperty).warning(")");
106 }
107
108 messageBuilder.warning(" ").warning(getParameterLogReason(parameter));
109
110 logger.warn(messageBuilder.toString());
111 }
112 }