diff --git a/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java b/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java index 059e1c8e1746..90b9c93276eb 100644 --- a/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java +++ b/maven-core/src/main/java/org/apache/maven/exception/DefaultExceptionHandler.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Set; +import org.apache.maven.api.plugin.MojoException; import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.model.building.ModelProblem; import org.apache.maven.model.building.ModelProblemUtils; @@ -232,16 +233,20 @@ private String getMessage(String message, Throwable exception) { Set dejaVu = Collections.newSetFromMap(new IdentityHashMap<>()); for (Throwable t = exception; t != null && t != t.getCause(); t = t.getCause()) { String exceptionMessage = t.getMessage(); + String longMessage = null; if (t instanceof AbstractMojoExecutionException) { - String longMessage = ((AbstractMojoExecutionException) t).getLongMessage(); - if (longMessage != null && !longMessage.isEmpty()) { - if ((exceptionMessage == null || exceptionMessage.isEmpty()) - || longMessage.contains(exceptionMessage)) { - exceptionMessage = longMessage; - } else if (!exceptionMessage.contains(longMessage)) { - exceptionMessage = join(exceptionMessage, System.lineSeparator() + longMessage); - } + longMessage = ((AbstractMojoExecutionException) t).getLongMessage(); + } else if (t instanceof MojoException) { + longMessage = ((MojoException) t).getLongMessage(); + } + + if (longMessage != null && !longMessage.isEmpty()) { + if ((exceptionMessage == null || exceptionMessage.isEmpty()) + || longMessage.contains(exceptionMessage)) { + exceptionMessage = longMessage; + } else if (!exceptionMessage.contains(longMessage)) { + exceptionMessage = join(exceptionMessage, System.lineSeparator() + longMessage); } } 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 5f442555bc88..0c3779ae7a40 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 @@ -37,6 +37,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import org.apache.maven.api.SessionData; +import org.apache.maven.api.services.MavenException; import org.apache.maven.api.services.MessageBuilderFactory; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; @@ -324,7 +325,8 @@ private void doExecute2(MavenSession session, MojoExecution mojoExecution) throw } catch (MojoFailureException | PluginManagerException | PluginConfigurationException - | MojoExecutionException e) { + | MojoExecutionException + | MavenException e) { throw new LifecycleExecutionException( messageBuilderFactory, mojoExecution, session.getCurrentProject(), e); } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java index 84774deebc84..7d3e8c4a7ac2 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java @@ -27,7 +27,7 @@ import java.util.List; import org.apache.maven.api.Project; -import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.services.MavenException; import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MojoExecutionEvent; import org.apache.maven.execution.MojoExecutionListener; @@ -143,12 +143,14 @@ public void executeMojo(MavenSession session, MojoExecution mojoExecution) mojoExecutionListener.beforeMojoExecution(mojoExecutionEvent); mojo.execute(); mojoExecutionListener.afterMojoExecutionSuccess(mojoExecutionEvent); - } catch (ClassCastException e) { + } catch (ClassCastException | MavenException e) { // to be processed in the outer catch block throw e; } catch (RuntimeException e) { throw new PluginExecutionException(mojoExecution, project, e); } + } catch (MavenException e) { + throw e; } catch (PluginContainerException e) { mojoExecutionListener.afterExecutionFailure( new MojoExecutionEvent(session, project, mojoExecution, mojo, e)); @@ -226,12 +228,8 @@ private static class MojoWrapper implements Mojo { } @Override - public void execute() throws MojoExecutionException, MojoFailureException { - try { - mojoV4.execute(); - } catch (MojoException e) { - throw new MojoExecutionException(e.getMessage(), e); - } + public void execute() { + mojoV4.execute(); } @Override