I have the below code, I want to transform it fully to groovy, so far what I came up with is shown below
def homeDir="INFA_HOME"
HashMap<String,String> params = IntermediateResults.get("userparams")
Map env=AppContext.get(AppCtxProperties.environmentVariables)
//checking if INFA_HOME is present in the map or not, I will be using INFA_HOME a lot, so can't I use homeDir istead??
boolean homeVarPresent=env.get("INFA_HOME")!=null
csm.pmserver(){
pmserver_homevar(name:"$homeDir",set:"${homeVarPresent?'Y':'N'}",value:"${homeVarPresent?env.get('INFA_HOME'):na}")
//Instead of $env.INFA_HOME can't i use homeDir?
pmserver_home(value:"$env.INFA_HOME/server/bin",exists:"${homeVarPresent?'Y':'N'}")
}
I think @tim_yates example is OK, but it over-complicates the map access and ternary operators. I’d probably do this:
It’s a lot more readable to use the array access modifier with variables that to create several unnecessary GStrings. I might also be tempted to use a manual string concatenation for the path (
env[homeDir] + '/server/bin'), but that’s personal preference.