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:msearch.tool.MSFunktionen.java

public static String getOsString() {
    String os = OS_UNKNOWN_STRING;
    if (System.getProperty("os.name").toLowerCase().contains("windows")) {
        if (System.getenv("ProgramFiles") != null) {
            // win 32Bit
            os = OS_WIN_32BIT_STRING;//  www.ja  va 2s  .c  o m
        } else if (System.getenv("ProgramFiles(x86)") != null) {
            // win 64Bit
            os = OS_WIN_64BIT_STRING;
        }
    } else if (System.getProperty("os.name").toLowerCase().contains("linux")) {
        os = OS_LINUX_STRING;
    } else if (System.getProperty("os.name").toLowerCase().contains("mac")) {
        os = OS_MAC_STRING;
    }
    return os;
}

From source file:eu.optimis.tf.ip.service.utils.PropertiesUtils.java

public static String getConfigFilePath(String configFile) {
    String optimisHome = System.getenv("OPTIMIS_HOME");
    //log.info(optimisHome);
    if (optimisHome == null) {
        if (System.getProperty("file.separator").equalsIgnoreCase("/")) {
            optimisHome = "/opt/optimis";
            log.debug("TRUST: OPTIMIS_HOME: " + optimisHome + " (DEFAULT)");
        } else {//from   w w w. ja  v a2  s  .  c  o  m
            optimisHome = "d:\\opt\\optimis";
            log.debug("TRUST: OPTIMIS_HOME: " + optimisHome + " (DEFAULT)");
        }
    } else {
        log.debug("TRUST: OPTIMIS_HOME: " + optimisHome);
    }

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

    return optimisHome.concat(configFile);
}

From source file:domainregistry.HypertyService.java

public void createUserHyperty(Connection connectionClient, HypertyInstance newHyperty) {
    long expiresLimit = Long.valueOf(System.getenv(EXPIRES)).longValue();
    String userID = newHyperty.getUserID();
    String hypertyID = newHyperty.getHypertyID();

    if (validateExpiresField(newHyperty.getExpires(), expiresLimit)) {
        newHyperty.setExpires((int) expiresLimit);
        log.info("Expires was set to the max value allowed by the Domain Registry: " + expiresLimit);
    }/*from   ww w.j  a  v  a  2  s  . c  o m*/

    if (connectionClient.userExists(userID)) {
        checkHypertyExistence(connectionClient, newHyperty);
        return;
    }

    if (connectionClient.hypertyExists(hypertyID))
        throw new CouldNotCreateOrUpdateHypertyException();

    else
        newHyperty(connectionClient, newHyperty);
}

From source file:org.greencheek.utils.environment.propertyplaceholder.spring.TestEnvironmentalPropertySourcesPlaceholderConfigurerViaCompositeBuilderInXml.java

@Test
public void testPropertyResolved() {
    System.setProperty("ENVIRONMENT", "dev");
    System.setProperty("ENV", "dev");
    ctx = new ClassPathXmlApplicationContext(
            new String[] { "classpath:SpringPropertySourcesPlaceholderConfigurer-composite-config.xml" });

    String value = (String) ctx.getBean("string");
    String valueSys = (String) ctx.getBean("string-sys");
    String valueEnv = (String) ctx.getBean("string-env");

    String valuePath = (String) ctx.getBean("string-path");

    assertEquals("devproperties", value);

    assertEquals("dev", valueSys);
    assertEquals(System.getenv("PATH"), valueEnv);

    assertEquals(System.getenv("PATH"), valuePath);
}

From source file:io.stallion.asyncTasks.AsyncTaskDbPersister.java

public AsyncTask findAndLockNextTask(Long now, int depth) {
    // Stop recursion at ten queries
    if (depth > 10) {
        return null;
    }/*  w  w  w  . jav  a 2  s .  co m*/
    String localMode = "";
    if (Settings.instance().getLocalMode()) {
        localMode = or(System.getenv("USER"), GeneralUtils.slugify(Settings.instance().getTargetFolder()));
    }
    // Do not execute tasks that are more than 2 days stale
    Long minTime = now - 86400 * 2 * 1000;
    AsyncTask task = DB.instance().queryForOne(AsyncTask.class,
            "SELECT * FROM stallion_async_tasks WHERE lockUuid='' AND executeAt<=? AND executeAt>? AND "
                    + " completedAt=0 AND localMode=? ORDER BY executeAt ASC",
            now, minTime, localMode);

    if (task == null) {
        return null;
    }
    String lockUuid = UUID.randomUUID().toString();
    Long lockedAt = mils();
    int affected = DB.instance().execute(
            "UPDATE stallion_async_tasks SET lockedAt=?, lockUuid=? WHERE lockUuid='' AND id=?", lockedAt,
            lockUuid, task.getId());
    if (affected == 0) {
        // This will happen if another thread or process locks the row in between the SELECT and the UPDATE.
        // If this happens, we just run the whole method again to get another row.
        // We could have done a SELECT FOR UPDATE, but we want to minimize locking. So better to do optimisic
        // locking rather than overly lock and create problems for MySQL
        return findAndLockNextTask(now, depth + 1);
    } else {
        task.setLockedAt(lockedAt);
        task.setLockUuid(lockUuid);
        return task;
    }
}

From source file:com.spectralogic.ds3cli.ClientFactory.java

private static String getProxy(final Arguments arguments) {
    String proxyValue = arguments.getOptionValue(PROXY.getOpt());
    if (Guard.isStringNullOrEmpty(proxyValue)) {
        proxyValue = System.getenv("http_proxy");
    }/*from  w  w  w .  j av a2 s. c o  m*/
    return proxyValue;
}

From source file:org.greencheek.utils.environment.propertyplaceholder.spring.TestEnvironmentalPropertyPlaceholderConfigurerViaCompositeBuilderInXml.java

@Test
public void testPropertyResolved() {
    System.setProperty("ENVIRONMENT", "dev");
    System.setProperty("ENV", "dev");
    ctx = new ClassPathXmlApplicationContext(new String[] {
            "classpath:SpringPropertyPlaceholderConfigurer-composite-config-withstringlocations.xml" });

    String value = (String) ctx.getBean("string");
    String valueSys = (String) ctx.getBean("string-sys");
    String valueEnv = (String) ctx.getBean("string-env");

    String valuePath = (String) ctx.getBean("string-path");

    assertEquals("devproperties", value);

    assertEquals("dev", valueSys);
    assertEquals(System.getenv("PATH"), valueEnv);

    assertEquals(System.getenv("PATH"), valuePath);
}

From source file:de.bstreit.java.oscr.business.staff.SimpleUserService.java

private void loadCurrentUser() {
    final String loginName = System.getenv("USER");

    if (StringUtils.isBlank(loginName)) {
        return;//from   ww  w .j  a v a2s . com
    }

    currentUser = userRepository.findByLoginname(loginName);

    if (currentUser == null) {
        currentUser = userRepository.save(new User(loginName, loginName));
    }
}

From source file:com.nebhale.cyclinglibrary.repository.RepositoryConfiguration.java

@Bean
DataSource dataSource() throws URISyntaxException {
    String dbUrlProperty = System.getenv(DB_URL_PROPERTY_NAME);
    Assert.hasText(dbUrlProperty,// w w w  . j  ava2 s.  c  om
            String.format("The enviroment variable '%s' must be specified", DB_URL_PROPERTY_NAME));

    URI dbUri = new URI(dbUrlProperty);

    String username = dbUri.getUserInfo().split(":")[0];
    String password = dbUri.getUserInfo().split(":")[1];
    String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath()
            + "?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory";

    BoneCPDataSource dataSource = new BoneCPDataSource();
    dataSource.setDriverClass(Driver.class.getCanonicalName());
    dataSource.setJdbcUrl(dbUrl);
    dataSource.setUsername(username);
    dataSource.setPassword(password);

    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource);
    flyway.migrate();

    return dataSource;
}

From source file:org.jenkinsci.plugins.fabric8.support.RestClient.java

public static HttpHost getHost(TaskListener listener, String name, String protocol)
        throws UnknownHostException {
    String envPrefix = name.toUpperCase().replace('-', '_');
    String envHost = envPrefix + "_SERVICE_HOST";
    String envPort = envPrefix + "_SERVICE_PORT";
    String host = System.getenv(envHost);
    String portText = System.getenv(envPort);
    if (host == null || portText == null) {
        log(listener, "No service " + name + "  is running!!!");
        return null;
    }//from w w  w  .  j  a v a2s. c om
    int portNumber = Integer.parseInt(portText);
    return new HttpHost(host, portNumber, protocol);
}