/** * Evaluates the given Groovy expression with values bound from this combination. * * <p> * For example, if this combination is a=X,b=Y, then expressions like <tt>a=="X"</tt> would evaluate to * true. */ public boolean evalGroovyExpression(AxisList axes, String expression) { if(Util.fixEmptyAndTrim(expression)==null) return true; Binding binding = new Binding(); for (Map.Entry<String, String> e : entrySet()) binding.setVariable(e.getKey(),e.getValue()); binding.setVariable("index",toModuloIndex(axes)); binding.setVariable("uniqueId",toIndex(axes)); GroovyShell shell = new GroovyShell(binding); Object result = shell.evaluate("use("+BooleanCategory.class.getName().replace('$','.')+") {"+expression+"}"); return TRUE.equals(result); }
/** * Evaluates the given Groovy expression with values bound from this combination. * * <p> * For example, if this combination is a=X,b=Y, then expressions like <tt>a=="X"</tt> would evaluate to * true. */ public boolean evalGroovyExpression(AxisList axes, String expression) { if(Util.fixEmptyAndTrim(expression)==null) return true; Binding binding = new Binding(); for (Map.Entry<String, String> e : entrySet()) binding.setVariable(e.getKey(),e.getValue()); binding.setVariable("index",toModuloIndex(axes)); binding.setVariable("uniqueId",toIndex(axes)); GroovyShell shell = new GroovyShell(binding); Object result = shell.evaluate("use("+BooleanCategory.class.getName().replace('$','.')+") {"+expression+"}"); return TRUE.equals(result); }
/** * Evaluates the given Dynamic Language Script Expression with values bound * from this combination. <p> For example, if this combination is a=X,b=Y, * then expressions like <tt>a=="X"</tt> would evaluate to true. * * @param axes * @param expression * @param scriptType * @return */ public boolean evalScriptExpression(AxisList axes, String expression) { if (Util.fixEmptyAndTrim(expression) == null) { return true; } Object result = Boolean.TRUE; if (Hudson.getInstance().getScriptSupport() != null) { expression = "use(" + BooleanCategory.class.getName().replace('$', '.') + ") {" + expression + "}"; Map<String, Object> variableMap = new HashMap<String, Object>(); for (Map.Entry<String, String> e : entrySet()) { variableMap.put(e.getKey(), e.getValue()); } variableMap.put("index", toModuloIndex(axes)); variableMap.put("uniqueId", toIndex(axes)); result = Hudson.getInstance().getScriptSupport().evaluateExpression(expression, variableMap); } return TRUE.equals(result); }
/** * Evaluates the given Dynamic Language Script Expression with values bound from this combination. * <p> * For example, if this combination is a=X,b=Y, then expressions like <tt>a=="X"</tt> would evaluate to * true. * @param axes * @param expression * @param scriptType * @return */ public boolean evalScriptExpression(AxisList axes, String expression) { if (Util.fixEmptyAndTrim(expression) == null) { return true; } Object result = Boolean.TRUE; if (Hudson.getInstance().getScriptSupport() != null) { expression = "use(" + BooleanCategory.class.getName().replace('$', '.') + ") {" + expression + "}"; Map<String, Object> variableMap = new HashMap<String, Object>(); for (Map.Entry<String, String> e : entrySet()) { variableMap.put(e.getKey(), e.getValue()); } variableMap.put("index", toModuloIndex(axes)); variableMap.put("uniqueId", toIndex(axes)); result = Hudson.getInstance().getScriptSupport().evaluateExpression(expression, variableMap); } return TRUE.equals(result); }