View Javadoc
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   */
31  abstract class AbstractMavenPluginDescriptorSourcedParametersValidator extends AbstractMavenPluginParametersValidator {
32  
33      // plugin author can provide @Parameter( property = "session" ) in this case property will always evaluate
34      // so, we need ignore those
35  
36      // source org.apache.maven.plugin.PluginParameterExpressionEvaluator
37      private static final List<String> IGNORED_PROPERTY_VALUES = Arrays.asList(
38              "basedir",
39              "executedProject",
40              "localRepository",
41              "mojo",
42              "mojoExecution",
43              "plugin",
44              "project",
45              "reactorProjects",
46              "session",
47              "settings");
48  
49      private static final List<String> IGNORED_PROPERTY_PREFIX =
50              Arrays.asList("mojo.", "pom.", "plugin.", "project.", "session.", "settings.");
51  
52      protected AbstractMavenPluginDescriptorSourcedParametersValidator(PluginValidationManager pluginValidationManager) {
53          super(pluginValidationManager);
54      }
55  
56      @Override
57      protected boolean isIgnoredProperty(String strValue) {
58          if (!strValue.startsWith("${")) {
59              return false;
60          }
61  
62          String propertyName = strValue.replace("${", "").replace("}", "");
63  
64          if (IGNORED_PROPERTY_VALUES.contains(propertyName)) {
65              return true;
66          }
67  
68          return IGNORED_PROPERTY_PREFIX.stream().anyMatch(propertyName::startsWith);
69      }
70  }