public GroovyCodeSource run() { return new GroovyCodeSource(in, fileName, DEFAULT_CODE_BASE); } });
public GroovyCodeSource run() { return new GroovyCodeSource(scriptText, fileName, codeBase); } });
protected void execute(URL bundled) throws IOException { if (bundled!=null) { LOGGER.info("Executing bundled script: "+bundled); execute(new GroovyCodeSource(bundled)); } }
protected void execute(File f) { if (f.exists()) { LOGGER.info("Executing "+f); try { execute(new GroovyCodeSource(f)); } catch (IOException e) { LOGGER.log(WARNING, "Failed to execute " + f, e); } } }
@SuppressWarnings("unchecked") public MarkupTemplateMaker(final Reader reader, String sourceName, Map<String, String> modelTypes) { String name = sourceName != null ? sourceName : "GeneratedMarkupTemplate" + counter.getAndIncrement(); templateClass = groovyClassLoader.parseClass(new GroovyCodeSource(reader, name, ""), modelTypes); this.modeltypes = modelTypes; }
/** * Runs the given script source with command line arguments * * @param source is the source content of the script * @param args the command line arguments to pass in */ public Object run(URI source, List args) throws CompilationFailedException, IOException { return run(new GroovyCodeSource(source), ((String[]) args.toArray(EMPTY_STRING_ARRAY))); }
/** * Runs the given script source with command line arguments * * @param source is the source content of the script * @param args the command line arguments to pass in */ public Object run(URI source, String[] args) throws CompilationFailedException, IOException { return run(new GroovyCodeSource(source), args); }
/** * Parses the given script and returns it ready to be run * * @param reader the stream reading the script * @param fileName is the logical file name of the script (which is used to create the class name of the script) * @return the parsed script which is ready to be run via {@link Script#run()} */ public Script parse(final Reader reader, final String fileName) throws CompilationFailedException { return parse(new GroovyCodeSource(reader, fileName, DEFAULT_CODE_BASE)); }
/** * Parses the given script and returns it ready to be run * * @param uri is the URI of the script (which is used to create the class name of the script) */ public Script parse(URI uri) throws CompilationFailedException, IOException { return parse(new GroovyCodeSource(uri)); }
/** * Parses the given file into a Java class capable of being run * * @param file the file name to parse * @return the main class defined in the given script */ public Class parseClass(File file) throws CompilationFailedException, IOException { return parseClass(new GroovyCodeSource(file, config.getSourceEncoding())); }
/** * Parses the given script and returns it ready to be run * * @param file is the file of the script (which is used to create the class name of the script) */ public Script parse(File file) throws CompilationFailedException, IOException { return parse(new GroovyCodeSource(file, config.getSourceEncoding())); }
public GroovyCodeSource run() { try { String scriptText = config.getSourceEncoding() != null ? IOGroovyMethods.getText(in, config.getSourceEncoding()) : IOGroovyMethods.getText(in); return new GroovyCodeSource(scriptText, fileName, "/groovy/script"); } catch (IOException e) { throw new RuntimeException("Impossible to read the content of the input stream for file named: " + fileName, e); } } });
protected GroovyObject compile(String fileName) throws Exception { Class groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName))); GroovyObject object = (GroovyObject) groovyClass.newInstance(); assertTrue(object != null); return object; } }
protected void assertScriptFile(String fileName) throws Exception { log.info("About to execute script: " + fileName); Class groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName))); Script script = InvokerHelper.createScript(groovyClass, new Binding()); script.run(); }
public void testWithGCSWithURL() throws Exception { String scriptFileName = "src/test/groovy/bugs/GROOVY3934Helper.groovy"; File helperScript = new File(scriptFileName); if(!helperScript.exists()) { fail("File " + scriptFileName + " does not exist"); } else { URL url = helperScript.toURI().toURL(); GroovyCodeSource gcs = new GroovyCodeSource(url); GroovyShell shell = new GroovyShell(); Object result = shell.evaluate(gcs); assertEquals("GROOVY3934Helper script called", result); } }
protected Class parseClass(File file) { GroovyCodeSource gcs = null; try { gcs = new GroovyCodeSource(file); } catch (IOException fnfe) { fail(fnfe.toString()); } return parseClass(gcs); }
public void testCodeSource() throws IOException, CompilationFailedException { URL script = loader.getResource("groovy/ArrayTest.groovy"); try { new GroovyCodeSource(script); } catch (RuntimeException re) { assertEquals("Could not construct a GroovyCodeSource from a null URL", re.getMessage()); } }
protected void assertExecute(File file, Permission missingPermission) { if (!isSecurityAvailable()) { return; } GroovyCodeSource gcs = null; try { gcs = new GroovyCodeSource(file); } catch (IOException fnfe) { fail(fnfe.toString()); } parseAndExecute(gcs, missingPermission); }
protected void assertExecute(String scriptStr, String codeBase, Permission missingPermission) { if (!isSecurityAvailable()) { return; } if (codeBase == null) { codeBase = "/groovy/security/test"; } parseAndExecute(new GroovyCodeSource(scriptStr, generateClassName(), codeBase), missingPermission); } }
public void testCreateScriptWithScriptClass() { GroovyClassLoader classLoader = new GroovyClassLoader(); String controlProperty = "text"; String controlValue = "I am a script"; String code = controlProperty + " = '" + controlValue + "'"; GroovyCodeSource codeSource = new GroovyCodeSource(code, "testscript", "/groovy/shell"); Class scriptClass = classLoader.parseClass(codeSource, false); Script script = InvokerHelper.createScript(scriptClass, new Binding(bindingVariables)); assertEquals(bindingVariables, script.getBinding().getVariables()); script.run(); assertEquals(controlValue, script.getProperty(controlProperty)); } }