in azure-sfmesh-maven-plugin/src/main/java/com/microsoft/azure/maven/servicefabric/AddServiceMojo.java [169:205]
public String addEnvironmentVariables(Log logger, String content,
String environmentVariables) throws MojoFailureException{
final String[] env = environmentVariables.split(",");
final ArrayList<Map<String, Object>> envVar = new ArrayList<Map<String, Object>>();
for (int i = 0; i < env.length; i++){
final String[] kvp = env[i].split(":");
final Map<String, Object> kvpMap = new LinkedHashMap<String, Object>();
kvpMap.put("name", kvp[0]);
kvpMap.put("value", kvp[1]);
envVar.add(kvpMap);
}
final Map<String, Object> map = Utils.stringToYaml(logger, content);
final Map<String, Object> application = (Map<String, Object>) map.get("application");
final Map<String, Object> applicationProperties =
(Map<String, Object>) application.get("properties");
final ArrayList<Map<String, Object>> services =
(ArrayList<Map<String, Object>>) applicationProperties.get("services");
final Map<String, Object> service = services.get(0);
final Map<String, Object> serviceProperties =
(Map<String, Object>) service.get("properties");
final ArrayList<Map<String, Object>> codePackages =
(ArrayList<Map<String, Object>>) serviceProperties.get("codePackages");
final Map<String, Object> codePackage = codePackages.get(0);
// TODO: Understand the reason why we need to remove instead of replace
codePackage.put("environmentVariables", envVar);
codePackages.remove(0);
codePackages.add(codePackage);
serviceProperties.replace("codePackages", codePackages);
service.replace("properties", serviceProperties);
services.remove(0);
services.add(0, service);
applicationProperties.replace("properties", services);
application.replace("application", applicationProperties);
map.replace("application", application);
return Utils.yamlToString(map);
}