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 /**
25 * Common implementations for plugin parameters configuration validation that relies on Mojo descriptor (leaves out
26 * core parameters by default).
27 *
28 * @author Slawomir Jaranowski
29 */
30 abstract class AbstractMavenPluginDescriptorSourcedParametersValidator extends AbstractMavenPluginParametersValidator {
31
32 // plugin author can provide @Parameter( property = "session" ) in this case property will always evaluate
33 // so, we need ignore those
34
35 // source org.apache.maven.plugin.PluginParameterExpressionEvaluator
36 private static final List<String> IGNORED_PROPERTY_VALUES = Arrays.asList(
37 "basedir",
38 "executedProject",
39 "localRepository",
40 "mojo",
41 "mojoExecution",
42 "plugin",
43 "project",
44 "reactorProjects",
45 "session",
46 "settings");
47
48 private static final List<String> IGNORED_PROPERTY_PREFIX =
49 Arrays.asList("mojo.", "pom.", "plugin.", "project.", "session.", "settings.");
50
51 @Override
52 protected boolean isIgnoredProperty(String strValue) {
53 if (!strValue.startsWith("${")) {
54 return false;
55 }
56
57 String propertyName = strValue.replace("${", "").replace("}", "");
58
59 if (IGNORED_PROPERTY_VALUES.contains(propertyName)) {
60 return true;
61 }
62
63 return IGNORED_PROPERTY_PREFIX.stream().anyMatch(propertyName::startsWith);
64 }
65 }