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

cucumber.runtime.Env Maven / Gradle / Ivy

package cucumber.runtime;

import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;

/**
 * Looks up values in the following order:
 * 
    *
  1. Environment variable
  2. *
  3. System property
  4. *
  5. Resource bundle
  6. *
*/ public class Env { private final String bundleName; private final Properties properties; public Env() { this(null, System.getProperties()); } public Env(String bundleName) { this(bundleName, System.getProperties()); } public Env(Properties properties) { this(null, properties); } public Env(String bundleName, Properties properties) { this.bundleName = bundleName; this.properties = properties; } public String get(String key) { String value = System.getenv(asEnvKey(key)); if (value == null) { value = properties.getProperty(key); if (value == null && bundleName != null) { try { value = ResourceBundle.getBundle(bundleName).getString(key); } catch (MissingResourceException ignore) { } } } return value; } public String get(String key, String defaultValue) { String result = get(key); return result != null ? result : defaultValue; } private static String asEnvKey(String key) { return key.replace('.', '_').toUpperCase(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy