Java Code Examples for org.codehaus.groovy.control.CompilationFailedException#getMessage()

The following examples show how to use org.codehaus.groovy.control.CompilationFailedException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroovyRunner.java    From flow-platform-x with Apache License 2.0 5 votes vote down vote up
private GroovyRunner<T> setScript(String source) throws ScriptException {
    try {
        GroovyShell shell = new GroovyShell(binding);
        script = shell.parse(source);
        return this;
    } catch (CompilationFailedException e) {
        throw new ScriptException("Script compile failed: " + e.getMessage());
    }
}
 
Example 2
Source File: GroovyDynamicData.java    From phoenix.webui.framework with Apache License 2.0 5 votes vote down vote up
@Override
public String getValue(String orginData)
{
	String value;
	
	Binding binding = new Binding();
	GroovyShell shell = new GroovyShell(binding);
	
	binding.setVariable("globalMap", globalMap);
	Object resObj = null;
	try
	{
		resObj = shell.evaluate(groovyCls + orginData);
		if(resObj != null)
		{
			value = resObj.toString();
		}
		else
	 	{
			value = "groovy not return!";
		}
	}
	catch(CompilationFailedException e)
	{
		value = e.getMessage();
           logger.error("Groovy动态数据语法错误!", e);
	}
	
	return value;
}
 
Example 3
Source File: GroovyRunner.java    From flow-platform-x with Apache License 2.0 5 votes vote down vote up
private GroovyRunner<T> setScript(String source) throws ScriptException {
    try {
        GroovyShell shell = new GroovyShell(binding);
        script = shell.parse(source);
        return this;
    } catch (CompilationFailedException e) {
        throw new ScriptException("Script compile failed: " + e.getMessage());
    }
}
 
Example 4
Source File: ScriptManagerImpl.java    From jira-groovioli with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public String validateSyntax(String groovyScript) {
    try {
        shell.parse(groovyScript);
    } catch (CompilationFailedException e) {
        return e.getMessage();
    }
    return null;
}
 
Example 5
Source File: ContentWorker.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/** Returns a boolean, result of whenStr evaluation with context.
 * If whenStr is empty return defaultReturn.
 * @param context A <code>Map</code> containing initial variables
 * @param whenStr A <code>String</code> condition expression
 * @param defaultReturn A <code>boolean</code> default return value
 * @return A <code>boolan</code> result of evaluation
 */
public static boolean checkWhen(Map<String, Object> context, String whenStr, boolean defaultReturn) {
    boolean isWhen = defaultReturn;
    if (UtilValidate.isNotEmpty(whenStr)) {
        FlexibleStringExpander fse = FlexibleStringExpander.getInstance(whenStr);
        String newWhen = fse.expandString(context);
        try {
            // SCIPIO: 2018-09-19: use Groovy
            // FIXME?: NO SCRIPT CACHING: It is not currently possible to cache this condition script safely,
            // because the method and transforms calling it are public so it is unknown who will call this from where,
            // so we could be receiving parametrized input and exploding the cache.
            //final boolean useCache = fse.isConstant();
            final boolean useCache = false;
            Object retVal = GroovyUtil.evalConditionExpr(newWhen, context, useCache);
            // retVal should be a Boolean, if not something weird is up...
            if (retVal instanceof Boolean) {
                Boolean boolVal = (Boolean) retVal;
                isWhen = boolVal;
            } else {
                throw new IllegalArgumentException("Return value from use-when condition eval was not a Boolean: "
                        + (retVal != null ? retVal.getClass().getName() : "null") + " [" + retVal + "]");
            }
        } catch (CompilationFailedException e) {
            Debug.logError("Error in evaluating :" + whenStr + " : " + e.getMessage(), module);
            throw new RuntimeException(e.getMessage());
        }
    }
    return isWhen;
}