Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-8196] Make exception messages match Maven 3 again #1628

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -232,16 +233,20 @@ private String getMessage(String message, Throwable exception) {
Set<Throwable> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down