1 package org.nanocontainer.script.groovy; 2 3 import java.util.Collections ; 4 import java.util.List ; 5 6 import org.codehaus.groovy.control.CompilationFailedException; 7 import org.codehaus.groovy.control.ErrorCollector; 8 import org.codehaus.groovy.control.ProcessingUnit; 9 import org.codehaus.groovy.control.messages.ExceptionMessage; 10 import org.nanocontainer.script.NanoContainerMarkupException; 11 12 16 public class GroovyCompilationException extends NanoContainerMarkupException { 17 private CompilationFailedException compilationFailedException; 18 19 public GroovyCompilationException(String message, CompilationFailedException e) { 20 super(message,e); 21 this.compilationFailedException = e; 22 } 23 24 public String getMessage() { 25 StringBuffer sb = new StringBuffer (); 26 sb.append(super.getMessage() + "\n"); 27 List errors = getErrors(compilationFailedException); 28 for (int i = 0; i < errors.size(); i++) { 29 Object o = errors.get(i); 30 if (o instanceof ExceptionMessage) { 31 ExceptionMessage em = (ExceptionMessage) o; 32 sb.append(em.getCause().getMessage() + "\n"); 33 } 34 } 35 return sb.toString(); 36 } 37 38 44 private List getErrors(CompilationFailedException e) { 45 ProcessingUnit unit = e.getUnit(); 46 if ( unit != null ){ 47 ErrorCollector collector = unit.getErrorCollector(); 48 if ( collector != null ){ 49 List errors = collector.getErrors(); 50 if ( errors != null ){ 51 return errors; 52 } 53 } 54 } 55 return Collections.EMPTY_LIST; 56 } 57 } 58 | Popular Tags |