1 | |
package org.apache.maven.usability; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.plugin.MojoFailureException; |
23 | |
import org.apache.maven.usability.diagnostics.DiagnosisUtils; |
24 | |
import org.apache.maven.usability.diagnostics.ErrorDiagnoser; |
25 | |
|
26 | 1 | public class MojoFailureExceptionDiagnoser |
27 | |
implements ErrorDiagnoser |
28 | |
{ |
29 | |
|
30 | |
public boolean canDiagnose( Throwable error ) |
31 | |
{ |
32 | 2 | return DiagnosisUtils.containsInCausality( error, MojoFailureException.class ); |
33 | |
} |
34 | |
|
35 | |
public String diagnose( Throwable error ) |
36 | |
{ |
37 | 1 | MojoFailureException mfe = |
38 | |
(MojoFailureException) DiagnosisUtils.getFromCausality( error, MojoFailureException.class ); |
39 | |
|
40 | 1 | StringBuffer message = new StringBuffer(); |
41 | |
|
42 | 1 | Object source = mfe.getSource(); |
43 | 1 | if ( source != null ) |
44 | |
{ |
45 | 0 | message.append( ": " ).append( mfe.getSource() ).append( "\n" ); |
46 | |
} |
47 | |
|
48 | 1 | String shortMessage = mfe.getMessage(); |
49 | 1 | if ( shortMessage != null ) |
50 | |
{ |
51 | 0 | message.append( shortMessage ); |
52 | |
} |
53 | |
|
54 | 1 | String longMessage = mfe.getLongMessage(); |
55 | |
|
56 | |
|
57 | 1 | if ( longMessage != null && !longMessage.equals( shortMessage ) && shortMessage.indexOf( longMessage ) < 0 ) |
58 | |
{ |
59 | 0 | message.append( "\n\n" ).append( longMessage ); |
60 | |
} |
61 | |
|
62 | 1 | return message.toString(); |
63 | |
} |
64 | |
|
65 | |
} |