es.iti.wakamiti.groovy.GroovyPropertyEvaluator Maven / Gradle / Ivy
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package es.iti.wakamiti.groovy;
import es.iti.commons.jext.Extension;
import es.iti.wakamiti.api.extensions.PropertyEvaluator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* This {@link PropertyEvaluator} allows eval groovy script.
*
* Pattern: {@code ${=[groovy script]}}
*
*
Examples:
*
* ${=1+1}
* ${=new Date().format('yyyy-MM-dd')}
*
*
* @author Maria Galbis Calomarde | [email protected]
*/
@Extension(provider = "es.iti.wakamiti", name = "groovy-property-resolver", version = "2.6",
extensionPoint = "es.iti.wakamiti.api.extensions.PropertyEvaluator")
public class GroovyPropertyEvaluator extends PropertyEvaluator {
@Override
public Pattern pattern() {
return Pattern.compile("\\$\\{=(?(((?!\\$\\{).)+))\\}");
}
@Override
public String evalProperty(String property, Matcher matcher) {
return GroovyHelper.executeScript(matcher.group("name")).toString();
}
}