use of org.codehaus.groovy.control.customizers.ImportCustomizer 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.customizers.ImportCustomizer in project groovy by apache.
the class Groovy method configureCompiler.
private void configureCompiler() {
if (scriptBaseClass != null) {
configuration.setScriptBaseClass(scriptBaseClass);
}
if (indy) {
configuration.getOptimizationOptions().put("indy", Boolean.TRUE);
configuration.getOptimizationOptions().put("int", Boolean.FALSE);
}
if (configscript != null) {
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);
File confSrc = new File(configscript);
try {
shell.evaluate(confSrc);
} catch (IOException e) {
throw new BuildException("Unable to configure compiler using configuration file: " + confSrc, e);
}
}
}
use of org.codehaus.groovy.control.customizers.ImportCustomizer 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 org.codehaus.groovy.control.customizers.ImportCustomizer in project groovy by apache.
the class ImportCustomizerFactory method onNodeChildren.
@Override
public boolean onNodeChildren(final FactoryBuilderSupport builder, final Object node, final Closure childContent) {
if (node instanceof ImportCustomizer) {
Closure clone = (Closure) childContent.clone();
clone.setDelegate(new ImportHelper((ImportCustomizer) node));
clone.call();
}
return false;
}
use of org.codehaus.groovy.control.customizers.ImportCustomizer in project groovy by apache.
the class ImportCustomizerFactory method newInstance.
public Object newInstance(final FactoryBuilderSupport builder, final Object name, final Object value, final Map attributes) throws InstantiationException, IllegalAccessException {
ImportCustomizer customizer = new ImportCustomizer();
addImport(customizer, value);
return customizer;
}
Aggregations