package sortpom.exception;

import org.apache.maven.plugin.MojoFailureException;

/**
 * Converts internal runtime FailureException in a method to a MojoFailureException in order to give nice output to 
 * the Maven framework
 */
public class ExceptionConverter {
    private final Runnable method;
    private FailureException fex;

    public ExceptionConverter(Runnable method) {
        this.method = method;
    }

    public void executeAndConvertException() throws MojoFailureException {
        try {
            method.run();
        } catch (FailureException fex) {
            this.fex = fex;
        }
        if (fex != null) {
            throwMojoFailureException();
        }
    }

    private void throwMojoFailureException() throws MojoFailureException {
        if (fex.getCause() != null) {
            throw new MojoFailureException(fex.getMessage(), fex.getCause());
        } else {
            throw new MojoFailureException(fex.getMessage());
        }
    }
}

@@ -194,17 +194,16 @@
 utput to
- 
 %0A * the 
@@ -294,42 +294,8 @@
 hod;
-%0A    private FailureException fex;
 %0A%0A  
@@ -542,202 +542,8 @@
     
-        this.fex = fex;%0A        %7D%0A        if (fex != null) %7B%0A            throwMojoFailureException();%0A        %7D%0A    %7D%0A%0A    private void throwMojoFailureException() throws MojoFailureException %7B%0A
     
@@ -580,32 +580,36 @@
 ) %7B%0A            
+    
 throw new MojoFa
@@ -666,16 +666,20 @@
         
+   
+ 
 %7D else %7B
@@ -679,16 +679,20 @@
  else %7B%0A
+    
         
@@ -741,24 +741,38 @@
 Message());%0A
+            %7D%0A
         %7D%0A  
@@ -775,10 +775,11 @@
 %7D%0A    %7D%0A
+%0A
 %7D%0A

Raise coverage. Lets see if this can work with JaCoCo