001package org.apache.maven.plugins.enforcer; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.maven.enforcer.rule.api.EnforcerRule; 023import org.apache.maven.enforcer.rule.api.EnforcerRuleException; 024import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; 025 026/** 027 * @author <a href="mailto:brianf@apache.org">Brian Fox</a> 028 */ 029public class MockEnforcerRule 030 implements EnforcerRule 031{ 032 033 public boolean failRule = false; 034 035 public String cacheId = ""; 036 037 public boolean isCacheable = false; 038 039 public boolean isResultValid = false; 040 041 public boolean executed = false; 042 043 public MockEnforcerRule( boolean fail ) 044 { 045 this.failRule = fail; 046 } 047 048 public MockEnforcerRule( boolean fail, String cacheId, boolean isCacheable, boolean isResultValid ) 049 { 050 this.failRule = fail; 051 this.isCacheable = isCacheable; 052 this.isResultValid = isResultValid; 053 this.cacheId = cacheId; 054 } 055 056 public void execute( EnforcerRuleHelper helper ) 057 throws EnforcerRuleException 058 { 059 executed = true; 060 if ( isFailRule() ) 061 { 062 throw new EnforcerRuleException( " this condition is not allowed." ); 063 } 064 } 065 066 /** 067 * @return the failRule 068 */ 069 public boolean isFailRule() 070 { 071 return this.failRule; 072 } 073 074 /** 075 * @param theFailRule the failRule to set 076 */ 077 public void setFailRule( boolean theFailRule ) 078 { 079 this.failRule = theFailRule; 080 } 081 082 /** 083 * @return the isResultValid 084 */ 085 public boolean isResultValid() 086 { 087 return this.isResultValid; 088 } 089 090 /** 091 * @param theIsResultValid the isResultValid to set 092 */ 093 public void setResultValid( boolean theIsResultValid ) 094 { 095 this.isResultValid = theIsResultValid; 096 } 097 098 /** 099 * @param theCacheId the cacheId to set 100 */ 101 public void setCacheId( String theCacheId ) 102 { 103 this.cacheId = theCacheId; 104 } 105 106 /** 107 * @param theIsCacheable the isCacheable to set 108 */ 109 public void setCacheable( boolean theIsCacheable ) 110 { 111 this.isCacheable = theIsCacheable; 112 } 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 /* 124 * (non-Javadoc) 125 * @see org.apache.maven.enforcer.rule.api.EnforcerRule#isCacheable() 126 */ 127 public boolean isCacheable() 128 { 129 return isCacheable; 130 } 131 132 /* 133 * (non-Javadoc) 134 * @see 135 * org.apache.maven.enforcer.rule.api.EnforcerRule#isResultValid(org.apache.maven.enforcer.rule.api.EnforcerRule) 136 */ 137 public boolean isResultValid( EnforcerRule theCachedRule ) 138 { 139 return isResultValid; 140 } 141 142}