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.yn.keygen.DefaultKeyGenerator.java

public static void initWorkerId() {
    String workerId = System.getProperty(WORKER_ID_PROPERTY_KEY);
    if (StringUtils.isNotBlank(workerId)) {
        setWorkerId(Long.valueOf(workerId));
        return;// ww  w .j  av  a2  s  .c  o m
    }
    workerId = System.getenv(WORKER_ID_ENV_KEY);
    if (StringUtils.isBlank(workerId)) {
        return;
    }
    setWorkerId(Long.valueOf(workerId));
}

From source file:GitHubApiTest.java

/**
 * It's not possible to store username/password in the test file,
 * this cretentials are stored in a properties file
 * under user home directory./*from ww w  .  ja v a2  s.com*/
 *
 * This method would be used to fetch parameters for the test
 * and allow to avoid committing createntials with source file.
 * @return username, repo, password
 */
@NotNull
public static Properties readGitHubAccount() {
    File propsFile = new File(System.getenv("USERPROFILE"), ".github.test.account");
    System.out.println("Loading properites from: " + propsFile);
    try {
        if (!propsFile.exists()) {
            FileUtil.createParentDirs(propsFile);
            Properties ps = new Properties();
            ps.setProperty(URL, "https://api.github.com");
            ps.setProperty(USERNAME, "jonnyzzz");
            ps.setProperty(REPOSITORY, "TeamCity.GitHub");
            ps.setProperty(PASSWORD_REV, rewind("some-password-written-end-to-front"));
            PropertiesUtil.storeProperties(ps, propsFile, "mock properties");
            return ps;
        } else {
            return PropertiesUtil.loadProperties(propsFile);
        }
    } catch (IOException e) {
        throw new RuntimeException("Could not read Amazon Access properties: " + e.getMessage(), e);
    }
}

From source file:com.github.gcauchis.scalablepress4j.test.PropertyTestConfiguration.java

@Bean
public PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() throws IOException {
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    encryptor.setPassword(System.getenv("PROPERTIES_PASSPHRASE"));
    final EncryptablePropertyPlaceholderConfigurer ppc = new EncryptablePropertyPlaceholderConfigurer(
            encryptor);/*w  ww.  j av  a2 s . c o  m*/
    ppc.setLocations(ArrayUtils.addAll(
            new PathMatchingResourcePatternResolver().getResources("classpath*:application.properties")));
    return ppc;
}

From source file:atg.tools.dynunit.DynUnit.java

public static String getHome() {
    logger.entry();//from www  . j av  a 2s .c om
    String dynUnitHome = PropertiesUtil.getSystemProperty(DYNUNIT_HOME_PROPERTY);
    if (StringUtils.isEmpty(dynUnitHome)) {
        dynUnitHome = System.getenv("DYNUNIT_HOME");
        if (StringUtils.isEmpty(dynUnitHome)) {
            logger.error("Can't find DynUnit home directory. Please set the {} property.",
                    DYNUNIT_HOME_PROPERTY);
        }
    }
    return logger.exit(StringUtils.defaultString(dynUnitHome));
}

From source file:org.zlogic.vogon.web.PersistenceConfiguration.java

/**
 * Returns the path to the H2 database/*w  w  w .ja v a  2 s .  co  m*/
 *
 * @return the path to the H2 database
 */
protected String getH2DatabasePath() {
    if (serverTypeDetector.getCloudType() == ServerTypeDetector.CloudType.OPENSHIFT)
        return System.getenv("OPENSHIFT_DATA_DIR"); //NOI18N
    if (System.getenv("VOGON_DATABASE_DIR") != null) //NOI18N
        return System.getenv("VOGON_DATABASE_DIR"); //NOI18N
    if (System.getProperty("vogon.database.dir") != null) //NOI18N
        return System.getProperty("vogon.database.dir"); //NOI18N
    if (null != serverTypeDetector.getServerType())
        switch (serverTypeDetector.getServerType()) {
        case TOMCAT:
            return System.getProperty("catalina.home"); //NOI18N
        case WILDFLY:
            return System.getProperty("jboss.server.data.dir"); //NOI18N
        case JETTY:
            return System.getProperty("jetty.base"); //NOI18N
        }
    return System.getProperty("user.dir"); //NOI18N 
}

From source file:com.gopivotal.cla.EnvironmentVariableConfiguration.java

private String getRequiredProperty(String key) {
    String property = System.getenv(key);
    Assert.hasText(property, String.format("The enviroment variable '%s' must be specified", key));
    return property;
}

From source file:com.celamanzi.liferay.portlets.rails286.Rails286PortletFunctions.java

/**
 * The getTempPath method will search for LIFERAY_PORTAL_TEMP variable on environment,
 * if the method not find our variable the catalina.base property will be used. The last attempt is
 * the path '../temp' that will work if you have started the server inside the bin folder.
 *///from  w w  w  . ja v a  2  s  . c  o  m
public static String getTempPath() {
    if (tempPath != null) {
        log.debug("TempPath: " + tempPath);
        return tempPath;
    }

    tempPath = System.getenv("LIFERAY_PORTAL_TEMP");
    if (tempPath != null && tempPath.length() > 0) {
        tempPath = tempPath.replaceAll("/\\Z", "");
        log.info("Using LIFERAY_PORTAL_TEMP variable for tempPath, defined path: " + tempPath);
        return tempPath;
    }

    // In case of catalina (tomcat)
    try {
        String catalinaDir = PropsUtil.get("catalina.base");
        if (catalinaDir != null && catalinaDir.length() > 0) {
            catalinaDir = catalinaDir.replaceAll("/\\Z", "");
            tempPath = catalinaDir + "/temp";
            log.info("Using catalina.base for tempPath, defined path: " + tempPath);
            return tempPath;
        }
    } catch (Exception e) {
        log.error(e.getMessage());
    }

    // default one
    // XXX: maybe use /tmp ?
    tempPath = "../temp";
    log.info("Using '../temp' as tempPath, this is a not very good aproach. Be aware");
    return tempPath;
}

From source file:io.vitess.client.TestEnv.java

/**
 * Get setup command to launch a cluster.
 *//* w  w w  .  j av  a  2  s  .co m*/
public List<String> getSetupCommand(int port) {
    String vtTop = System.getenv("VTTOP");
    if (vtTop == null) {
        throw new RuntimeException("cannot find env variable: VTTOP");
    }
    String schemaDir = getTestDataPath() + "/schema";
    List<String> command = new ArrayList<String>();
    command.add(vtTop + "/py/vttest/run_local_database.py");
    command.add("--port");
    command.add(Integer.toString(port));
    command.add("--proto_topo");
    command.add(getTopology().toString());
    command.add("--schema_dir");
    command.add(schemaDir);
    return command;
}

From source file:de.teamgrit.grit.checking.compile.HaskellCompileChecker.java

/**
 * The constructor for the compileChecker only checks if ghci can be found
 * in PATH on windows systems./*www  . j a  v a2s  .c o m*/
 * 
 */
public HaskellCompileChecker() {
    if (!System.getenv("PATH").contains("ghci") && ("Windows".equals(System.getProperty("os.name")))) {
        LOGGER.severe("No ghci in path. This is required on Windows." + "Please append the path to ghci"
                + " to your system PATH variable.");
    }
}

From source file:org.usergrid.clustering.hazelcast.HazelcastTest.java

@Before
public void setup() throws Exception {
    // assertNotNull(client);

    String maven_opts = System.getenv("MAVEN_OPTS");
    logger.info("Maven options: " + maven_opts);

    String[] locations = { "testApplicationContext.xml" };
    ac = new ClassPathXmlApplicationContext(locations);

    AutowireCapableBeanFactory acbf = ac.getAutowireCapableBeanFactory();
    acbf.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
    acbf.initializeBean(this, "testClient");

}