Author: stephenc
Date: Wed Oct 21 06:38:13 2009
New Revision: 827900

URL: http://svn.apache.org/viewvc?rev=827900&view=rev
Log:
[MINVOKER-95] Restoring the behaviour that exceptions thrown in a post-build 
hook script result in a build failure

o In general if a hook script throws an exception, this indicates an error in 
the hook script and not actually a failure of the test, in fact the test status 
is indeterminate.  However, in the post-build hook scripts throwing an 
exception is a good way to provide a meaningful error message.
o Perhaps a better way to achieve the distinction between post-build hook 
script errors and post-build hook script identified build failures would be to 
have the hook script throw an AssertionError, or some other defined 
exception... however that would require reworking all the existing post-build 
hook scripts, hence this jump-around

Modified:
    
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
    
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptRunner.java

Modified: 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java?rev=827900&r1=827899&r2=827900&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
 Wed Oct 21 06:38:13 2009
@@ -1211,7 +1211,7 @@
             try
             {
                 scriptRunner.run( "selector script", basedir, selectorScript, 
context, logger,
-                                  BuildJob.Result.SKIPPED );
+                                  BuildJob.Result.SKIPPED, false );
             }
             catch ( BuildErrorException e ) 
             {
@@ -1223,7 +1223,7 @@
             }
  
             scriptRunner.run( "pre-build script", basedir, preBuildHookScript, 
context, logger,
-                              BuildJob.Result.FAILURE_PRE_HOOK );
+                              BuildJob.Result.FAILURE_PRE_HOOK, false );
 
             final InvocationRequest request = new DefaultInvocationRequest();
 
@@ -1312,7 +1312,7 @@
             }
 
             scriptRunner.run( "post-build script", basedir, 
postBuildHookScript, context, logger,
-                              BuildJob.Result.FAILURE_POST_HOOK );
+                              BuildJob.Result.FAILURE_POST_HOOK, true );
         }
         finally
         {

Modified: 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptRunner.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptRunner.java?rev=827900&r1=827899&r2=827900&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptRunner.java
 (original)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptRunner.java
 Wed Oct 21 06:38:13 2009
@@ -144,11 +144,13 @@
      * @param context The key-value storage used to share information between 
hook scripts, may be <code>null</code>.
      * @param logger The logger to redirect the script output to, may be 
<code>null</code> to use stdout/stderr.
      * @param stage The stage of the build job the script is invoked in, must 
not be <code>null</code>.
+     * @param failOnException If <code>true</code> and the script throws an 
exception, then a {...@link BuildFailureException}
+     *            will be thrown, otherwise a {...@link BuildErrorException} 
will be thrown on script exception.
      * @throws MojoExecutionException If an I/O error occurred while reading 
the script file.
      * @throws BuildFailureException If the script did not return 
<code>true</code> of threw an exception.
      */
     public void run( final String scriptDescription, final File basedir, final 
String relativeScriptPath,
-                     final Map context, final FileLogger logger, String stage )
+                     final Map context, final FileLogger logger, String stage, 
boolean failOnException )
         throws MojoExecutionException, BuildFailureException
     {
         if ( relativeScriptPath == null )
@@ -215,7 +217,14 @@
             {
                 t.printStackTrace( logger.getPrintStream() );
             }
-            throw new BuildErrorException( "The " + scriptDescription + " did 
not succeed. " + msg, stage, t );
+            if ( failOnException )
+            {
+                throw new BuildFailureException( "The " + scriptDescription + 
" did not succeed. " + msg, stage );
+            }
+            else
+            {
+                throw new BuildErrorException( "The " + scriptDescription + " 
did not succeed. " + msg, stage, t );
+            }
         }
 
         if ( !( result == null || Boolean.TRUE.equals( result ) || 
"true".equals( result ) ) )


Reply via email to