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