Example usage for java.lang System getenv

List of usage examples for java.lang System getenv

Introduction

In this page you can find the example usage for java.lang System getenv.

Prototype

public static String getenv(String name) 

Source Link

Document

Gets the value of the specified environment variable.

Usage

From source file:com.gopivotal.cla.web.TestConfiguration.java

@Bean
String databaseUrl() {
    return String.format("postgresql://%s@127.0.0.1:5432/test", System.getenv("USER"));
}

From source file:com.baidu.fsg.uid.utils.DockerUtils.java

/**
 * Retrieve host & port from environment
 *//*ww  w  .  j  a  v a2  s .  c  om*/
private static void retrieveFromEnv() {
    // retrieve host & port from environment
    DOCKER_HOST = System.getenv(ENV_KEY_HOST);
    DOCKER_PORT = System.getenv(ENV_KEY_PORT);

    // not found from 'JPAAS_HTTP_PORT', then try to find from 'JPAAS_HOST_PORT_8080'
    if (StringUtils.isBlank(DOCKER_PORT)) {
        DOCKER_PORT = System.getenv(ENV_KEY_PORT_ORIGINAL);
    }

    boolean hasEnvHost = StringUtils.isNotBlank(DOCKER_HOST);
    boolean hasEnvPort = StringUtils.isNotBlank(DOCKER_PORT);

    // docker can find both host & port from environment
    if (hasEnvHost && hasEnvPort) {
        IS_DOCKER = true;

        // found nothing means not a docker, maybe an actual machine
    } else if (!hasEnvHost && !hasEnvPort) {
        IS_DOCKER = false;

    } else {
        LOGGER.error("Missing host or port from env for Docker. host:{}, port:{}", DOCKER_HOST, DOCKER_PORT);
        throw new RuntimeException(
                "Missing host or port from env for Docker. host:" + DOCKER_HOST + ", port:" + DOCKER_PORT);
    }
}

From source file:org.eclipse.epp.internal.logging.aeri.ui.utils.Proxies.java

/**
 * Returns the domain of the current machine- if any.
 *
 * @param userName//from ww  w . j a  v  a  2s.com
 *            the user name which may be null. On windows it may contain the domain name as prefix "domain\\username".
 */
public static Optional<String> getUserDomain(String userName) {

    // check the app's system properties
    String domain = System.getProperty(PROP_HTTP_AUTH_NTLM_DOMAIN);
    if (domain != null) {
        return of(domain);
    }

    // check the OS environment
    domain = System.getenv(ENV_USERDOMAIN);
    if (domain != null) {
        return of(domain);
    }

    // test the user's name whether it may contain an information about the domain name
    if (StringUtils.contains(userName, DOUBLEBACKSLASH)) {
        return of(substringBefore(userName, DOUBLEBACKSLASH));
    }

    // no domain name found
    return absent();
}

From source file:com.shopzilla.api.client.helper.CredentialFactory.java

public CredentialFactory() {
    String id = StringUtils.isNotBlank(System.getenv("PUBLISHER_ID")) ? System.getenv("PUBLISHER_ID")
            : System.getProperty("PUBLISHER_ID");
    String key = StringUtils.isNotBlank(System.getenv("PUBLISHER_API_KEY")) ? System.getenv("PUBLISHER_API_KEY")
            : System.getProperty("PUBLISHER_API_KEY");

    if (key != null && id != null) {
        this.publisherId = id;
        this.publisherApiKey = key;
    } else {/*from w w  w . j  a v a2  s .c o  m*/
        throw new IllegalArgumentException(
                "No API credentials were provided! " + "Please set PUBLISHER_ID and PUBLISHER_API_KEY ");
    }
}

From source file:io.github.bonigarcia.wdm.Downloader.java

public static Proxy createProxy() {
    String proxyString = System.getenv("HTTPS_PROXY");
    if (proxyString == null || proxyString.length() < 1)
        proxyString = System.getenv("HTTP_PROXY");
    if (proxyString == null || proxyString.length() < 1) {
        return null;
    }/*from   www. j  a v a  2 s.c  o  m*/
    proxyString = proxyString.replace("http://", "");
    proxyString = proxyString.replace("https://", "");
    StringTokenizer st = new StringTokenizer(proxyString, ":");
    if (st.countTokens() != 2)
        return null;
    String host = st.nextToken();
    String portString = st.nextToken();
    try {
        int port = Integer.parseInt(portString);
        return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
    } catch (NumberFormatException e) {
        return null;
    }
}

From source file:org.paxml.util.PaxmlUtils.java

public static File getPaxmlHome(boolean assert_PAXML_HOME) {
    String paxmlHome = System.getenv(PAXML_HOME_ENV_KEY);
    if (paxmlHome == null) {
        paxmlHome = System.getProperty(PAXML_HOME_ENV_KEY);
    }//from  w  ww  . j  a va  2 s.c o  m
    if (paxmlHome == null) {
        if (assert_PAXML_HOME) {
            throw new PaxmlRuntimeException("System environment 'PAXML_HOME' not set!");
        } else {
            return null;
        }
    }
    return new File(paxmlHome);
}

From source file:net.gtl.movieanalytics.data.InfoStore.java

private InfoStore() {
    featureMap = new HashMap<String, FeatureDimension>();
    readJsonFile(System.getenv("INFO_FILE_PATH"));
}

From source file:ch.rasc.wampspring.testsupport.CompletableFutureWebSocketHandler.java

private static int getTimeoutValue() {
    int timeout = 2;
    try {//from   w ww  .  j  a  va2s.co  m
        String timeoutValue = System.getenv("WS_TIMEOUT");
        timeout = Integer.parseInt(timeoutValue);
    } catch (Exception e) {
        // ignore error
    }
    return timeout;
}

From source file:net.emotivecloud.scheduler.drp4one.ConfigManager.java

public static String getConfigFilePath(String configFile) {
    String optimisHome = optimis_Home;
    if (optimisHome == null) {
        optimis_Home = System.getenv(PROJ_HOME_ENV);
        optimisHome = PROJ_HOME_DEFAULT;
        log.warn("Please set environment variable " + PROJ_HOME_ENV + ". Using default " + PROJ_HOME_DEFAULT
                + ".");
    }//from ww  w  .j  a  v a2s .  co  m

    File fileObject = new File(optimisHome + configFile);
    if (!fileObject.exists()) {
        try {
            createDefaultConfigFile(fileObject);
        } catch (Exception ex) {
            log.error("Error reading " + optimisHome.concat(configFile) + " configuration file: "
                    + ex.getMessage());
            log.error(ex.getMessage());
        }
    } else {
        System.out.println("File exists! :" + fileObject.getPath());
    }

    return optimisHome + configFile;
}

From source file:eu.annocultor.common.Utils.java

public static String getLocalOrGlobalEnvironmentVariable(String parameter) throws RuntimeException {
    return (System.getProperty(parameter) == null) ? System.getenv(parameter) : System.getProperty(parameter);
}