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.plugins.enforcer;
20  
21  import org.apache.maven.enforcer.rule.api.EnforcerRule;
22  import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
23  import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
24  
25  /**
26   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
27   */
28  public class MockEnforcerRule implements EnforcerRule {
29  
30      public boolean failRule = false;
31  
32      public String cacheId = "";
33  
34      public boolean isCacheable = false;
35  
36      public boolean isResultValid = false;
37  
38      public boolean executed = false;
39  
40      public MockEnforcerRule(boolean fail) {
41          this.failRule = fail;
42      }
43  
44      public MockEnforcerRule(boolean fail, String cacheId, boolean isCacheable, boolean isResultValid) {
45          this.failRule = fail;
46          this.isCacheable = isCacheable;
47          this.isResultValid = isResultValid;
48          this.cacheId = cacheId;
49      }
50  
51      public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
52          executed = true;
53          if (isFailRule()) {
54              throw new EnforcerRuleException(" this condition is not allowed.");
55          }
56      }
57  
58      /**
59       * @return the failRule
60       */
61      public boolean isFailRule() {
62          return this.failRule;
63      }
64  
65      /**
66       * @param theFailRule the failRule to set
67       */
68      public void setFailRule(boolean theFailRule) {
69          this.failRule = theFailRule;
70      }
71  
72      /**
73       * @return the isResultValid
74       */
75      public boolean isResultValid() {
76          return this.isResultValid;
77      }
78  
79      /**
80       * @param theIsResultValid the isResultValid to set
81       */
82      public void setResultValid(boolean theIsResultValid) {
83          this.isResultValid = theIsResultValid;
84      }
85  
86      /**
87       * @param theCacheId the cacheId to set
88       */
89      public void setCacheId(String theCacheId) {
90          this.cacheId = theCacheId;
91      }
92  
93      /**
94       * @param theIsCacheable the isCacheable to set
95       */
96      public void setCacheable(boolean theIsCacheable) {
97          this.isCacheable = theIsCacheable;
98      }
99  
100     /*
101      * (non-Javadoc)
102      * @see org.apache.maven.enforcer.rule.api.EnforcerRule#getCacheId()
103      */
104     public String getCacheId() {
105         return cacheId;
106     }
107 
108     /*
109      * (non-Javadoc)
110      * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isCacheable()
111      */
112     public boolean isCacheable() {
113         return isCacheable;
114     }
115 
116     /*
117      * (non-Javadoc)
118      * @see
119      * org.apache.maven.enforcer.rule.api.EnforcerRule#isResultValid(org.apache.maven.enforcer.rule.api.EnforcerRule)
120      */
121     public boolean isResultValid(EnforcerRule theCachedRule) {
122         return isResultValid;
123     }
124 }