use of org.codehaus.groovy.control.CompilerConfiguration in project gradle by gradle.
the class ApiGroovyCompiler method applyConfigurationScript.
private void applyConfigurationScript(File configScript, CompilerConfiguration configuration) {
VersionNumber version = parseGroovyVersion();
if (version.compareTo(VersionNumber.parse("2.1")) < 0) {
throw new GradleException("Using a Groovy compiler configuration script requires Groovy 2.1+ but found Groovy " + version + "");
}
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);
GroovyShell shell = new GroovyShell(binding, configuratorConfig);
try {
shell.evaluate(configScript);
} catch (Exception e) {
throw new GradleException("Could not execute Groovy compiler configuration script: " + configScript.getAbsolutePath(), e);
}
}
use of org.codehaus.groovy.control.CompilerConfiguration in project groovy-core by groovy.
the class GroovyShellTest method testScriptWithCustomBodyMethod.
/**
* Test for GROOVY-6615
* @throws Exception
*/
public void testScriptWithCustomBodyMethod() throws Exception {
Binding context = new Binding();
CompilerConfiguration config = new CompilerConfiguration();
config.setScriptBaseClass(BaseScriptCustomBodyMethod.class.getName());
GroovyShell shell = new GroovyShell(context, config);
Object result = shell.evaluate("'I like ' + cheese");
assertEquals("I like Cheddar", result);
}
use of org.codehaus.groovy.control.CompilerConfiguration in project groovy-core by groovy.
the class GroovyShellTest method testScriptWithDerivedBaseClass.
public void testScriptWithDerivedBaseClass() throws Exception {
Binding context = new Binding();
CompilerConfiguration config = new CompilerConfiguration();
config.setScriptBaseClass(DerivedScript.class.getName());
GroovyShell shell = new GroovyShell(context, config);
Object result = shell.evaluate("x = 'abc'; doSomething(cheese)");
assertEquals("I like Cheddar", result);
assertEquals("abc", context.getVariable("x"));
}
use of org.codehaus.groovy.control.CompilerConfiguration in project groovy-core by groovy.
the class FileSystemCompiler method commandLineCompile.
/**
* Same as main(args) except that exceptions are thrown out instead of causing
* the VM to exit and the lookup for .groovy files can be controlled
*/
public static void commandLineCompile(String[] args, boolean lookupUnnamedFiles) throws Exception {
Options options = createCompilationOptions();
CommandLineParser cliParser = new GroovyInternalPosixParser();
CommandLine cli;
cli = cliParser.parse(options, args);
if (cli.hasOption('h')) {
displayHelp(options);
return;
}
if (cli.hasOption('v')) {
displayVersion();
return;
}
displayStackTraceOnError = cli.hasOption('e');
CompilerConfiguration configuration = generateCompilerConfigurationFromOptions(cli);
//
// Load the file name list
String[] filenames = generateFileNamesFromOptions(cli);
boolean fileNameErrors = filenames == null;
if (!fileNameErrors && (filenames.length == 0)) {
displayHelp(options);
return;
}
fileNameErrors = fileNameErrors && !validateFiles(filenames);
if (!fileNameErrors) {
doCompilation(configuration, null, filenames, lookupUnnamedFiles);
}
}
use of org.codehaus.groovy.control.CompilerConfiguration in project spock by spockframework.
the class ConfigurationScriptLoader method createShell.
private GroovyShell createShell() {
CompilerConfiguration compilerSettings = new CompilerConfiguration();
compilerSettings.setScriptBaseClass(DelegatingScript.class.getName());
return new GroovyShell(getClass().getClassLoader(), new Binding(), compilerSettings);
}
Aggregations