public String getMessage() { Writer data = new StringBuilderWriter(); PrintWriter writer = new PrintWriter(data); Janitor janitor = new Janitor(); writer.write(super.getMessage()); writer.println(":"); try { collector.write(writer, janitor); } finally { janitor.cleanup(); } return data.toString(); } }
/** * For CompilationFailedException. */ protected void report( CompilationFailedException e, boolean child ) { println( e.toString() ); stacktrace( e, false ); }
/** * Convenience routine to get the named ClassNode. */ public ClassNode getClassNode(final String name) { final ClassNode[] result = new ClassNode[]{null}; PrimaryClassNodeOperation handler = new PrimaryClassNodeOperation() { public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) { if (classNode.getName().equals(name)) { result[0] = classNode; } } }; try { applyToPrimaryClassNodes(handler); } catch (CompilationFailedException e) { if (debug) e.printStackTrace(); } return result[0]; }
if (p++ >= 0) { if (scriptName.substring(p).equals("java")) { throw new CompilationFailedException(0, null);
/** * Performs on-the-fly validation on the Groovy script. * * @param script * the script * @return the validation result */ public static FormValidation doCheckScript(final String script) { try { if (StringUtils.isBlank(script)) { return FormValidation.error(Messages.Warnings_GroovyParser_Error_Script_isEmpty()); } GroovyShell groovyShell = new GroovyShell(WarningsDescriptor.class.getClassLoader()); groovyShell.parse(script); return FormValidation.ok(); } catch (CompilationFailedException exception) { return FormValidation.error(Messages.Warnings_GroovyParser_Error_Script_invalid(exception.getLocalizedMessage())); } } }
/** * Evaluates some script against the current Binding and returns the result * * @param scriptText the text of the script * @param fileName is the logical file name of the script (which is used to create the class name of the script) */ public Object evaluate(String scriptText, String fileName) throws CompilationFailedException { try { return evaluate(new ByteArrayInputStream(scriptText.getBytes(config.getSourceEncoding())), fileName); } catch (UnsupportedEncodingException e) { throw new CompilationFailedException(0, null, e); } }
/** * Performs on-the-fly validation on the Groovy script. * * @param script * the script * @return the validation result */ public FormValidation doCheckScript(@QueryParameter(required = true) final String script) { try { if (StringUtils.isBlank(script)) { return FormValidation.error(Messages.Warnings_GroovyParser_Error_Script_isEmpty()); } GroovyShell groovyShell = new GroovyShell(WarningsDescriptor.class.getClassLoader()); groovyShell.parse(script); return FormValidation.ok(); } catch (CompilationFailedException exception) { return FormValidation.error(Messages.Warnings_GroovyParser_Error_Script_invalid(exception.getLocalizedMessage())); } }
private Class loadScript(String name) { Class scriptClass = null; GroovyClassLoader gcl = new GroovyClassLoader(this.getClass().getClassLoader()); name = "src/test/" + getClass().getPackage().getName().replace(".", "/") + "/" + name; try { scriptClass = gcl.parseClass(new File(name)); } catch (CompilationFailedException e) { throw new RuntimeException("Script compilation failed: " + e.getMessage()); } catch (IOException e) { throw new RuntimeException("Script file not found: " + name); } return scriptClass; }
public Script parse(String scriptText, String fileName) throws CompilationFailedException { try { return parse(new ByteArrayInputStream(scriptText.getBytes(config.getSourceEncoding())), fileName); } catch (UnsupportedEncodingException e) { throw new CompilationFailedException(0, null, e); } }
/** * For CompilationFailedException. */ protected void report( CompilationFailedException e, boolean child ) { println( e.toString() ); stacktrace( e, false ); }
public static Test suite(String basedir, String pattern, String excludesPattern) { AllTestSuite suite = new AllTestSuite(); List<String> filenames = excludesPattern.length() > 0 ? finder.getFileNames(basedir, pattern, excludesPattern) : finder.getFileNames(basedir, pattern); for (String filename : filenames) { LOG.finest("trying to load " + filename); try { suite.loadTest(filename); } catch (CompilationFailedException cfe) { cfe.printStackTrace(); throw new RuntimeException("CompilationFailedException when loading " + filename, cfe); } catch (IOException ioe) { throw new RuntimeException("IOException when loading " + filename, ioe); } } return suite; }
/** * Performs on-the-fly validation on the Groovy script. * * @param script * the script * @return the validation result */ @RequirePOST public FormValidation doCheckScript(@QueryParameter(required = true) final String script) { if (!canRunScripts()) { return NO_RUN_SCRIPT_PERMISSION_WARNING; } try { if (StringUtils.isBlank(script)) { return FormValidation.error(Messages.Warnings_GroovyParser_Error_Script_isEmpty()); } GroovyExpressionMatcher matcher = new GroovyExpressionMatcher(script, null); matcher.compile(); return FormValidation.ok(); } catch (CompilationFailedException exception) { return FormValidation.error(Messages.Warnings_GroovyParser_Error_Script_invalid(exception.getLocalizedMessage())); } }
public FormValidation doCheckScript(@QueryParameter String command) { if (command == null || command.trim().isEmpty()) return FormValidation.error("Script seems to be empty string!"); try { new GroovyShell(GroovySandbox.createSecureCompilerConfiguration()).parse(command); return FormValidation.ok("So far so good"); } catch (CompilationFailedException e) { return FormValidation.error(e.getMessage()); } } }
public Script parse(String scriptText, String fileName) throws CompilationFailedException { try { return parse(new ByteArrayInputStream(scriptText.getBytes(config.getSourceEncoding())), fileName); } catch (UnsupportedEncodingException e) { throw new CompilationFailedException(0, null, e); } }
/** * For CompilationFailedException. */ protected void report( CompilationFailedException e, boolean child ) { println( e.toString() ); stacktrace( e, false ); }
/** * Convenience routine to get the named ClassNode. */ public ClassNode getClassNode(final String name) { final ClassNode[] result = new ClassNode[]{null}; PrimaryClassNodeOperation handler = new PrimaryClassNodeOperation() { public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) { if (classNode.getName().equals(name)) { result[0] = classNode; } } }; try { applyToPrimaryClassNodes(handler); } catch (CompilationFailedException e) { if (debug) e.printStackTrace(); } return result[0]; }