use of groovy.lang.GroovyShell 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 groovy.lang.GroovyShell in project adempiere by adempiere.
the class GroovyEditor method actionProcess.
// actionPerformed
/**
* Process Script
*/
private void actionProcess() {
MUser user = MUser.get(Env.getCtx());
if (!user.isAdministrator()) {
fResult.setText("Not Administrator");
return;
}
//
GroovyShell sh = new GroovyShell();
Exception e = null;
try {
sh.parse(editor.getTextEditor().getText());
} catch (Exception e1) {
e = e1;
}
if (e != null) {
ADialog.error(m_WindowNo, this, "ScriptError", e.toString());
fResult.setText("Syntax errors detected.");
} else
fResult.setText("No syntax errors detected.");
}
use of groovy.lang.GroovyShell in project intellij-community by JetBrains.
the class GroovyModelInitializer method run.
@Override
public void run(JpsModel model) {
Map<String, Object> variables = new HashMap<>();
variables.put("project", model.getProject());
variables.put("global", model.getGlobal());
try {
new GroovyShell(new Binding(variables)).evaluate(myScriptFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of groovy.lang.GroovyShell 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 groovy.lang.GroovyShell in project fess by codelibs.
the class GroovyUtil method evaluate.
public static Object evaluate(final String template, final Map<String, Object> paramMap) {
final Map<String, Object> bindingMap = new HashMap<>(paramMap);
bindingMap.put("container", SingletonLaContainerFactory.getContainer());
final GroovyShell groovyShell = new GroovyShell(new Binding(bindingMap));
try {
return groovyShell.evaluate(template);
} catch (final Exception e) {
logger.warn("Failed to evalue groovy script: " + template + " => " + paramMap, e);
return null;
} finally {
final GroovyClassLoader loader = groovyShell.getClassLoader();
// StreamUtil.of(loader.getLoadedClasses()).forEach(c -> {
// try {
// GroovySystem.getMetaClassRegistry().removeMetaClass(c);
// } catch (Throwable t) {
// logger.warn("Failed to delete " + c, t);
// }
// });
loader.clearCache();
}
}
Aggregations