/*
 * Script for setting an OS environment variable on Windows.
 * This can be called within the wrapped application to set environment variables
 *
 * Arguments: 
 * - none
 * 
 * Example Configuration:
 * 
 * wrapper.app.pre.script = setenv.gv
 * 
 * to define the variables and their values edit the vars map in the script
 * note: System.getenv() will not return values set by this script. This script is invoked after the java launcher initialized the environment properties.
 */

import com.sun.jna.Native;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

// set the variables in the following map
def vars = ['testvar1':'testval1', 'testvar2':'testval2']

logger.info "setting environment variables"


public interface Kernel32 extends StdCallLibrary 
{
	Kernel32 INSTANCE = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class, W32APIOptions.UNICODE_OPTIONS);

	boolean SetEnvironmentVariable(String lpName, String lpValue);
}

vars.each
{
	var = it.key
	value = it.value
	println "setting $var = $value"
	Kernel32.INSTANCE.SetEnvironmentVariable(var, value)
}

logger.info "done setting environment variables"

