1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
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.PluginValidationManager;
25
26 /**
27 * Common implementations for plugin parameters configuration validation that relies on Mojo descriptor (leaves out
28 * core parameters by default).
29 *
30 * @author Slawomir Jaranowski
31 */
32 abstract class AbstractMavenPluginDescriptorSourcedParametersValidator extends AbstractMavenPluginParametersValidator {
33
34 // plugin author can provide @Parameter( property = "session" ) in this case property will always evaluate
35 // so, we need ignore those
36
37 // source org.apache.maven.plugin.PluginParameterExpressionEvaluator
38 private static final List<String> IGNORED_PROPERTY_VALUES = Arrays.asList(
39 "basedir",
40 "executedProject",
41 "localRepository",
42 "mojo",
43 "mojoExecution",
44 "plugin",
45 "project",
46 "reactorProjects",
47 "session",
48 "settings");
49
50 private static final List<String> IGNORED_PROPERTY_PREFIX =
51 Arrays.asList("mojo.", "pom.", "plugin.", "project.", "session.", "settings.");
52
53 protected AbstractMavenPluginDescriptorSourcedParametersValidator(PluginValidationManager pluginValidationManager) {
54 super(pluginValidationManager);
55 }
56
57 @Override
58 protected boolean isIgnoredProperty(String strValue) {
59 if (!strValue.startsWith("${")) {
60 return false;
61 }
62
63 String propertyName = strValue.replace("${", "").replace("}", "");
64
65 if (IGNORED_PROPERTY_VALUES.contains(propertyName)) {
66 return true;
67 }
68
69 return IGNORED_PROPERTY_PREFIX.stream().anyMatch(propertyName::startsWith);
70 }
71 }