use of org.codehaus.groovy.control.MultipleCompilationErrorsException in project OpenAM by OpenRock.
the class StandardScriptValidator method getScriptErrors.
/**
* Convert from ScriptException to ScriptError.
*
* @param script the script that was validated.
* @param se the error thrown by the validation task.
* @return the converted script error.
*/
private List<ScriptError> getScriptErrors(ScriptObject script, ScriptException se) {
final List<ScriptError> scriptErrorList = new ArrayList<ScriptError>();
final Throwable cause = se.getCause();
// with useful information so we have to retrieve it from the cause exception.
if (cause instanceof EvaluatorException) {
final EvaluatorException ee = (EvaluatorException) cause;
final ScriptError error = new ScriptError();
error.setScriptName(script.getName());
error.setMessage(ee.details());
error.setLineNumber(ee.lineNumber());
error.setColumnNumber(ee.columnNumber());
scriptErrorList.add(error);
} else if (cause instanceof MultipleCompilationErrorsException) {
ErrorCollector errorCollector = ((MultipleCompilationErrorsException) cause).getErrorCollector();
for (int i = 0; i < errorCollector.getErrorCount(); i++) {
final SyntaxException syntaxException = errorCollector.getSyntaxError(i);
final ScriptError error = new ScriptError();
error.setScriptName(script.getName());
error.setMessage(syntaxException.getOriginalMessage());
error.setLineNumber(syntaxException.getLine());
error.setColumnNumber(syntaxException.getStartColumn());
scriptErrorList.add(error);
}
} else {
final ScriptError error = new ScriptError();
error.setScriptName(script.getName());
error.setMessage(se.getMessage());
error.setLineNumber(se.getLineNumber());
error.setColumnNumber(se.getColumnNumber());
scriptErrorList.add(error);
}
return scriptErrorList;
}
use of org.codehaus.groovy.control.MultipleCompilationErrorsException in project intellij-community by JetBrains.
the class GrapeRunner method main.
public static void main(String[] args) {
final GroovyShell shell = new GroovyShell();
try {
shell.parse(args[0] + " import java.lang.*");
} catch (MultipleCompilationErrorsException e) {
List errors = e.getErrorCollector().getErrors();
for (Iterator iterator = errors.iterator(); iterator.hasNext(); ) {
Object o = iterator.next();
if (o instanceof ExceptionMessage) {
Exception cause = ((ExceptionMessage) o).getCause();
String message = cause.getMessage();
if (message != null && message.startsWith("Error grabbing Grapes")) {
System.out.println(message);
return;
}
}
}
e.printStackTrace();
return;
} catch (Throwable e) {
e.printStackTrace();
return;
}
URL[] urls = shell.getClassLoader().getURLs();
for (int i = 0; i < urls.length; i++) {
System.out.println(URL_PREFIX + urls[i]);
}
}
use of org.codehaus.groovy.control.MultipleCompilationErrorsException in project intellij-community by JetBrains.
the class ScriptSupport method checkValidScript.
public static String checkValidScript(String scriptText) {
try {
final File scriptFile = new File(scriptText);
final GroovyShell shell = new GroovyShell();
final Script script = scriptFile.exists() ? shell.parse(scriptFile) : shell.parse(scriptText);
return null;
} catch (IOException e) {
return e.getMessage();
} catch (MultipleCompilationErrorsException e) {
final ErrorCollector errorCollector = e.getErrorCollector();
final List<Message> errors = errorCollector.getErrors();
for (Message error : errors) {
if (error instanceof SyntaxErrorMessage) {
final SyntaxErrorMessage errorMessage = (SyntaxErrorMessage) error;
final SyntaxException cause = errorMessage.getCause();
return cause.getMessage();
}
}
return e.getMessage();
} catch (CompilationFailedException ex) {
return ex.getLocalizedMessage();
}
}
use of org.codehaus.groovy.control.MultipleCompilationErrorsException in project workflow-cps-plugin by jenkinsci.
the class CpsFlowDefinitionValidator method toCheckStatus.
public static List<CheckStatus> toCheckStatus(CompilationFailedException x) {
List<CheckStatus> errors = new ArrayList<CheckStatus>();
if (x instanceof MultipleCompilationErrorsException) {
for (Object o : ((MultipleCompilationErrorsException) x).getErrorCollector().getErrors()) {
if (o instanceof SyntaxErrorMessage) {
SyntaxException cause = ((SyntaxErrorMessage) o).getCause();
CheckStatus st = new CheckStatus(cause.getOriginalMessage(), FAIL_KEY);
st.setLine(cause.getLine());
st.setColumn(cause.getStartColumn());
errors.add(st);
}
}
}
if (errors.isEmpty()) {
// Fallback to simple message
CheckStatus st = new CheckStatus(x.getMessage(), FAIL_KEY);
st.setLine(1);
st.setColumn(0);
errors.add(st);
}
return errors;
}
use of org.codehaus.groovy.control.MultipleCompilationErrorsException in project gradle by gradle.
the class DefaultScriptCompilationHandler method wrapCompilationFailure.
private void wrapCompilationFailure(ScriptSource source, MultipleCompilationErrorsException e) {
// Fix the source file name displayed in the error messages
for (Object message : e.getErrorCollector().getErrors()) {
if (message instanceof SyntaxErrorMessage) {
try {
SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage) message;
Field sourceField = SyntaxErrorMessage.class.getDeclaredField("source");
sourceField.setAccessible(true);
SourceUnit sourceUnit = (SourceUnit) sourceField.get(syntaxErrorMessage);
Field nameField = SourceUnit.class.getDeclaredField("name");
nameField.setAccessible(true);
nameField.set(sourceUnit, source.getDisplayName());
} catch (Exception failure) {
throw UncheckedException.throwAsUncheckedException(failure);
}
}
}
SyntaxException syntaxError = e.getErrorCollector().getSyntaxError(0);
Integer lineNumber = syntaxError == null ? null : syntaxError.getLine();
throw new ScriptCompilationException(String.format("Could not compile %s.", source.getDisplayName()), e, source, lineNumber);
}
Aggregations