diff --git a/cloudslang-compiler/src/main/java/io/cloudslang/lang/compiler/modeller/transformers/AbstractInOutForTransformer.java b/cloudslang-compiler/src/main/java/io/cloudslang/lang/compiler/modeller/transformers/AbstractInOutForTransformer.java index 2843ddde33..4b776b14c2 100644 --- a/cloudslang-compiler/src/main/java/io/cloudslang/lang/compiler/modeller/transformers/AbstractInOutForTransformer.java +++ b/cloudslang-compiler/src/main/java/io/cloudslang/lang/compiler/modeller/transformers/AbstractInOutForTransformer.java @@ -37,6 +37,11 @@ protected Accumulator extractFunctionData(Serializable... values) { functionDependencies.add(ScriptFunction.GET); } + boolean getSpVarFunctionFound = ExpressionUtils.matchGetSystemPropertyVariableFunction(expression); + if (getSpVarFunctionFound) { + functionDependencies.add(ScriptFunction.GET_SP_VAR); + } + for (ScriptFunction function : ScriptFunction.values()) { if (ExpressionUtils.matchesFunction(function, expression)) { functionDependencies.add(function); diff --git a/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/bindings/ScriptFunction.java b/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/bindings/ScriptFunction.java index eb223e6c71..77c6c37104 100644 --- a/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/bindings/ScriptFunction.java +++ b/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/bindings/ScriptFunction.java @@ -41,7 +41,9 @@ public enum ScriptFunction { CS_XPATH_QUERY("cs_xpath_query"), - CS_JSON_QUERY("cs_json_query"); + CS_JSON_QUERY("cs_json_query"), + + GET_SP_VAR("get_sp_var"); private final String value; diff --git a/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/constants/Regex.java b/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/constants/Regex.java index 17f8750f05..21f20ed5b4 100644 --- a/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/constants/Regex.java +++ b/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/constants/Regex.java @@ -98,5 +98,8 @@ public class Regex { public static final String DESCRIPTION_TOKEN = "#!"; public static final String DESCRIPTION_EMPTY_LINE = "(\\s*)(#!)(\\s*)"; + + // get_sp_var(flow_input) + public static final String GET_SP_VAR_REGEX = "get_sp_var\\(\\s*(.+)\\s*\\)"; //////////////// description end } diff --git a/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/utils/ExpressionUtils.java b/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/utils/ExpressionUtils.java index 658ab3919c..b699ce5d7e 100644 --- a/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/utils/ExpressionUtils.java +++ b/cloudslang-entities/src/main/java/io/cloudslang/lang/entities/utils/ExpressionUtils.java @@ -36,6 +36,7 @@ import static io.cloudslang.lang.entities.constants.Regex.SYSTEM_PROPERTY_REGEX_WITH_DEFAULT_DOUBLE_QUOTE; import static io.cloudslang.lang.entities.constants.Regex.SYSTEM_PROPERTY_REGEX_WITH_DEFAULT_SINGLE_QUOTE; import static java.util.regex.Pattern.compile; +import static io.cloudslang.lang.entities.constants.Regex.GET_SP_VAR_REGEX; /** * @author Bonczidai Levente @@ -65,6 +66,8 @@ private ExpressionUtils() { private static final Map patternsMap = new HashMap<>(); + private static final Pattern GET_SP_VAR_PATTERN = compile(GET_SP_VAR_REGEX, Pattern.UNICODE_CHARACTER_CLASS); + static { addPattern(ScriptFunction.CHECK_EMPTY, CHECK_EMPTY_REGEX); addPattern(ScriptFunction.CS_APPEND, CS_APPEND_REGEX); @@ -131,4 +134,8 @@ public static boolean matchesFunction(ScriptFunction function, String expression return false; } + + public static boolean matchGetSystemPropertyVariableFunction(String text) { + return matchPattern(GET_SP_VAR_PATTERN, text); + } } diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java index 974ab8372b..f825154056 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/bindings/scripts/ScriptEvaluator.java @@ -80,7 +80,13 @@ private Value doEvaluateExpressionJython(String expr, Set systemProperties, Set functionDependencies) { Map jythonContext = createJythonContext(context); - boolean systemPropertiesDefined = functionDependencies.contains(ScriptFunction.GET_SYSTEM_PROPERTY); + + boolean systemPropertiesDefined = false; + if (functionDependencies.contains(ScriptFunction.GET_SYSTEM_PROPERTY) + || functionDependencies.contains(ScriptFunction.GET_SP_VAR)) { + systemPropertiesDefined = true; + } + if (systemPropertiesDefined) { jythonContext.put(SYSTEM_PROPERTIES_MAP, (Serializable) prepareSystemPropertiesForJython(systemProperties)); @@ -93,7 +99,11 @@ private Value doEvaluateExpressionExternalPython(String expr, Set systemProperties, Set functionDependencies) { Map pythonContext = createExternalPythonContext(context); - boolean systemPropertiesDefined = functionDependencies.contains(ScriptFunction.GET_SYSTEM_PROPERTY); + boolean systemPropertiesDefined = false; + if (functionDependencies.contains(ScriptFunction.GET_SYSTEM_PROPERTY) + || functionDependencies.contains(ScriptFunction.GET_SP_VAR)) { + systemPropertiesDefined = true; + } if (systemPropertiesDefined) { pythonContext.put(SYSTEM_PROPERTIES_MAP, (Serializable) prepareSystemPropertiesForExternalPython(systemProperties)); diff --git a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/services/ScriptsService.java b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/services/ScriptsService.java index b3ad05e51d..cc82a8d75d 100644 --- a/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/services/ScriptsService.java +++ b/cloudslang-runtime/src/main/java/io/cloudslang/lang/runtime/services/ScriptsService.java @@ -45,7 +45,8 @@ public void init() throws IOException { ScriptFunction.CS_ROUND, ScriptFunction.CS_SUBSTRING, ScriptFunction.CS_TO_UPPER, - ScriptFunction.CS_TO_LOWER + ScriptFunction.CS_TO_LOWER, + ScriptFunction.GET_SP_VAR ); for (ScriptFunction function: list) { diff --git a/cloudslang-runtime/src/main/resources/scripts/get_sp_var.py b/cloudslang-runtime/src/main/resources/scripts/get_sp_var.py new file mode 100644 index 0000000000..3e6cda5b9c --- /dev/null +++ b/cloudslang-runtime/src/main/resources/scripts/get_sp_var.py @@ -0,0 +1,8 @@ +def get_sp_var(key): + try: + value1 = get_from_smaller_context(key) + except NameError: + value1 = globals().get(key) + accessed(value1) + property_value = sys_prop.get(value1) + return property_value