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:Main.java

/**
 * Lookup a key from the environment./*from   www . j  a v a2s . c om*/
 *
 * @param key the environment variable's key
 * @return value corresponding to key from the OS environment
 */
public static String getEnv(String key) {
    try {
        return System.getenv(key);
    } catch (SecurityException e) {
        return null;
    }
}

From source file:com.splout.db.engine.BaseTest.java

public static Configuration getBaseConfiguration() {
    Configuration conf = new PropertiesConfiguration();
    if (System.getenv("REDIS_HOME") == null) {
        throw new RuntimeException("REDIS_HOME must be defined to run splout-redis unit tests");
    }/*from   w  w  w . j a v  a2  s.c o  m*/
    String redisServerPath = System.getenv("REDIS_HOME") + "/src/redis-server";
    conf.setProperty(RedisManager.REDIS_EXECUTABLE_CONF, redisServerPath);
    return conf;
}

From source file:Main.java

public static boolean isEnvironmentProperlySet() {
    return new File(System.getProperty("user.home") + File.separatorChar + ".eg", "eg.properties").exists()
            || new File(System.getenv("EG_HOME") + File.separatorChar + "config", "eg.properties").exists();
}

From source file:com.ibm.dgaasx.config.EnvironmentInfo.java

public static final DGaaSInfo parseVCAPS() {
    DGaaSInfo info = new DGaaSInfo();

    String vcaps = System.getenv("VCAP_SERVICES");

    if (vcaps == null || vcaps.trim().isEmpty() || "{}".equals(vcaps)) {
        String dgaasURL = SystemUtils.getSystemProperty("DGAAS_URL", null);
        info.setURL(dgaasURL == null || dgaasURL.isEmpty() ? "https://giediprime:9443/dgaas" : dgaasURL);

        log.info("No VCAPS detected. Using default DGaaS URL: " + dgaasURL);

        return info;
    }/*from   w w  w  .  j a va2 s . c  om*/

    JSONObject jsonRoot = new JSONObject(vcaps);
    JSONObject docgenJSON = (JSONObject) jsonRoot.getJSONArray("Document Generation").get(0);
    JSONObject credentialsJSON = docgenJSON.getJSONObject("credentials");

    info.setURL(credentialsJSON.getString("url"));
    info.setInstanceID(credentialsJSON.getString("instanceid"));
    info.setRegion(credentialsJSON.getString("region"));

    log.info("VCAPS detected. DgaaS URL is: " + info.getURL());

    return info;
}

From source file:Main.java

public static String extSD() {
    String externalsd = "";

    if (!TextUtils.isEmpty(System.getenv("SECONDARY_STORAGE"))) {
        final String externalstorage[] = System.getenv("SECONDARY_STORAGE").split(":");
        for (final String dirs : externalstorage) {
            final File dir = new File(dirs);
            if (dir.exists() && dir.isDirectory() && dir.canRead() && dir.canWrite()) {
                externalsd = dirs;//from   w  w  w  . j av  a 2s .c om
                break;
            }
        }
    } else {
        final String supported[] = { "/mnt/extSdCard", "/storage/sdcard1", "/mnt/external_sd" };
        for (final String dirs : supported) {
            final File dir = new File(dirs);
            if (dir.exists() && dir.isDirectory() && dir.canRead() && dir.canWrite()) {
                externalsd = dirs;
                break;
            }
        }
    }
    return externalsd;
}

From source file:Main.java

public static String[] getSecondaryDirs() {
    List<String> ret = new ArrayList<String>();
    String secondaryStorageString = System.getenv("SECONDARY_STORAGE");
    if (secondaryStorageString != null && !secondaryStorageString.trim().isEmpty()) {
        String[] dirs = secondaryStorageString.split(":");

        for (String dir : dirs) {
            File file = new File(dir);
            if (file.isDirectory() && file.canWrite()) {
                ret.add(dir);/*from   ww  w. jav a 2s. c  o  m*/
            }
        }

        if (ret.isEmpty())
            return null;
        else
            return ret.toArray(new String[ret.size()]);

    } else {
        return null;
    }
}

From source file:com.alibaba.antx.util.CharsetUtil.java

public static String detectedSystemCharset() {
    String charset = Charset.defaultCharset().name();

    // unix?LANGcharset
    if (SystemUtils.IS_OS_UNIX) {
        String lang = System.getenv("LANG");
        int index = -1;

        if (!StringUtil.isBlank(lang) && (index = lang.indexOf(".")) >= 0) {
            String langCharset = lang.substring(index + 1);

            if (Charset.isSupported(langCharset)) {
                charset = langCharset;//from w ww  . j av  a  2s .  co  m
            }
        }
    }

    return charset;
}

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

public static boolean inOpenShiftContainer() {
    return System.getenv(OPENSHIFT_REPO_DIR) != null;
}

From source file:com.microsoft.alm.common.utils.SystemHelper.java

/**
 * Gets the computer name/*from  www  .ja  v  a 2s . c o  m*/
 *
 * @return local host name if found, falls back to computername env variable otherwise
 */
public static String getComputerName() {
    try {
        java.net.InetAddress localMachine = java.net.InetAddress.getLocalHost();
        return localMachine.getHostName();
    } catch (UnknownHostException e) {
        logger.warn("getComputerName failed", e);
        return System.getenv(COMPUTER_NAME);
    }
}

From source file:com.microsoft.azure.management.compute.samples.CreateVirtualMachinesInParallel.java

/**
 * Main entry point.//from   www.  ja  v  a2s. c  o m
 * @param args the parameters
 */
public static void main(String[] args) {
    try {

        //=============================================================
        // Authenticate
        //
        System.out.println("AZURE_AUTH_LOCATION_2=" + System.getenv("AZURE_AUTH_LOCATION_2"));
        final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION_2"));

        Azure azure = Azure.configure().withLogLevel(LogLevel.NONE).authenticate(credFile)
                .withDefaultSubscription();

        // Print selected subscription
        System.out.println("Selected subscription: " + azure.subscriptionId());

        runSample(azure);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }

}