package sample;

import static util.Utils.readFile;

import java.io.File;
import java.io.StringReader;
import java.util.Properties;

public class Config {

    /**
     * devel | test | prod
     */
    private static String env;

    @SuppressWarnings("unused")
    private static String currentDir;
    private static String projectDir;

    private static Properties props;

    static {
        props = new Properties();
    }

    public static String getEnv() {
        return env;
    }

    public static void setEnv(String env) {
        Config.env = env;
    }

    public static void setCurrentDir(String dir){
        currentDir = dir;
    }
    public static void setProjectDir(String dir){
        projectDir = dir;
    }

    public static void load() {
        String suffix = "";
        if (!env.equals("prod")) {
            suffix = "_" + env;
        }

        String path = projectRelativePath("config" + suffix + ".properties");
        String propsSrc = readFile(path);
        try (StringReader sr = new StringReader(propsSrc)) {
            props.load(sr);
        } catch (Throwable t) {
            throw new RuntimeException(t);
        }
    }

    public static String prop(String key){
        return props.getProperty(key);
    }

    /**
     * @param tail
     * @return project dir + tail (full path)
     */
    public static String projectRelativePath(String tail){
        try {
            return new File(projectDir, tail).getCanonicalPath();
        } catch (Throwable t) {
            throw new RuntimeException(t);
        }
    }
}

@@ -113,26 +113,171 @@
 va.util.
-Properties
+ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.Properties;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern
 ;%0A%0Apubli
@@ -776,28 +776,74 @@
 currentDir =
+ normalizePath(System.getProperty(%22os.name%22),
  dir
+)
 ;%0A    %7D%0A    
@@ -913,12 +913,970 @@
 r = 
-dir;
+normalizePath(System.getProperty(%22os.name%22), dir);%0A    %7D%0A%0A    /**%0A     * %22/c/path/to/...%22 =%3E %22C:/path/to/...%22%0A     */%0A    private static String normalizePath(String osName, String path) %7B%0A        if (osName.toLowerCase().startsWith(%22windows%22)) %7B%0A            List%3CString%3E m = re_match(%22%5E/(%5Ba-zA-Z%5D)/%22, path);%0A            if (m.isEmpty()) %7B%0A                return path;%0A            %7D else %7B%0A                return m.get(1).toUpperCase() + %22:%22 + path.substring(2);%0A            %7D%0A        %7D else %7B%0A            return path;%0A        %7D%0A    %7D%0A%0A    private static List%3CString%3E re_match(String restr, String target) %7B%0A        Pattern p = Pattern.compile(restr);%0A        Matcher m = p.matcher(target);%0A        if (m.find()) %7B%0A            List%3CString%3E ss = new ArrayList%3C%3E();%0A            for (int i = 0; i %3C= m.groupCount(); i++) %7B%0A                ss.add(m.group(i));%0A            %7D%0A            return ss;%0A        %7D else %7B%0A            return Collections.emptyList();%0A        %7D
 %0A   

normalize path for Windows