package org.apache.maven.usability;

import org.apache.maven.plugin.MojoExecutionException;

public class MojoExecutionExceptionDiagnoser
    implements ErrorDiagnoser
{

    public boolean canDiagnose( Throwable error )
    {
        return DiagnosisUtils.containsInCausality( error, MojoExecutionException.class );
    }

    public String diagnose( Throwable error )
    {
        MojoExecutionException mee = (MojoExecutionException) DiagnosisUtils.getFromCausality( error, MojoExecutionException.class );
        
        StringBuffer message = new StringBuffer();
        
        message.append( "Error executing mojo: " ).append( mee.getSource() ).append( "\n\n" );
        message.append( mee.getLongMessage() ).append( "\n\n" );
        
        Throwable root = DiagnosisUtils.getRootCause( mee );
        
        if ( root != null && root != mee )
        {
            message.append( "Root Cause: " ).append( root.getMessage() ).append( "\n\n" );
        }
        
        return message.toString();
    }

}

@@ -621,122 +621,511 @@
 mojo
-: %22 ).append( mee.getSource() ).append( %22%5Cn%5Cn%22 );%0A        message.append( mee.getLongMessage() ).append( %22%5Cn%5Cn%22 );
+%22 );%0A        %0A        Object source = mee.getSource();%0A        if ( source != null )%0A        %7B%0A            message.append( %22: %22 ).append( mee.getSource() ).append( %22%5Cn%22 );%0A        %7D%0A        else%0A        %7B%0A            message.append( %22.%5Cn%22 );%0A        %7D%0A        %0A        message.append( %22%5CnMessage: %22 ).append( mee.getMessage() );%0A        %0A        String longMessage = mee.getLongMessage();%0A        if ( longMessage != null )%0A        %7B%0A            message.append( %22%5Cn%5Cn%22 ).append( longMessage );%0A        %7D
 %0A   
@@ -1282,16 +1282,20 @@
 ppend( %22
+%5Cn%5Cn
 Root Cau
@@ -1325,24 +1325,60 @@
 tMessage() )
+;%0A        %7D%0A        %0A        message
 .append( %22%5Cn
@@ -1380,34 +1380,24 @@
 ( %22%5Cn%5Cn%22 );%0A
-        %7D%0A
         %0A   

Cleaning up diagnosis output for MojoExecutionException's.