Search in sources :

Example 11 with ImportCustomizer

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);
    }
}
Also used : Binding(groovy.lang.Binding) GradleException(org.gradle.api.GradleException) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) ImportCustomizer(org.codehaus.groovy.control.customizers.ImportCustomizer) VersionNumber(org.gradle.util.VersionNumber) GroovyShell(groovy.lang.GroovyShell) GradleException(org.gradle.api.GradleException)

Example 12 with ImportCustomizer

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);
        }
    }
}
Also used : Binding(groovy.lang.Binding) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) ImportCustomizer(org.codehaus.groovy.control.customizers.ImportCustomizer) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) GroovyShell(groovy.lang.GroovyShell)

Example 13 with ImportCustomizer

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();
    }
}
Also used : Binding(groovy.lang.Binding) ImportCustomizer(org.codehaus.groovy.control.customizers.ImportCustomizer) GroovyShell(groovy.lang.GroovyShell)

Example 14 with ImportCustomizer

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;
}
Also used : Closure(groovy.lang.Closure) ImportCustomizer(org.codehaus.groovy.control.customizers.ImportCustomizer)

Example 15 with ImportCustomizer

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;
}
Also used : ImportCustomizer(org.codehaus.groovy.control.customizers.ImportCustomizer)

Aggregations

ImportCustomizer (org.codehaus.groovy.control.customizers.ImportCustomizer)22 GroovyShell (groovy.lang.GroovyShell)13 CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)13 Binding (groovy.lang.Binding)11 Closure (groovy.lang.Closure)4 File (java.io.File)3 GroovyClassLoader (groovy.lang.GroovyClassLoader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Constructor (java.lang.reflect.Constructor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 List (java.util.List)2 ParseException (org.apache.commons.cli.ParseException)2 BuildException (org.apache.tools.ant.BuildException)2 GroovyBugError (org.codehaus.groovy.GroovyBugError)2 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)2 SimpleMessage (org.codehaus.groovy.control.messages.SimpleMessage)2 GroovityASTTransformation (com.disney.groovity.compile.GroovityASTTransformation)1