From 6f9be24b14431b2406f7df6eeb00fa68e7d6ca05 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 4 Dec 2010 14:22:06 +0000 Subject: [PATCH] [MNG-4922] ExecutionEvent give on the exception encountered (when having mojoFailed) . Issue id: MNG-4922 git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1042189 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/execution/ExecutionListener.java | 7 ++++++ .../lifecycle/internal/MojoExecutor.java | 1 + .../apache/maven/plugin/MojoExecution.java | 24 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/maven-core/src/main/java/org/apache/maven/execution/ExecutionListener.java b/maven-core/src/main/java/org/apache/maven/execution/ExecutionListener.java index 91fa945938..becca712f4 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/ExecutionListener.java +++ b/maven-core/src/main/java/org/apache/maven/execution/ExecutionListener.java @@ -1,5 +1,8 @@ package org.apache.maven.execution; +import org.apache.maven.plugin.MojoExecution; + + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -49,6 +52,10 @@ public interface ExecutionListener void mojoSucceeded( ExecutionEvent event ); + /** + * since 3.0.2 {@link Exception} is in {@link MojoExecution#getException()} returned + * by {@link ExecutionEvent#getMojoExecution()} + */ void mojoFailed( ExecutionEvent event ); void forkStarted( ExecutionEvent event ); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java index 3f8985df8e..b8257e2674 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java @@ -215,6 +215,7 @@ public class MojoExecutor } catch ( LifecycleExecutionException e ) { + mojoExecution.setException( new Exception( e.getCause() ) ); eventCatapult.fire( ExecutionEvent.Type.MojoFailed, session, mojoExecution ); throw e; diff --git a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java index d16a8bd54f..420a214413 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/MojoExecution.java @@ -39,6 +39,11 @@ public class MojoExecution private MojoDescriptor mojoDescriptor; private Xpp3Dom configuration; + + /** + * @since 3.0.2 + */ + private Exception exception; /** * Describes the source of an execution. @@ -234,4 +239,23 @@ public class MojoExecution this.forkedExecutions.put( projectKey, forkedExecutions ); } + /** + * @since 3.0.2 + * @return {@link Exception} encountered during the execution + */ + public Exception getException() + { + return exception; + } + + /** + * @since 3.0.2 + * @param exception + */ + public MojoExecution setException( Exception exception ) + { + this.exception = exception; + return this; + } + }