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