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 java.util.Map<String, String> getenv() 

Source Link

Document

Returns an unmodifiable string map view of the current system environment.

Usage

From source file:com.tascape.qa.th.android.comm.Adb.java

private static String locateAdb() {
    String sysAdb = SystemConfiguration.getInstance().getProperty(SYSPROP_ADB_EXECUTABLE);
    if (sysAdb != null) {
        return sysAdb;
    } else {/*from   ww w .ja v  a  2  s.  c  om*/
        String paths = System.getenv().get("PATH");
        if (StringUtils.isBlank(paths)) {
            paths = System.getenv().get("Path");
        }
        if (StringUtils.isBlank(paths)) {
            paths = System.getenv().get("path");
        }
        if (StringUtils.isNotBlank(paths)) {
            String[] path = paths.split(System.getProperty("path.separator"));
            for (String p : path) {
                LOG.debug("path {}", p);
                File f = Paths.get(p, "adb").toFile();
                if (f.exists()) {
                    return f.getAbsolutePath();
                }
            }
        }
    }
    throw new RuntimeException("Cannot find adb based on system PATH. Please specify where adb executable is by"
            + " setting system property " + SYSPROP_ADB_EXECUTABLE + "=/path/to/your/sdk/platform-tools/adb");
}

From source file:com.technofovea.packbsp.packaging.ExternalController.java

public ExternalController() {
    executor.setExitValue(SUCCESSFUL_EXIT);
    watchdog = new ExecuteWatchdog(WATCHDOG_TIME);
    executor.setWatchdog(watchdog);/*from   w w  w.j av  a  2s.  c om*/
    environment = new HashMap<String, String>(System.getenv());
}

From source file:io.fabric8.spring.boot.condition.OnInsideKubernetesCondition.java

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    for (String variable : REQUIRED_ENV_VARIABLES) {
        if (Strings.isNullOrBlank(System.getenv().get(variable))) {
            return ConditionOutcome.noMatch("Environment variable " + variable + " not found.");
        }//from  w w w  .j  a  va2  s  .com
    }
    return ConditionOutcome.match();
}

From source file:com.tasktop.c2c.server.common.service.HttpProxySetup.java

public void setupProxyFromEnvironment() {
    String http_proxy = System.getenv().get("http_proxy");

    if (http_proxy != null) {
        if (!http_proxy.startsWith("http://")) {
            http_proxy = "http://" + http_proxy;
        }/*w  ww . j  a v  a2s .c  o  m*/

        logger.info("Configuring http proxy as: " + http_proxy);
        try {
            URL proxyUrl = new URL(http_proxy);
            httpProxyHost = proxyUrl.getHost();
            System.setProperty("http.proxyHost", httpProxyHost);
            httpProxyPort = proxyUrl.getPort();
            if (httpProxyPort != 80) {
                System.setProperty("http.proxyPort", httpProxyPort + "");
            }

        } catch (MalformedURLException e) {
            logger.error("Error configuring proxy", e);
        }

    } else {
        logger.info("No http proxy defined");
    }

    String https_proxy = System.getenv().get("https_proxy");
    if (https_proxy != null) {
        if (!https_proxy.startsWith("https://")) {
            https_proxy = "https://" + https_proxy;
        }

        logger.info("Configuring https proxy as: " + https_proxy);
        try {
            URL proxyUrl = new URL(https_proxy);
            System.setProperty("https.proxyHost", proxyUrl.getHost());
            if (proxyUrl.getPort() != 443) {
                System.setProperty("https.proxyPort", proxyUrl.getPort() + "");
            }
        } catch (MalformedURLException e) {
            logger.error("Error configuring proxy", e);
        }

    } else {
        logger.info("No https proxy defined");
    }

    String no_proxy = System.getenv().get("no_proxy");

    if (no_proxy != null) {
        no_proxy = no_proxy.replace(",", "|");
    }

    if (dontProxyToProfile) {
        if (no_proxy == null) {
            no_proxy = "";
        } else {
            no_proxy = no_proxy + "|";
        }
        no_proxy = no_proxy + profileConfiguration.getBaseWebHost() + "|*."
                + profileConfiguration.getBaseWebHost();
    }

    if (no_proxy != null && !no_proxy.isEmpty()) {
        logger.info("Configuring no_proxy as: " + no_proxy);

        System.setProperty("http.nonProxyHosts", no_proxy);
        System.setProperty("https.nonProxyHosts", no_proxy);
    }

}

From source file:edu.isi.pegasus.common.util.VariableExpander.java

/**
 * Overloaded constructor /*from w ww  . j ava2 s.  co  m*/
 * 
 * @param caseSensitive  boolean indicating whether you want lookups to be
 *                       case sensitive or not.
 */
public VariableExpander(boolean caseSensitive) {
    mValuesMap = new HashMap(System.getenv());
    mExpander = new StrSubstitutor(mValuesMap, "${", "}", '\\');
    mExpander.setVariableResolver(new CaseSensitiveStrLookup(this.mValuesMap, caseSensitive));

}

From source file:com.eryansky.utils.SigarUtil.java

/**
 * ??//from   w  ww .  j  ava 2  s  . c om
 * @throws Exception
 */
public static ServerStatus getServerStatus() throws Exception {
    ServerStatus status = new ServerStatus();
    status.setServerTime(DateFormatUtils.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss"));
    status.setServerName(System.getenv().get("COMPUTERNAME"));

    Runtime rt = Runtime.getRuntime();
    //status.setIp(InetAddress.getLocalHost().getHostAddress());
    status.setJvmTotalMem(rt.totalMemory() / (1024 * 1024));
    status.setJvmFreeMem(rt.freeMemory() / (1024 * 1024));
    status.setJvmMaxMem(rt.maxMemory() / (1024 * 1024));
    Properties props = System.getProperties();
    status.setServerOs(props.getProperty("os.name") + " " + props.getProperty("os.arch") + " "
            + props.getProperty("os.version"));
    status.setJavaHome(props.getProperty("java.home"));
    status.setJavaVersion(props.getProperty("java.version"));
    status.setJavaTmpPath(props.getProperty("java.io.tmpdir"));

    Sigar sigar = new Sigar();
    getServerCpuInfo(sigar, status);
    getServerDiskInfo(sigar, status);
    getServerMemoryInfo(sigar, status);

    return status;
}

From source file:com.aleerant.tnssync.PropertiesHandler.java

public PropertiesHandler(String[] args) throws AppException {
    initOptions();//  w ww.  j a  v  a  2  s  . c  o  m

    try {
        CommandLine cl = mParser.parse(mOptions, args);

        if (cl.hasOption("h")) {
            printUsageInfo();
            System.exit(0);
        }

        if (cl.hasOption("v")) {
            printVersion();
            System.exit(0);
        }

        if (cl.hasOption("ta")) {
            mTnsAdminPathString = cl.getOptionValue("ta");
        } else {
            mTnsAdminPathString = (System.getenv()).get("TNS_ADMIN");
            if (mTnsAdminPathString == null) {
                throw new IllegalArgumentException("Missing envinronment variable: TNS_ADMIN");
            }
        }

    } catch (ParseException e) {
        // oops, something went wrong
        System.err.println("parsing failed.  Reason: " + e.getMessage());
        printUsageInfo();
        System.exit(1);
    }

    selectLoggingConfigFile();
    validateTnsAdminPath();
    getLdapOraProperties();
}

From source file:eu.europa.ec.fisheries.uvms.spatial.service.bean.impl.SpatialInitializerBean.java

protected boolean mustRedeploy() {
    boolean isMustRedploy = false;
    String envVariable = System.getenv().get(PROP_USM_DESCRIPTOR_FORCE_UPDATE);

    if (StringUtils.isNotBlank(envVariable)) {
        log.info(/*from  w w  w . java2  s . co  m*/
                "You have environment variable {}, which overrides the same configuration in {} of Spatial.ear. The value is {}.",
                PROP_USM_DESCRIPTOR_FORCE_UPDATE, PROP_FILE_NAME, envVariable);
        isMustRedploy = Boolean.valueOf(envVariable);
    } else {
        try {
            Properties moduleConfigs = retrieveModuleConfigs();
            isMustRedploy = Boolean.valueOf(moduleConfigs.getProperty(PROP_USM_DESCRIPTOR_FORCE_UPDATE));
            log.info("{} file contains a configuration {}, with the following value {}", PROP_FILE_NAME,
                    PROP_USM_DESCRIPTOR_FORCE_UPDATE, isMustRedploy);
        } catch (IOException e) {
            log.error(e.getMessage(), e);
            log.info(
                    "No {} file with property {} was configured. The default behavior is to skip USM deployment if application has already been deployed.",
                    PROP_FILE_NAME, PROP_USM_DESCRIPTOR_FORCE_UPDATE);
            //in case we can't retrieve a configuration, the default behavior is skipping redeployment
        }
    }
    return isMustRedploy;
}

From source file:com.urbancode.ud.client.UDRestClient.java

/**
 * Create an HTTP client configuring trustAllCerts using agent environment variables
 *
 * @param user The username to associate with the http client connection.
 * @param password The password of the username used to associate with the http client connection.
 * @see #createHttpClient(String,String,boolean)
 *
 * @return DefaultHttpClient// ww  w  .  j  a va  2s . c  o  m
 */
static public DefaultHttpClient createHttpClient(String user, String password) {
    String verifyServerIdentityString = System.getenv().get("UC_TLS_VERIFY_CERTS");
    Boolean verifiedCerts = Boolean.valueOf(verifyServerIdentityString);
    return createHttpClient(user, password, !verifiedCerts);
}

From source file:com.gopivotal.cloudfoundry.test.core.MemoryUtils.java

/**
 * Creates an instance of the utility
 */
public MemoryUtils() {
    this(System.getenv(), ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax());
}