You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2007/03/28 05:53:55 UTC

svn commit: r523156 - in /maven/plugins/trunk/maven-enforcer-plugin/src: main/java/org/apache/maven/plugin/enforcer/ test/java/org/apache/maven/plugin/enforcer/

Author: brianf
Date: Tue Mar 27 20:53:54 2007
New Revision: 523156

URL: http://svn.apache.org/viewvc?view=rev&rev=523156
Log:
added license and failFast flag

Modified:
    maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/EnforceMojo.java
    maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/EnforcerTestUtils.java
    maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockEnforcerRule.java
    maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockPlexusContainer.java
    maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestAbstractVersionEnforcer.java
    maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestDefaultEnforcementRuleHelper.java
    maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestEnforceMojo.java
    maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestMavenVersion.java
    maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestRequireJavaVersion.java

Modified: maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/EnforceMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/EnforceMojo.java?view=diff&rev=523156&r1=523155&r2=523156
==============================================================================
--- maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/EnforceMojo.java (original)
+++ maven/plugins/trunk/maven-enforcer-plugin/src/main/java/org/apache/maven/plugin/enforcer/EnforceMojo.java Tue Mar 27 20:53:54 2007
@@ -19,6 +19,13 @@
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -62,44 +69,91 @@
     protected boolean skip = false;
 
     /**
+     * Fail on the first rule that doesn't pass
+     * 
+     * @parameter expression="${enforcer.failFast}" default-value="false"
+     */
+    protected boolean failFast = false;
+
+    /**
      * @parameter
      * @required
      */
     private EnforcerRule[] rules;
 
+    /**
+     * Entry point to the mojo
+     */
     public void execute()
         throws MojoExecutionException
     {
         Log log = this.getLog();
+
+        // the entire execution can be easily skipped
         if ( !skip )
         {
+            // list to store exceptions
+            ArrayList list = new ArrayList();
+
+            // make sure the rules exist
             if ( rules != null && rules.length > 0 )
             {
                 String currentRule = "Unknown";
 
+                // create my helper
                 EnforcerRuleHelper helper = new DefaultEnforcementRuleHelper( session, log );
-                try
+
+                // if we are only warning, then disable failFast
+                if ( !fail )
                 {
-                    for ( int i = 0; i < rules.length; i++ )
+                    failFast = false;
+                }
+
+                // go through each rule unless
+                for ( int i = 0; i < rules.length; i++ )
+                {
+
+                    // prevent against empty rules
+                    EnforcerRule rule = rules[i];
+                    if ( rule != null )
                     {
-                        EnforcerRule rule = rules[i];
-                        if ( rule != null )
+                        // store the current rule for loggin purposes
+                        currentRule = rule.getClass().getSimpleName();
+                        log.debug( "Executing rule: " + currentRule );
+                        try
                         {
-                            currentRule = rule.getClass().getSimpleName();
-                            log.debug( "Executing rule: " + currentRule );
+                            // execute the rule
                             rules[i].execute( helper );
                         }
+                        catch ( EnforcerRuleException e )
+                        {
+                            // i can throw an exception because failfast will be
+                            // false if fail is false.
+                            if ( failFast )
+                            {
+                                throw new MojoExecutionException( currentRule + " failed with message: "
+                                    + e.getMessage(), e );
+                            }
+                            else
+                            {
+                                list.add( "Rule "+i+": "+currentRule+" failed with message: " + e.getMessage());
+                            }
+                        }
                     }
                 }
-                catch ( EnforcerRuleException e )
+
+                // if we found anything
+                if ( !list.isEmpty() )
                 {
-                    if ( fail )
+                    Iterator iter = list.iterator();
+                    while ( iter.hasNext() )
                     {
-                        throw new MojoExecutionException( currentRule + " failed with message: " + e.getMessage(), e );
+                        String failure = (String) iter.next();
+                        log.warn( failure );
                     }
-                    else
+                    if ( fail )
                     {
-                        log.warn( e.getLocalizedMessage() );
+                        throw new MojoExecutionException( "Some rules have failed." );
                     }
                 }
             }
@@ -181,6 +235,22 @@
     public void setSkip( boolean theSkip )
     {
         this.skip = theSkip;
+    }
+
+    /**
+     * @return the failFast
+     */
+    public boolean isFailFast()
+    {
+        return this.failFast;
+    }
+
+    /**
+     * @param theFailFast the failFast to set
+     */
+    public void setFailFast( boolean theFailFast )
+    {
+        this.failFast = theFailFast;
     }
 
 }

Modified: maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/EnforcerTestUtils.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/EnforcerTestUtils.java?view=diff&rev=523156&r1=523155&r2=523156
==============================================================================
--- maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/EnforcerTestUtils.java (original)
+++ maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/EnforcerTestUtils.java Tue Mar 27 20:53:54 2007
@@ -1,5 +1,24 @@
 package org.apache.maven.plugin.enforcer;
 
+/*
+ * 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.
+ */
+
 import java.util.Date;
 
 import org.apache.maven.execution.MavenSession;

Modified: maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockEnforcerRule.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockEnforcerRule.java?view=diff&rev=523156&r1=523155&r2=523156
==============================================================================
--- maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockEnforcerRule.java (original)
+++ maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockEnforcerRule.java Tue Mar 27 20:53:54 2007
@@ -1,5 +1,24 @@
 package org.apache.maven.plugin.enforcer;
 
+/*
+ * 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.
+ */
+
 import org.apache.maven.shared.enforcer.rule.api.EnforcerRule;
 import org.apache.maven.shared.enforcer.rule.api.EnforcerRuleException;
 import org.apache.maven.shared.enforcer.rule.api.EnforcerRuleHelper;

Modified: maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockPlexusContainer.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockPlexusContainer.java?view=diff&rev=523156&r1=523155&r2=523156
==============================================================================
--- maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockPlexusContainer.java (original)
+++ maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/MockPlexusContainer.java Tue Mar 27 20:53:54 2007
@@ -1,5 +1,24 @@
 package org.apache.maven.plugin.enforcer;
 
+/*
+ * 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.
+ */
+
 import java.io.File;
 import java.io.Reader;
 import java.util.Date;

Modified: maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestAbstractVersionEnforcer.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestAbstractVersionEnforcer.java?view=diff&rev=523156&r1=523155&r2=523156
==============================================================================
--- maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestAbstractVersionEnforcer.java (original)
+++ maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestAbstractVersionEnforcer.java Tue Mar 27 20:53:54 2007
@@ -1,5 +1,24 @@
 package org.apache.maven.plugin.enforcer;
 
+/*
+ * 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.
+ */
+
 import junit.framework.TestCase;
 
 import org.apache.maven.artifact.versioning.ArtifactVersion;

Modified: maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestDefaultEnforcementRuleHelper.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestDefaultEnforcementRuleHelper.java?view=diff&rev=523156&r1=523155&r2=523156
==============================================================================
--- maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestDefaultEnforcementRuleHelper.java (original)
+++ maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestDefaultEnforcementRuleHelper.java Tue Mar 27 20:53:54 2007
@@ -1,5 +1,24 @@
 package org.apache.maven.plugin.enforcer;
 
+/*
+ * 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.
+ */
+
 import junit.framework.TestCase;
 
 import org.apache.maven.plugin.logging.Log;

Modified: maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestEnforceMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestEnforceMojo.java?view=diff&rev=523156&r1=523155&r2=523156
==============================================================================
--- maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestEnforceMojo.java (original)
+++ maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestEnforceMojo.java Tue Mar 27 20:53:54 2007
@@ -51,12 +51,14 @@
         
         EnforcerRule[] rules = new EnforcerRule[10];
         rules[0] = new MockEnforcerRule(true);
+        rules[1] = new MockEnforcerRule(true);
         mojo.setRules( rules );
         
         mojo.execute();
         
         try
         {
+            mojo.setFailFast( false );
             mojo.setFail( true );
             mojo.execute();
             fail("Expected a Mojo Execution Exception.");
@@ -66,9 +68,24 @@
             System.out.println("Caught Expected Exception:"+e.getLocalizedMessage());
         }
 
-        ((MockEnforcerRule) rules[0]).setFailRule(false);
+        try
+        {
+            mojo.setFailFast( true );
+            mojo.setFail( true );
+            mojo.execute();
+            fail("Expected a Mojo Execution Exception.");
+        }
+        catch ( MojoExecutionException e )
+        {
+            System.out.println("Caught Expected Exception:"+e.getLocalizedMessage());
+        }
         
+        ((MockEnforcerRule) rules[0]).setFailRule(false);
+        ((MockEnforcerRule) rules[1]).setFailRule(false);
         mojo.execute();
         
+
+
+    
     }
 }

Modified: maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestMavenVersion.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestMavenVersion.java?view=diff&rev=523156&r1=523155&r2=523156
==============================================================================
--- maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestMavenVersion.java (original)
+++ maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestMavenVersion.java Tue Mar 27 20:53:54 2007
@@ -1,5 +1,24 @@
 package org.apache.maven.plugin.enforcer;
 
+/*
+ * 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.
+ */
+
 import org.apache.commons.lang.SystemUtils;
 import org.apache.maven.plugin.logging.SystemStreamLog;
 import org.apache.maven.shared.enforcer.rule.api.EnforcerRuleException;

Modified: maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestRequireJavaVersion.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestRequireJavaVersion.java?view=diff&rev=523156&r1=523155&r2=523156
==============================================================================
--- maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestRequireJavaVersion.java (original)
+++ maven/plugins/trunk/maven-enforcer-plugin/src/test/java/org/apache/maven/plugin/enforcer/TestRequireJavaVersion.java Tue Mar 27 20:53:54 2007
@@ -1,5 +1,24 @@
 package org.apache.maven.plugin.enforcer;
 
+/*
+ * 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.
+ */
+
 import org.apache.commons.lang.SystemUtils;
 import org.apache.maven.plugin.logging.SystemStreamLog;
 import org.apache.maven.shared.enforcer.rule.api.EnforcerRuleException;