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.ansorgit.plugins.bash.BashTestUtils.java

private static String computeBasePath() {
    String configuredDir = StringUtils.stripToNull(System.getenv("BASHSUPPORT_TESTDATA"));
    if (configuredDir != null) {
        File dir = new File(configuredDir);
        if (dir.isDirectory() && dir.exists()) {
            return dir.getAbsolutePath();
        }// w w  w. j a  v a2 s  .c  om
    }

    //try to find out from the current classloader
    URL url = BashTestUtils.class.getClassLoader().getResource("log4j.xml");
    if (url != null) {
        try {
            File resourceFile = new File(url.toURI());
            //we need to cut the out dir and the other resource paths
            File basePath = resourceFile.getParentFile().getParentFile().getParentFile().getParentFile();
            if (basePath != null && basePath.isDirectory()) {
                return basePath + File.separator + "testData";
            }
        } catch (Exception e) {
            //ignore, use fallback below
        }
    }

    return null;
}

From source file:org.zalando.stups.tokens.FileSupplier.java

private static File getCredentialsDir() {
    String dir = System.getenv("CREDENTIALS_DIR");
    if (dir == null) {

        // this for testing
        dir = System.getProperty("CREDENTIALS_DIR");
        if (dir == null) {
            throw new IllegalStateException("environment variable CREDENTIALS_DIR not set");
        }//ww w.  j a v a  2 s  . c o m
    }

    return new File(dir);
}

From source file:net.chris54721.infinitycubed.utils.Utils.java

public static File getAppdataPath() {
    if (SystemUtils.IS_OS_WINDOWS)
        return new File(System.getenv("APPDATA"));
    if (SystemUtils.IS_OS_MAC_OSX)
        return new File(System.getProperty("user.home") + "/Library/Application Support");
    if (SystemUtils.IS_OS_LINUX)
        return new File(System.getProperty("user.home"));
    return new File(System.getProperty("user.home"));
}

From source file:kirchnerei.glatteis.webapp.WebappSetup.java

/**
 * returns the value of either system env or system properties
 * @throws CompositeException if there is no value, then an exception will be thrown
 *//*from  w  ww.j  a v a 2  s.  c o  m*/
public static String getParam(String name) {
    String value = System.getenv(name);
    if (value == null) {
        value = System.getProperty(name);
    }
    if (value == null) {
        throw new CompositeException("parameter '%s' is not present in system env or system properties", name);
    }
    return value;
}

From source file:ezbake.common.openshift.OpenShiftUtil.java

public static String getRepoDir() {
    return Preconditions.checkNotNull(System.getenv(OPENSHIFT_REPO_DIR));
}

From source file:com.messagehub.samples.bluemix.BluemixEnvironment.java

/**
 * Check whether the code is executing in a Bluemix Java Buildpack
 *///  w  w w  . java 2  s  .co  m
public static boolean isRunningInBluemix() {
    String userDir = System.getProperty("user.dir");
    File buildpack = new File(userDir + File.separator + ".java-buildpack");
    String vcapServices = System.getenv("VCAP_SERVICES");

    if (buildpack.exists() && (vcapServices == null)) {
        throw new IllegalStateException("ASSERTION FAILED: buildpack.exists() but VCAP_SERVICES==null");
    }

    return buildpack.exists();
}

From source file:Connector.AlchemyConnector.java

public void getConnection() {

    try {//from   ww w  . java  2s. c  om
        String envServices = System.getenv("VCAP_SERVICES");

        JSONParser parser = new JSONParser();
        Object obj = parser.parse(envServices);
        JSONObject jsonObject = (JSONObject) obj;
        JSONArray vcapArray = (JSONArray) jsonObject.get("alchemy_api");
        JSONObject vcap = (JSONObject) vcapArray.get(0);
        JSONObject credentials = (JSONObject) vcap.get("credentials");
        apiKey = credentials.get("apikey").toString();

    } catch (ParseException ex) {
    }
}

From source file:com.exalttech.trex.stateful.utilities.FileManager.java

/**
 * Return local file path//from  ww  w .ja v a 2 s. c  o m
 *
 * @return
 */
public static String getLocalFilePath() {
    String path = System.getProperty("user.home");
    if (Util.isWindows()) {
        if (!Util.isNullOrEmpty(System.getenv("LOCALAPPDATA"))) {
            path = System.getenv("LOCALAPPDATA");
        }
    }
    return path + APP_DATA_PATH;
}

From source file:app.config.DatabaseConfig.java

@Bean
public BasicDataSource dataSource() throws URISyntaxException {
    String dbUrl = System.getenv("JDBC_DATABASE_URL");
    String username = System.getenv("JDBC_DATABASE_USERNAME");
    String password = System.getenv("JDBC_DATABASE_PASSWORD");

    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setUrl(dbUrl);/*from   w ww.ja  va 2 s .  com*/
    basicDataSource.setUsername(username);
    basicDataSource.setPassword(password);

    return basicDataSource;
}

From source file:f1db.configuration.ProductionProfile.java

@Bean
public BasicDataSource dataSource() throws URISyntaxException {
    URI dbUri = new URI(System.getenv("DATABASE_URL"));
    String username = dbUri.getUserInfo().split(":")[0];
    String password = dbUri.getUserInfo().split(":")[1];
    String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath();
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setUrl(dbUrl);//from  w  w w  .  j a va 2s.  c  o m
    basicDataSource.setUsername(username);
    basicDataSource.setPassword(password);
    return basicDataSource;
}