All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.appium.utils.ConfigFileManager Maven / Gradle / Ivy

There is a newer version: 14.0.4
Show newest version
package com.appium.utils;


import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Logger;

/**
 * ConfigFileManager - Read config file statically into configFileMap
 */
public class ConfigFileManager {
    public static Map configFileMap = new HashMap();
    private static Properties prop = new Properties();
    private static ConfigFileManager instance;
    private static final Logger LOGGER = Logger.getLogger(ConfigFileManager.class.getSimpleName());

    private ConfigFileManager(String configFile) throws IOException {
        FileInputStream inputStream = new FileInputStream(configFile);
        prop.load(inputStream);
    }

    public static ConfigFileManager getInstance() {
        if (instance == null) {
            String configFile = "config.properties";
            try {
                if (System.getenv().containsKey("CONFIG_FILE")) {
                    configFile = System.getenv().get("CONFIG_FILE");
                    LOGGER.info("Using config file from " + configFile);
                }
                instance = new ConfigFileManager(configFile);
                Enumeration keys = prop.propertyNames();
                while (keys.hasMoreElements()) {
                    String key = (String) keys.nextElement();
                    String value = (null == System.getenv(key))
                            ? prop.getProperty(key) : System.getenv(key);
                    configFileMap.put(key, value);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return instance;
    }

    public String getProperty(String object) {
        return configFileMap.get(object);
    }

    public String getProperty(String key,String value) {
        return configFileMap.getOrDefault(key,value);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy