<commit_before>package au.com.onegeek.sbtdotenv;

import java.util.Map;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;

/**
 * Change the actual program environment so that changes propagate to child processes
 *
 * Taken from: http://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java/7201825#7201825
 *
 * Created by mfellows on 20/07/2014.
 */

public abstract class NativeEnvironmentManager {
    public abstract void setEnv(String key, String value);

    public static class EnvironmentException extends RuntimeException {
        EnvironmentException(String key) {
            super("Failed to set environment variable: " + key);
        }
    }

    static class WindowsNativeEnvironmentManagerImpl extends NativeEnvironmentManager {
        public static interface WindowsEnvironmentLibC extends Library {
            WindowsEnvironmentLibC INSTANCE = (
                (WindowsEnvironmentLibC)Native.loadLibrary("msvcrt",
                    WindowsEnvironmentLibC.class)
            );

            int _putenv(String name);
        }

        private WindowsEnvironmentLibC libc = WindowsEnvironmentLibC.INSTANCE;

        @Override
        public void setEnv(String name, String value) {
            String s = name + "=";
            if(value != null)
                name += value;

            if(libc._putenv(s) != 0)
                throw new EnvironmentException(name);
        }
    }

    static class PosixNativeEnvironmentManagerImpl extends NativeEnvironmentManager {
        public static interface PosixEnvironmentLibC extends Library {
            PosixEnvironmentLibC INSTANCE = (
                (PosixEnvironmentLibC) Native.loadLibrary("c",
                    PosixEnvironmentLibC.class)
            );

            int setenv(String name, String value, int overwrite);
            int unsetenv(String name);<commit_msg>Append value to `s` not `name`<commit_after>package au.com.onegeek.sbtdotenv;

import java.util.Map;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;

/**
 * Change the actual program environment so that changes propagate to child processes
 *
 * Taken from: http://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java/7201825#7201825
 *
 * Created by mfellows on 20/07/2014.
 */

public abstract class NativeEnvironmentManager {
    public abstract void setEnv(String key, String value);

    public static class EnvironmentException extends RuntimeException {
        EnvironmentException(String key) {
            super("Failed to set environment variable: " + key);
        }
    }

    static class WindowsNativeEnvironmentManagerImpl extends NativeEnvironmentManager {
        public static interface WindowsEnvironmentLibC extends Library {
            WindowsEnvironmentLibC INSTANCE = (
                (WindowsEnvironmentLibC)Native.loadLibrary("msvcrt",
                    WindowsEnvironmentLibC.class)
            );

            int _putenv(String name);
        }

        private WindowsEnvironmentLibC libc = WindowsEnvironmentLibC.INSTANCE;

        @Override
        public void setEnv(String name, String value) {
            String s = name + "=";
            if(value != null)
                s += value;

            if(libc._putenv(s) != 0)
                throw new EnvironmentException(name);
        }
    }

    static class PosixNativeEnvironmentManagerImpl extends NativeEnvironmentManager {
        public static interface PosixEnvironmentLibC extends Library {
            PosixEnvironmentLibC INSTANCE = (
                (PosixEnvironmentLibC) Native.loadLibrary("c",
                    PosixEnvironmentLibC.class)
            );

            int setenv(String name, String value, int overwrite);
            int unsetenv(String name);
{'fraction_non_alphanumeric': 0.0763239875389408, 'fraction_numerical': 0.015057113187954309, 'mean_word_length': 2.5155109489051095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '418989', 'n_tokens_mistral': 1018, 'n_tokens_neox': 941, 'n_words': 248}