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 org.apache.maven.enforcer.rule.api.EnforcerRule;
23  import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
24  
25  /**
26   * This rule checks that certain environment variable is set.
27   *
28   * @author <a href='mailto:marvin[at]marvinformatics[dot]com'>Marvin Froeder</a>
29   */
30  public class RequireEnvironmentVariable
31      extends AbstractPropertyEnforcerRule
32  {
33  
34      /**
35       * Specify the required variable.
36       */
37      public String variableName = null;
38  
39      @Override
40      public String resolveValue( EnforcerRuleHelper helper )
41      {
42          String envValue = System.getenv( variableName );
43          return envValue;
44      }
45  
46      public boolean isCacheable()
47      {
48          // environment variables won't change while maven is on the run
49          return true;
50      }
51  
52      public boolean isResultValid( EnforcerRule cachedRule )
53      {
54          // this rule shall always have the same result, since environment
55          // variables are set before maven is launched
56          return true;
57      }
58  
59      public String getCacheId()
60      {
61          return variableName;
62      }
63  
64      @Override
65      public String getPropertyName()
66      {
67          return variableName;
68      }
69  
70      @Override
71      public String getName()
72      {
73          return "Environment variable";
74      }
75  }