Search in sources :

Example 6 with GroovyScriptEngine

use of groovy.util.GroovyScriptEngine in project groovy-core by groovy.

the class Groovy1567_Bug method testGroovyScriptEngineVsGroovyShell.

public void testGroovyScriptEngineVsGroovyShell() throws IOException, ResourceException, ScriptException {
    // @todo refactor this path
    File currentDir = new File("./src/test/groovy/bugs");
    String file = "bug1567_script.groovy";
    Binding binding = new Binding();
    GroovyShell shell = new GroovyShell(binding);
    String[] test = null;
    Object result = shell.run(new File(currentDir, file), test);
    String[] roots = new String[] { currentDir.getAbsolutePath() };
    GroovyScriptEngine gse = new GroovyScriptEngine(roots);
    binding = new Binding();
    // a MME was ensued here stating no 't.start()' was available
    // in the script
    gse.run(file, binding);
}
Also used : Binding(groovy.lang.Binding) GroovyScriptEngine(groovy.util.GroovyScriptEngine) File(java.io.File) GroovyShell(groovy.lang.GroovyShell)

Example 7 with GroovyScriptEngine

use of groovy.util.GroovyScriptEngine in project groovy by apache.

the class Groovy1567_Bug method testGroovyScriptEngineVsGroovyShell.

public void testGroovyScriptEngineVsGroovyShell() throws IOException, ResourceException, ScriptException {
    // @todo refactor this path
    File currentDir = new File("./src/test/groovy/bugs");
    String file = "bug1567_script.groovy";
    Binding binding = new Binding();
    GroovyShell shell = new GroovyShell(binding);
    String[] test = null;
    Object result = shell.run(new File(currentDir, file), test);
    String[] roots = new String[] { currentDir.getAbsolutePath() };
    GroovyScriptEngine gse = new GroovyScriptEngine(roots);
    binding = new Binding();
    // a MME was ensued here stating no 't.start()' was available
    // in the script
    gse.run(file, binding);
}
Also used : Binding(groovy.lang.Binding) GroovyScriptEngine(groovy.util.GroovyScriptEngine) File(java.io.File) GroovyShell(groovy.lang.GroovyShell)

Example 8 with GroovyScriptEngine

use of groovy.util.GroovyScriptEngine in project pom-manipulation-ext by release-engineering.

the class TestUtils method runScript.

/**
 * Run runScript.groovy script in workingDir directory.
 *
 * @param workingDir - Directory with groovy script.
 * @param file - groovy script to run
 * @throws Exception if an error occurs
 */
private static void runScript(String workingDir, String file) throws Exception {
    File verify = new File(workingDir + "/" + file + ".groovy");
    if (!verify.isFile()) {
        return;
    }
    Binding binding = new Binding();
    binding.setVariable("basedir", workingDir);
    GroovyScriptEngine engine = new GroovyScriptEngine(workingDir);
    engine.run(file + ".groovy", binding);
}
Also used : Binding(groovy.lang.Binding) GroovyScriptEngine(groovy.util.GroovyScriptEngine) File(java.io.File)

Example 9 with GroovyScriptEngine

use of groovy.util.GroovyScriptEngine in project groovy-core by groovy.

the class GroovyClassLoaderDeadlockTest method testNoDeadlockWhenTwoThreadsCompileScripts.

public void testNoDeadlockWhenTwoThreadsCompileScripts() throws IOException, InterruptedException {
    String[] roots = new String[] { PATH };
    GroovyScriptEngine gse = new GroovyScriptEngine(roots);
    Runner[] runners = new Runner[] { new Runner(gse, "script0.groovy", 0), new Runner(gse, "script1.groovy", 1) };
    for (Runner runner : runners) {
        runner.start();
    }
    for (Runner runner : runners) {
        runner.join();
    }
    assertEquals("0+0=0", runners[0].getResult());
    assertEquals("1+1=2", runners[1].getResult());
}
Also used : GroovyScriptEngine(groovy.util.GroovyScriptEngine)

Example 10 with GroovyScriptEngine

use of groovy.util.GroovyScriptEngine in project groovy by apache.

the class GroovyClassLoaderDeadlockTest method testNoDeadlockWhenTwoThreadsCompileScripts.

public void testNoDeadlockWhenTwoThreadsCompileScripts() throws IOException, InterruptedException {
    String[] roots = new String[] { PATH };
    GroovyScriptEngine gse = new GroovyScriptEngine(roots);
    Runner[] runners = new Runner[] { new Runner(gse, "script0.groovy", 0), new Runner(gse, "script1.groovy", 1) };
    for (Runner runner : runners) {
        runner.start();
    }
    for (Runner runner : runners) {
        runner.join();
    }
    assertEquals("0+0=0", runners[0].getResult());
    assertEquals("1+1=2", runners[1].getResult());
}
Also used : GroovyScriptEngine(groovy.util.GroovyScriptEngine)

Aggregations

GroovyScriptEngine (groovy.util.GroovyScriptEngine)11 Binding (groovy.lang.Binding)5 File (java.io.File)5 GroovyShell (groovy.lang.GroovyShell)3 ResourceException (groovy.util.ResourceException)3 ScriptException (groovy.util.ScriptException)3 Closure (groovy.lang.Closure)2 GitBlitException (com.gitblit.GitBlitException)1 UserModel (com.gitblit.models.UserModel)1 Script (groovy.lang.Script)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1 KnowledgeBaseScript (org.openksavi.sponge.kb.KnowledgeBaseScript)1