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:fi.hsl.parkandride.ActiveProfileAppender.java

private Set<String> currentActiveProfiles() {
    String springProfilesActive = System.getProperty("spring.profiles.active");
    if (isNullOrEmpty(springProfilesActive)) {
        springProfilesActive = System.getenv("SPRING_PROFILES_ACTIVE");
    }/*from w  w  w .  java 2s.c  om*/

    Set<String> profiles = new LinkedHashSet<>();
    if (!isNullOrEmpty(springProfilesActive)) {
        profiles.addAll(asList(springProfilesActive.split(",")));
    }
    return profiles;
}

From source file:com.sillelien.dollar.test.CircleCiParallelRule.java

@Override
public Statement apply(Statement statement, @NotNull Description description) {

    boolean runTest = true;

    final String tName = description.getClassName() + "#" + description.getMethodName();

    final String numNodes = System.getenv("CIRCLE_NODE_TOTAL");
    final String curNode = System.getenv("CIRCLE_NODE_INDEX");

    if (StringUtils.isBlank(numNodes) || StringUtils.isBlank(curNode)) {
        System.out.println("Running locally, so skipping");
    } else {/*from ww  w . j  a v a 2s .  co m*/
        final int hashCode = Math.abs(tName.hashCode());

        int nodeToRunOn = hashCode % Integer.parseInt(numNodes);
        final int curNodeInt = Integer.parseInt(curNode);

        runTest = nodeToRunOn == curNodeInt;

        System.out.println(
                "currentNode: " + curNodeInt + ", targetNode: " + nodeToRunOn + ", runTest: " + runTest);

        if (!runTest) {
            return new Statement() {
                @Override
                public void evaluate() {
                    Assume.assumeTrue("Skipping test, currentNode: " + curNode + ", targetNode: " + nodeToRunOn,
                            false);
                }
            };
        }
    }

    return statement;
}

From source file:ai.grakn.graql.internal.shell.animalia.chordata.mammalia.artiodactyla.hippopotamidae.HippopotamusFactory.java

/**
 * Raise population of hippopotamus amphibius within console.
 * @param console/*from  w  ww.  j  ava2s .  c  om*/
 */
public static void increasePop(ConsoleReader console) {
    HippopotamusFactory builder = HippopotamusFactory.builder();

    if (System.getenv("HIPPO_SIZE") != null) {
        int hippoSize = Integer.parseInt(System.getenv("HIPPO_SIZE"));
        builder.size(hippoSize);
    }

    Hippopotamus hippo = builder.build();

    try {
        for (double i = 0; i < Math.PI; i += 0.1) {
            console.println(hippo.toString().replaceAll("^|\n",
                    "\n" + StringUtils.repeat(" ", (int) (Math.sin(i) * 100))));
            console.flush();
            Thread.sleep(100);
        }
    } catch (IOException | InterruptedException e) {
        System.err.println("Supercalafrajilistichippopotamusexception");
    }

    hippo.submerge();

    console.setPrompt(hippo.toString());
}

From source file:com.spotify.helios.serviceregistration.skydns.MiniEtcdClientITCase.java

@Test
public void test() throws Exception {
    String etcdServer = System.getenv("ETCD_SERVER");
    if (isNullOrEmpty(etcdServer)) {
        etcdServer = "http://localhost:4001";
    }/*  w  w w .  j  a va 2  s. c  o  m*/
    final MiniEtcdClient client = new MiniEtcdClient(etcdServer + "/v2/keys/", 10000, 10000, 10000);
    final String data = "DATA!";
    final String key = "KEY";
    client.set(key, data, null).get();

    final HttpResponse getResult = client.get(key).get();
    final EtcdResponse etc = client.getEtcdInfoFromResponse(getResult);
    assertEquals(data, etc.getNode().getValue());

    final HttpResponse delResult = client.delete(key).get();
    final StatusLine statusLine = delResult.getStatusLine();
    assertEquals(200, statusLine.getStatusCode());

    final HttpResponse postDelResult = client.get(key).get();
    final StatusLine postDelStatusLine = postDelResult.getStatusLine();
    assertEquals(404, postDelStatusLine.getStatusCode());

    client.close();
}

From source file:org.springdata.ehcache.config.java.JavaConfig.java

@Override
public String terracottaLicenseFile() {
    return System.getenv("TERRACOTTA_LICENSE_KEY");
}

From source file:com.nike.vault.client.auth.EnvironmentVaultCredentialsProvider.java

/**
 * Attempts to acquire credentials from an environment variable.
 *
 * @return credentials/*from   ww w.  j av  a2 s.  co  m*/
 */
@Override
public VaultCredentials getCredentials() {
    final String token = System.getenv(VAULT_TOKEN_ENV_PROPERTY);

    if (StringUtils.isNotBlank(token)) {
        return new TokenVaultCredentials(token);
    }

    throw new VaultClientException("Vault token not found in the environment property.");
}

From source file:com.r573.enfili.common.resource.cloud.aws.s3.S3Manager.java

public static void initFromEnv(String keyAccessKey, String keySecretKey, String downloadDir, String tag) {
    String awsAccessKey = System.getenv(keyAccessKey);
    String awsSecretKey = System.getenv(keySecretKey);
    if ((awsAccessKey == null) || (awsAccessKey.isEmpty())) {
        throw new IllegalStateException("AWS_ACCESS_KEY environment variable not defined");
    }/*from  w  w w . jav a2  s  . c  o  m*/
    if ((awsSecretKey == null) || (awsSecretKey.isEmpty())) {
        throw new IllegalStateException("AWS_SECRET_KEY environment variable not defined");
    }

    initWithCredentials(awsAccessKey, awsSecretKey, downloadDir, tag);
}

From source file:com.cloudera.sqoop.manager.NetezzaTestUtils.java

public static String getNZPassword() {
    String nzPass = System.getenv("NZ_PASSWORD");
    if (nzPass == null) {
        nzPass = NZ_DB_PASSWORD;/*  w  ww. j  a  va2  s  . com*/
    }
    return nzPass;
}

From source file:beadsan.AppConfig.java

@ConfigurationProperties("spring.datasource")
@Bean(destroyMethod = "close")
DataSource realDataSource() throws URISyntaxException {
    String url;//from   ww  w  . java  2  s . c  om
    String username;
    String password;

    String databaseUrl = System.getenv("DATABASE_URL");
    if (databaseUrl != null) {
        URI dbUri = new URI(databaseUrl);
        url = "jdbc:postgresql://" + dbUri.getHost() + ":" + dbUri.getPort() + dbUri.getPath();
        username = dbUri.getUserInfo().split(":")[0];
        password = dbUri.getUserInfo().split(":")[1];
    } else {
        url = this.properties.getUrl();
        username = this.properties.getUsername();
        password = this.properties.getPassword();
    }

    DataSourceBuilder factory = DataSourceBuilder.create(this.properties.getClassLoader()).url(url)
            .username(username).password(password);
    this.dataSource = factory.build();
    return this.dataSource;
}

From source file:com.github.dozermapper.core.config.resolvers.SystemEnvironmentSettingsResolver.java

/**
 * Gets value from environment via {@link System#getenv}
 * @param key key to retrieve/* w  ww. ja v a2  s.  com*/
 * @param defaultValue value to default to if none found
 * @return value found or default if none
 */
@Override
public Object get(String key, Object defaultValue) {
    Object value = System.getenv(getEnvironmentSafeKey(key));
    if (value == null) {
        value = defaultValue;
    }

    return value;
}