View Javadoc

1   package org.apache.maven.plugins.enforcer;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.List;
23  
24  import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
25  import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
26  import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
27  
28  /**
29   * This rule checks that certain properties are set.
30   * 
31   * @author Paul Gier
32   */
33  public class RequireProperty
34      extends AbstractPropertyEnforcerRule
35  {
36  
37      /** Specify the required property. 
38       * 
39       * @deprecated the visibility will be reduced to private with the next major version
40       * @see {@link #setProperty(String)}
41       * @see {@link #getPropertyName()}
42       */
43      public String property = null;
44      
45      
46      public final void setProperty( String property )
47      {
48          this.property = property;
49      }
50  
51      @Override
52      public Object resolveValue( EnforcerRuleHelper helper )
53          throws EnforcerRuleException
54      {
55          Object propValue = null;
56          try
57          {
58              propValue = helper.evaluate( "${" + property + "}" );
59          }
60          catch ( ExpressionEvaluationException eee )
61          {
62              throw new EnforcerRuleException( "Unable to evaluate property: " + property, eee );
63          }
64          return propValue;
65      }
66  
67      protected String resolveValue()
68      {
69          return null;
70      }
71  
72      @Override
73      public String getPropertyName()
74      {
75          return property;
76      }
77  
78      @Override
79      public String getName()
80      {
81          return "Property";
82      }
83  }