Search in sources :

Example 21 with GroovyClassLoader

use of groovy.lang.GroovyClassLoader in project be5 by DevelopmentOnTheEdge.

the class GroovyRegister method initClassLoader.

public void initClassLoader() {
    classLoader = new GroovyClassLoader();
    addClassPaths();
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader)

Example 22 with GroovyClassLoader

use of groovy.lang.GroovyClassLoader in project ofbiz-framework by apache.

the class GroovyUtil method loadClass.

public static Class<?> loadClass(String path) throws ClassNotFoundException, IOException {
    GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
    Class<?> classLoader = groovyClassLoader.loadClass(path);
    groovyClassLoader.close();
    return classLoader;
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader)

Example 23 with GroovyClassLoader

use of groovy.lang.GroovyClassLoader 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 24 with GroovyClassLoader

use of groovy.lang.GroovyClassLoader in project jbehave-core by jbehave.

the class BytecodeGroovyClassLoaderBehaviour method shouldCacheBytes.

@Test
public void shouldCacheBytes() throws IOException {
    GroovyClassLoader classLoader = new BytecodeGroovyClassLoader();
    assertThat((Class<?>) classLoader.parseClass("class Hello { }"), is(notNullValue()));
    InputStream bytecode = classLoader.getResourceAsStream("Hello.class");
    assertThat(bytecode, is(notNullValue()));
    bytecode.close();
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 25 with GroovyClassLoader

use of groovy.lang.GroovyClassLoader in project LogHub by fbacchella.

the class TestGroovy method testGroovy2.

@SuppressWarnings("unchecked")
@Test
public void testGroovy2() throws InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException, IOException {
    String script = "event.a.b * 2";
    try (GroovyClassLoader groovyClassLoader = new GroovyClassLoader()) {
        Class<Script> theParsedClass = groovyClassLoader.parseClass(script);
        Script groovyScript = theParsedClass.newInstance();
        Binding groovyBinding = new Binding();
        Event event = new EventInstance(ConnectionContext.EMPTY);
        event.put("a", Collections.singletonMap("b", 1));
        groovyBinding.setVariable("event", event);
        groovyScript.setBinding(groovyBinding);
        System.out.println(groovyScript.run().getClass());
    }
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) Binding(groovy.lang.Binding) Script(groovy.lang.Script) Test(org.junit.Test)

Aggregations

GroovyClassLoader (groovy.lang.GroovyClassLoader)136 File (java.io.File)28 GroovyObject (groovy.lang.GroovyObject)19 Test (org.junit.jupiter.api.Test)18 IOException (java.io.IOException)15 HashMap (java.util.HashMap)15 CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)14 Map (java.util.Map)12 Binding (groovy.lang.Binding)10 URL (java.net.URL)10 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)10 BuildException (org.apache.tools.ant.BuildException)9 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)9 ClassNode (org.codehaus.groovy.ast.ClassNode)9 CompilationUnit (org.codehaus.groovy.control.CompilationUnit)9 DefaultGrailsApplication (grails.core.DefaultGrailsApplication)8 GrailsApplication (grails.core.GrailsApplication)8 AnnotatedNode (org.codehaus.groovy.ast.AnnotatedNode)8 ArtefactHandler (grails.core.ArtefactHandler)7 SimpleMessage (org.codehaus.groovy.control.messages.SimpleMessage)7