use of groovy.lang.GroovyShell in project groovy by apache.
the class UnimplementedSyntaxTest method test_StaticImport2.
public void test_StaticImport2() throws Exception {
//GROOVY-3711: The following call now results in a valid script class node, so foo.Bar needs to get resolved.
GroovyShell groovyShell = new GroovyShell();
compile("package foo; class Bar{}", groovyShell);
assertNotNull(compile("import static foo.Bar.*", groovyShell));
}
use of groovy.lang.GroovyShell in project intellij-community by JetBrains.
the class GroovyScriptMacro method runIt.
private static Object runIt(Expression[] params, ExpressionContext context) {
try {
Result result = params[0].calculateResult(context);
if (result == null)
return result;
String text = result.toString();
GroovyShell shell = new GroovyShell();
File possibleFile = new File(text);
Script script = possibleFile.exists() ? shell.parse(possibleFile) : shell.parse(text);
Binding binding = new Binding();
for (int i = 1; i < params.length; ++i) {
Result paramResult = params[i].calculateResult(context);
Object value = null;
if (paramResult instanceof ListResult) {
value = ContainerUtil.map2List(((ListResult) paramResult).getComponents(), result1 -> result1.toString());
} else if (paramResult != null) {
value = paramResult.toString();
}
binding.setVariable("_" + i, value);
}
binding.setVariable("_editor", context.getEditor());
script.setBinding(binding);
Object o = script.run();
return o != null ? StringUtil.convertLineSeparators(o.toString()) : null;
} catch (Exception e) {
return new TextResult(StringUtil.convertLineSeparators(e.getLocalizedMessage()));
}
}
use of groovy.lang.GroovyShell in project intellij-community by JetBrains.
the class DependentGroovycRunner method applyConfigurationScript.
// adapted from https://github.com/gradle/gradle/blob/c4fdfb57d336b1a0f1b27354c758c61c0a586942/subprojects/language-groovy/src/main/java/org/gradle/api/internal/tasks/compile/ApiGroovyCompiler.java
private static void applyConfigurationScript(File configScript, CompilerConfiguration configuration) {
Binding binding = new Binding();
binding.setVariable("configuration", configuration);
CompilerConfiguration configuratorConfig = new CompilerConfiguration();
ImportCustomizer customizer = new ImportCustomizer();
customizer.addStaticStars("org.codehaus.groovy.control.customizers.builder.CompilerCustomizationBuilder");
configuratorConfig.addCompilationCustomizers(customizer);
try {
new GroovyShell(binding, configuratorConfig).evaluate(configScript);
} catch (Exception e) {
e.printStackTrace();
}
}
use of groovy.lang.GroovyShell in project uPortal by Jasig.
the class PortalShell method main.
public static void main(String[] args) throws Exception {
final Options options = getOptions();
final CommandLineParser parser = new PosixParser();
final CommandLine commandLine;
try {
commandLine = parser.parse(options, args);
} catch (ParseException e) {
System.err.println(e.getMessage());
printHelp(options);
return;
}
final ApplicationContext applicationContext = PortalApplicationContextLocator.getApplicationContext();
try {
final Binding binding = new SpringBinding(applicationContext);
binding.setVariable("logger", LOGGER);
final CompilerConfiguration conf = new CompilerConfiguration(System.getProperties());
final GroovyShell shell = new GroovyShell(binding, conf);
if (commandLine.hasOption("script")) {
final String scriptName = commandLine.getOptionValue("script");
final File scriptFile = getAbsoluteFile(scriptName);
shell.run(scriptFile, args);
}
} finally {
if (applicationContext instanceof DisposableBean) {
((DisposableBean) applicationContext).destroy();
}
}
}
use of groovy.lang.GroovyShell in project bamboobsc by billchen198318.
the class ScriptExpressionUtils method buildGroovyShell.
public static GroovyShell buildGroovyShell(boolean fromThreadLocal) {
if (fromThreadLocal) {
GroovyShell groovyShell = null;
if ((groovyShell = groovyShellTL.get()) == null) {
groovyShell = new GroovyShell(groovyCompilerConfig);
groovyShellTL.set(groovyShell);
}
return groovyShell;
}
return new GroovyShell(groovyCompilerConfig);
}
Aggregations