/** * Adds a map of key, value environment variables to the default process environment * * @param envVariables * environment variables. Value might be null. * * @throws IllegalArgumentException */ public CommandTool addEnvironment(Map<? extends CharSequence, ? extends CharSequence> envVariables) throws IllegalArgumentException { Validate.notNull(envVariables, "Environment variables must not be null"); for (Map.Entry<? extends CharSequence, ? extends CharSequence> entry : envVariables.entrySet()) { Validate.notNull(entry.getKey(), "Environment variable name must not be null nor empty"); CharSequence value = entry.getValue(); environment.put(entry.getKey().toString(), value != null ? value.toString() : null); } return this; }
/** * Adds a sequence of key, value environment variables to the default process environment * * @param envVariables * environment variables. Value might be null. * * @throws IllegalArgumentException * If values do not form complete pairs or if key is null */ public CommandTool addEnvironment(CharSequence... envVariables) throws IllegalArgumentException { if (envVariables.length % 2 == 1) { throw new IllegalArgumentException("Environment variables must be a sequence of key, value pairs."); } for (int i = 0; i < (envVariables.length / 2); i += 2) { CharSequence key = envVariables[i]; CharSequence value = envVariables[i + 1]; Validate.notNull(key, "Environment variable name must not be null nor empty"); environment.put(key.toString(), value != null ? value.toString() : null); } return this; }