Search in sources :

Example 1 with ASTTransformationCustomizer

use of org.codehaus.groovy.control.customizers.ASTTransformationCustomizer in project groovity by disney.

the class Groovity method createCompilerConfiguration.

protected CompilerConfiguration createCompilerConfiguration(Map<Integer, Integer> sourceLineNumbers, Collection<String> initDependencies) {
    CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
    if (scriptBaseClass != null) {
        compilerConfiguration.setScriptBaseClass(scriptBaseClass);
        compilerConfiguration.addCompilationCustomizers(new ImportCustomizer().addImports(scriptBaseClass));
    }
    compilerConfiguration.addCompilationCustomizers(new ImportCustomizer().addStarImports("java.util.concurrent", "groovy.transform", "java.util.function", "com.disney.groovity.model").addImports(ClosureWritable.class.getName(), AsyncChannel.class.getName(), GroovityStatistics.class.getName(), Taggable.class.getName(), Tag.class.getName(), Attr.class.getName(), Function.class.getName(), Arg.class.getName(), SkipStatistics.class.getName()));
    compilerConfiguration.addCompilationCustomizers(new ASTTransformationCustomizer(new GroovityASTTransformation(this, sourceLineNumbers, initDependencies)));
    compilerConfiguration.addCompilationCustomizers(new ASTTransformationCustomizer(new StatsASTTransformation()));
    Map<String, Boolean> options = compilerConfiguration.getOptimizationOptions();
    options.put(CompilerConfiguration.JDK8, true);
    compilerConfigurationDecorators.forEach(decorator -> {
        decorator.decorate(compilerConfiguration);
    });
    return compilerConfiguration;
}
Also used : ASTTransformationCustomizer(org.codehaus.groovy.control.customizers.ASTTransformationCustomizer) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) ImportCustomizer(org.codehaus.groovy.control.customizers.ImportCustomizer) StatsASTTransformation(com.disney.groovity.compile.StatsASTTransformation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GroovityASTTransformation(com.disney.groovity.compile.GroovityASTTransformation)

Example 2 with ASTTransformationCustomizer

use of org.codehaus.groovy.control.customizers.ASTTransformationCustomizer in project spring-integration by spring-projects.

the class GroovyScriptExecutingMessageProcessor method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    if (this.beanFactory != null && this.beanFactory instanceof ConfigurableListableBeanFactory) {
        ((ConfigurableListableBeanFactory) this.beanFactory).ignoreDependencyType(MetaClass.class);
    }
    CompilerConfiguration compilerConfiguration = this.compilerConfiguration;
    if (compilerConfiguration == null && this.compileStatic) {
        compilerConfiguration = new CompilerConfiguration();
        compilerConfiguration.addCompilationCustomizers(new ASTTransformationCustomizer(CompileStatic.class));
    }
    this.groovyClassLoader = new GroovyClassLoader(this.beanClassLoader, compilerConfiguration);
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) ASTTransformationCustomizer(org.codehaus.groovy.control.customizers.ASTTransformationCustomizer) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) CompileStatic(groovy.transform.CompileStatic) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 3 with ASTTransformationCustomizer

use of org.codehaus.groovy.control.customizers.ASTTransformationCustomizer in project RecordManager2 by moravianlibrary.

the class AbstractScriptFactory method innerCreate.

private MappingScript<T> innerCreate(List<byte[]> scriptsSource) {
    logger.info("About to create new mapping script");
    final AssignmentEliminationTransformation astTransformer = new AssignmentEliminationTransformation();
    final Binding binding = createBinding();
    final List<DelegatingScript> scripts = new ArrayList<DelegatingScript>(scriptsSource.size());
    final CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
    compilerConfiguration.setScriptBaseClass(DelegatingScript.class.getCanonicalName());
    compilerConfiguration.addCompilationCustomizers(new SecureASTCustomizer(), new ASTTransformationCustomizer(astTransformer));
    for (byte[] scriptSource : scriptsSource) {
        GroovyShell sh = new GroovyShell(binding, compilerConfiguration);
        final DelegatingScript script = (DelegatingScript) sh.parse(new InputStreamReader(new ByteArrayInputStream(scriptSource)));
        scripts.add(script);
        astTransformer.getVariablesToExclude().addAll(astTransformer.getVariablesToExclude());
    }
    Collections.reverse(scripts);
    MappingScript<T> result = create(binding, scripts);
    logger.info("New mapping script created");
    return result;
}
Also used : Binding(groovy.lang.Binding) ASTTransformationCustomizer(org.codehaus.groovy.control.customizers.ASTTransformationCustomizer) SecureASTCustomizer(org.codehaus.groovy.control.customizers.SecureASTCustomizer) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) GroovyShell(groovy.lang.GroovyShell) ByteArrayInputStream(java.io.ByteArrayInputStream) DelegatingScript(groovy.util.DelegatingScript) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration)

Aggregations

CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)3 ASTTransformationCustomizer (org.codehaus.groovy.control.customizers.ASTTransformationCustomizer)3 GroovityASTTransformation (com.disney.groovity.compile.GroovityASTTransformation)1 StatsASTTransformation (com.disney.groovity.compile.StatsASTTransformation)1 Binding (groovy.lang.Binding)1 GroovyClassLoader (groovy.lang.GroovyClassLoader)1 GroovyShell (groovy.lang.GroovyShell)1 CompileStatic (groovy.transform.CompileStatic)1 DelegatingScript (groovy.util.DelegatingScript)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ImportCustomizer (org.codehaus.groovy.control.customizers.ImportCustomizer)1 SecureASTCustomizer (org.codehaus.groovy.control.customizers.SecureASTCustomizer)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1