You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2019/01/05 20:07:45 UTC
[maven] 01/01: [MNG-5693] Change logging of MojoExceptions to
console
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch MNG-5693
in repository https://gitbox.apache.org/repos/asf/maven.git
commit 2d88cbc8fac79f398879c384f68ef6988ba0f380
Author: Sylwester Lachiewicz <sl...@gmail.com>
AuthorDate: Wed Oct 10 11:48:10 2018 +0200
[MNG-5693] Change logging of MojoExceptions to console
MojoExecutionException and MojoFailureException should never refer to a wikipage anymore.
---
.../maven/exception/DefaultExceptionHandler.java | 103 +--------------------
.../exception/DefaultExceptionHandlerTest.java | 16 ++--
.../main/java/org/apache/maven/cli/MavenCli.java | 12 ---
3 files changed, 9 insertions(+), 122 deletions(-)
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 2a86667..86f272e 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
@@ -19,20 +19,13 @@ package org.apache.maven.exception;
* under the License.
*/
-import java.io.IOException;
-import java.net.ConnectException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
-import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.ModelProblemUtils;
import org.apache.maven.plugin.AbstractMojoExecutionException;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugin.PluginContainerException;
-import org.apache.maven.plugin.PluginExecutionException;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.ProjectBuildingResult;
import org.codehaus.plexus.component.annotations.Component;
@@ -98,8 +91,6 @@ public class DefaultExceptionHandler
private ExceptionSummary handle( String message, Throwable exception )
{
- String reference = getReference( exception );
-
List<ExceptionSummary> children = null;
if ( exception instanceof ProjectBuildingException )
@@ -124,7 +115,7 @@ public class DefaultExceptionHandler
message = getMessage( message, exception );
}
- return new ExceptionSummary( exception, message, reference, children );
+ return new ExceptionSummary( exception, message, null, children );
}
private ExceptionSummary handle( ProjectBuildingResult result )
@@ -173,98 +164,6 @@ public class DefaultExceptionHandler
}
}
- private String getReference( Throwable exception )
- {
- String reference = "";
-
- if ( exception != null )
- {
- if ( exception instanceof MojoExecutionException )
- {
- reference = MojoExecutionException.class.getSimpleName();
-
- Throwable cause = exception.getCause();
- if ( cause instanceof IOException )
- {
- cause = cause.getCause();
- if ( cause instanceof ConnectException )
- {
- reference = ConnectException.class.getSimpleName();
- }
- }
- }
- else if ( exception instanceof MojoFailureException )
- {
- reference = MojoFailureException.class.getSimpleName();
- }
- else if ( exception instanceof LinkageError )
- {
- reference = LinkageError.class.getSimpleName();
- }
- else if ( exception instanceof PluginExecutionException )
- {
- Throwable cause = exception.getCause();
-
- if ( cause instanceof PluginContainerException )
- {
- Throwable cause2 = cause.getCause();
-
- if ( cause2 instanceof NoClassDefFoundError
- && cause2.getMessage().contains( "org/sonatype/aether/" ) )
- {
- reference = "AetherClassNotFound";
- }
- }
-
- if ( StringUtils.isEmpty( reference ) )
- {
- reference = getReference( cause );
- }
-
- if ( StringUtils.isEmpty( reference ) )
- {
- reference = exception.getClass().getSimpleName();
- }
- }
- else if ( exception instanceof LifecycleExecutionException )
- {
- reference = getReference( exception.getCause() );
- }
- else if ( isNoteworthyException( exception ) )
- {
- reference = exception.getClass().getSimpleName();
- }
- }
-
- if ( StringUtils.isNotEmpty( reference ) && !reference.startsWith( "http:" ) )
- {
- reference = "http://cwiki.apache.org/confluence/display/MAVEN/" + reference;
- }
-
- return reference;
- }
-
- private boolean isNoteworthyException( Throwable exception )
- {
- if ( exception == null )
- {
- return false;
- }
- else if ( exception instanceof Error )
- {
- return true;
- }
- else if ( exception instanceof RuntimeException )
- {
- return false;
- }
- else if ( exception.getClass().getName().startsWith( "java" ) )
- {
- return false;
- }
- return true;
- }
-
private String getMessage( String message, Throwable exception )
{
String fullMessage = ( message != null ) ? message : "";
diff --git a/maven-core/src/test/java/org/apache/maven/exception/DefaultExceptionHandlerTest.java b/maven-core/src/test/java/org/apache/maven/exception/DefaultExceptionHandlerTest.java
index 9727bdf..82a0c79 100644
--- a/maven-core/src/test/java/org/apache/maven/exception/DefaultExceptionHandlerTest.java
+++ b/maven-core/src/test/java/org/apache/maven/exception/DefaultExceptionHandlerTest.java
@@ -24,14 +24,14 @@ import java.net.ConnectException;
import org.apache.maven.plugin.MojoExecutionException;
-import junit.framework.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
/**
* @author <a href="mailto:baerrach@apache.org">Barrie Treloar</a>
*/
-public class DefaultExceptionHandlerTest
- extends TestCase
-{
+public class DefaultExceptionHandlerTest {
/**
* Running Maven under JDK7 may cause connection issues because IPv6 is used by default.
* <p>
@@ -42,19 +42,19 @@ public class DefaultExceptionHandlerTest
* http://cwiki.apache.org/confluence/display/MAVEN/ConnectException
* </p>
*/
+ @Test
public void testJdk7ipv6()
{
ConnectException connEx = new ConnectException( "Connection refused: connect" );
- IOException ioEx = new IOException( "Unable to establish loopback connection" );
- ioEx.initCause( connEx );
+ IOException ioEx = new IOException( "Unable to establish loopback connection", connEx );
MojoExecutionException mojoEx =
new MojoExecutionException( "Error executing Jetty: Unable to establish loopback connection", ioEx );
ExceptionHandler exceptionHandler = new DefaultExceptionHandler();
ExceptionSummary exceptionSummary = exceptionHandler.handleException( mojoEx );
- String expectedReference = "http://cwiki.apache.org/confluence/display/MAVEN/ConnectException";
- assertEquals( expectedReference, exceptionSummary.getReference() );
+ assertEquals( "", exceptionSummary.getReference() );
+ assertEquals( mojoEx, exceptionSummary.getException() );
}
}
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index f7ceda2..638c310 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -992,18 +992,6 @@ public class MavenCli
+ " switch to enable full debug logging." );
}
- if ( !references.isEmpty() )
- {
- slf4jLogger.error( "" );
- slf4jLogger.error( "For more information about the errors and possible solutions"
- + ", please read the following articles:" );
-
- for ( Map.Entry<String, String> entry : references.entrySet() )
- {
- slf4jLogger.error( buffer().strong( entry.getValue() ) + " " + entry.getKey() );
- }
- }
-
if ( project != null && !project.equals( result.getTopologicallySortedProjects().get( 0 ) ) )
{
slf4jLogger.error( "" );