// TestNGListener.java

package ed;

import java.util.*;

import org.testng.*;
import org.testng.reporters.*;

public class TestNGListener extends TestListenerAdapter {
    
    public void onTestFailure(ITestResult tr) {
        log("F");
    }
    
    public void onTestSkipped(ITestResult tr) {
        log("S");
    }
    
    public void onTestSuccess(ITestResult tr) {
        log(".");
    }

    private void log(String string) {
        System.out.print(string);
        if ( ++_count % 40 == 0) {
            System.out.println("");
        }
    }

    public void onFinish(ITestContext context){
        System.out.println();
        for ( ITestResult r : context.getFailedTests().getAllResults() ){
            System.out.println( r );
            if ( r.getThrowable() != null )
                _print( r.getThrowable() );
        }
    }
    
    private void _print( Throwable t ){
        for ( StackTraceElement e : t.getStackTrace() ){
            if ( e.getClassName().startsWith( "org.testng." ) ||
                 e.getClassName().startsWith( "sun.reflect." ) )
                continue;

            System.out.println( e );
        }
    }
    
    private int _count = 0;
} 

@@ -737,19 +737,17 @@
 println(
- r 
+r
 );%0A     
@@ -757,44 +757,44 @@
     
-if ( r.getThrowable() != null )%0A    
+System.out.println(%22Exception : %22);%0A
     
@@ -886,24 +886,133 @@
 owable t )%7B%0A
+%0A        int otcount = 0;%0A        int jlrcount = 0;%0A%0A        if (t == null) %7B%0A            return;%0A        %7D%0A%0A
         for 
@@ -1119,60 +1119,279 @@
 ng.%22
- ) %7C%7C%0A                 e.getClassName().startsWith( 
+)) %7B%0A                if (otcount++ == 0) %7B%0A                    System.out.println(%22  %22 + e + %22 (with others of org.testng.* omitted)%22);%0A                %7D%0A            %7D%0A            else if (e.getClassName().startsWith( %22java.lang.reflect.%22) %7C%7C e.getClassName().startsWith(
 %22sun
@@ -1404,12 +1404,13 @@
 ct.%22
- 
 ) )
+ %7B
 %0A   
@@ -1426,19 +1426,204 @@
     
+if (jlr
 co
+u
 nt
-inue;%0A%0A
+++ == 0) %7B%0A                    System.out.println(%22  %22 + e  + %22 (with others of java.lang.reflect.* or sun.reflect.* omitted)%22);%0A                %7D%0A            %7D%0A            else %7B%0A    
     
@@ -1653,14 +1653,25 @@
 tln(
+%22  %22 + 
  e );%0A
+    
     
@@ -1668,32 +1668,211 @@
 ;%0A            %7D%0A
+        %7D%0A%0A        if (t.getCause() != null) %7B%0A            System.out.println(%22Caused By : %22);%0A        %0A            _print(t.getCause());%0A        %7D%0A%0A        System.out.println();%0A
     %7D%0A    %0A    p

Improve the stacktrace output of TestNGListener