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 java.util.Arrays;
22 import java.util.List;
23
24 import org.apache.maven.plugin.descriptor.Parameter;
25 import org.apache.maven.shared.utils.logging.MessageBuilder;
26 import org.apache.maven.shared.utils.logging.MessageUtils;
27 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
28 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
29 import org.codehaus.plexus.configuration.PlexusConfiguration;
30 import org.slf4j.Logger;
31
32
33
34
35
36
37 abstract class AbstractMavenPluginParametersValidator implements MavenPluginConfigurationValidator {
38
39
40
41
42
43 private static final List<String> IGNORED_PROPERTY_VALUES = Arrays.asList(
44 "basedir",
45 "executedProject",
46 "localRepository",
47 "mojo",
48 "mojoExecution",
49 "plugin",
50 "project",
51 "reactorProjects",
52 "session",
53 "settings");
54
55 private static final List<String> IGNORED_PROPERTY_PREFIX =
56 Arrays.asList("mojo.", "plugin.", "project.", "session.", "settings.");
57
58 protected abstract Logger getLogger();
59
60 protected static boolean isValueSet(PlexusConfiguration config, ExpressionEvaluator expressionEvaluator) {
61 if (config == null) {
62 return false;
63 }
64
65
66 if (config.getChildCount() > 0) {
67 return true;
68 }
69
70 String strValue = config.getValue();
71
72 if (strValue == null || strValue.isEmpty()) {
73 return false;
74 }
75
76 if (isIgnoredProperty(strValue)) {
77 return false;
78 }
79
80
81
82
83 try {
84 return expressionEvaluator.evaluate(strValue) != null;
85 } catch (ExpressionEvaluationException e) {
86
87
88 }
89
90
91 return false;
92 }
93
94 private static boolean isIgnoredProperty(String strValue) {
95 if (!strValue.startsWith("${")) {
96 return false;
97 }
98
99 String propertyName = strValue.replace("${", "").replace("}", "");
100
101 if (IGNORED_PROPERTY_VALUES.contains(propertyName)) {
102 return true;
103 }
104
105 return IGNORED_PROPERTY_PREFIX.stream().anyMatch(propertyName::startsWith);
106 }
107
108 protected abstract String getParameterLogReason(Parameter parameter);
109
110 protected void logParameter(Parameter parameter) {
111 MessageBuilder messageBuilder = MessageUtils.buffer()
112 .warning("Parameter '")
113 .warning(parameter.getName())
114 .warning('\'');
115
116 if (parameter.getExpression() != null) {
117 String userProperty = parameter.getExpression().replace("${", "'").replace('}', '\'');
118 messageBuilder.warning(" (user property ").warning(userProperty).warning(")");
119 }
120
121 messageBuilder.warning(" ").warning(getParameterLogReason(parameter));
122
123 getLogger().warn(messageBuilder.toString());
124 }
125 }