From 03f249b9e47e06ce64780a5f4b134d4bbc360270 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Fri, 14 Oct 2005 01:26:23 +0000 Subject: [PATCH] remove "Error type" git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@320962 13f79535-47bb-0310-9956-ffa450edef68 --- .../usability/diagnostics/DiagnosisUtils.java | 78 +++++++++---------- .../diagnostics/ErrorDiagnostics.java | 6 +- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/maven-error-diagnostics/src/main/java/org/apache/maven/usability/diagnostics/DiagnosisUtils.java b/maven-error-diagnostics/src/main/java/org/apache/maven/usability/diagnostics/DiagnosisUtils.java index 636f0206d9..a93b1c142a 100644 --- a/maven-error-diagnostics/src/main/java/org/apache/maven/usability/diagnostics/DiagnosisUtils.java +++ b/maven-error-diagnostics/src/main/java/org/apache/maven/usability/diagnostics/DiagnosisUtils.java @@ -1,54 +1,53 @@ package org.apache.maven.usability.diagnostics; - /* - * Copyright 2001-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +* Copyright 2001-2005 The Apache Software Foundation. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ public final class DiagnosisUtils { private DiagnosisUtils() { } - + public static boolean containsInCausality( Throwable error, Class test ) { Throwable cause = error; - - while( cause != null ) + + while ( cause != null ) { - if( test.isInstance( cause ) ) + if ( test.isInstance( cause ) ) { return true; } - + cause = cause.getCause(); } - + return false; } public static Throwable getRootCause( Throwable error ) { Throwable cause = error; - - while( true ) + + while ( true ) { Throwable nextCause = cause.getCause(); - - if( nextCause == null ) + + if ( nextCause == null ) { break; } @@ -57,39 +56,40 @@ public final class DiagnosisUtils cause = nextCause; } } - + return cause; } public static Throwable getFromCausality( Throwable error, Class targetClass ) { Throwable cause = error; - - while( cause != null ) + + while ( cause != null ) { - if( targetClass.isInstance( cause ) ) + if ( targetClass.isInstance( cause ) ) { return cause; } - + cause = cause.getCause(); } - + return null; } - public static void appendRootCauseIfPresentAndUnique( Throwable error, StringBuffer message, boolean includeTypeInfo ) + public static void appendRootCauseIfPresentAndUnique( Throwable error, StringBuffer message, + boolean includeTypeInfo ) { - Throwable root = DiagnosisUtils.getRootCause( error ); - - if ( root != null && root != error ) + Throwable root = getRootCause( error ); + + if ( root != null && !root.equals( error ) ) { String rootMsg = root.getMessage(); - - if ( rootMsg != null && error.getMessage().indexOf(rootMsg) < 0 ) + + if ( rootMsg != null && error.getMessage().indexOf( rootMsg ) < 0 ) { - message.append( "\nRoot message: " ).append( rootMsg ); - + message.append( "\n" ).append( rootMsg ); + if ( includeTypeInfo ) { message.append( "\nRoot error type: " ).append( root.getClass().getName() ); diff --git a/maven-error-diagnostics/src/main/java/org/apache/maven/usability/diagnostics/ErrorDiagnostics.java b/maven-error-diagnostics/src/main/java/org/apache/maven/usability/diagnostics/ErrorDiagnostics.java index 21516c4b5a..6a068764c4 100644 --- a/maven-error-diagnostics/src/main/java/org/apache/maven/usability/diagnostics/ErrorDiagnostics.java +++ b/maven-error-diagnostics/src/main/java/org/apache/maven/usability/diagnostics/ErrorDiagnostics.java @@ -128,10 +128,8 @@ public class ErrorDiagnostics StringBuffer message = new StringBuffer(); message.append( error.getMessage() ); - - message.append( "\nError type: " ).append( error.getClass().getName() ); - - DiagnosisUtils.appendRootCauseIfPresentAndUnique( error, message, true ); + + DiagnosisUtils.appendRootCauseIfPresentAndUnique( error, message, false ); return message.toString(); }