Author: brianf Date: Wed May 28 19:27:54 2008 New Revision: 661185 URL: http://svn.apache.org/viewvc?rev=661185&view=rev Log: MENFORCER-38 new rules from Ben Lidgey - Always Fail and Always Pass
Added: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysFail.java maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysPass.java maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysFail.java maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysPass.java Added: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysFail.java URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysFail.java?rev=661185&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysFail.java (added) +++ maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysFail.java Wed May 28 19:27:54 2008 @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.plugins.enforcer; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; + +/** + * Always fail. This rule is useful for testing the Enforcer configuration, or to always fail the build if a particular + * profile is enabled. + * @author Ben Lidgey + */ +public class AlwaysFail + extends AbstractNonCacheableEnforcerRule +{ + + /** + * [EMAIL PROTECTED] + */ + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + throw new EnforcerRuleException( "Always fails!" ); + } +} Added: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysPass.java URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysPass.java?rev=661185&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysPass.java (added) +++ maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AlwaysPass.java Wed May 28 19:27:54 2008 @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.plugins.enforcer; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.logging.Log; + +/** + * Always pass. This rule is useful for testing the Enforcer configuration. + * @author Ben Lidgey + */ +public class AlwaysPass + extends AbstractNonCacheableEnforcerRule +{ + + /** + * [EMAIL PROTECTED] + */ + public void execute( EnforcerRuleHelper helper ) + throws EnforcerRuleException + { + final Log log = helper.getLog(); + log.info( "Always pass!" ); + } + +} Added: maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysFail.java URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysFail.java?rev=661185&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysFail.java (added) +++ maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysFail.java Wed May 28 19:27:54 2008 @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.plugins.enforcer; + +import junit.framework.TestCase; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; + +/** + * Test AlwaysFail rule. + * @author Ben Lidgey + * @see AlwaysFail + */ +public class TestAlwaysFail extends TestCase +{ + + public void testExecute() + { + final AlwaysFail rule = new AlwaysFail(); + try + { + // execute rule -- should throw EnforcerRuleException + rule.execute( EnforcerTestUtils.getHelper() ); + fail( "Should throw EnforcerRuleException" ); + } + catch ( EnforcerRuleException e ) + { + assertTrue( true ); + } + } + +} Added: maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysPass.java URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysPass.java?rev=661185&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysPass.java (added) +++ maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestAlwaysPass.java Wed May 28 19:27:54 2008 @@ -0,0 +1,30 @@ +package org.apache.maven.plugins.enforcer; + +import junit.framework.TestCase; + +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; + +/** + * Test AlwaysPass rule. + * @author Ben Lidgey + * @see AlwaysPass + */ +public class TestAlwaysPass extends TestCase +{ + + public void testExecute() + { + final AlwaysPass rule = new AlwaysPass(); + try + { + // execute rule -- should NOT throw EnforcerRuleException + rule.execute( EnforcerTestUtils.getHelper() ); + assertTrue( true ); + } + catch ( EnforcerRuleException e ) + { + fail( "Should NOT throw EnforcerRuleException" ); + } + } + +}