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:org.shept.util.CommandShellExecute.java

/**
 * Merge the existing environment with additional parameters
 * If the additional parameters are null then simply return the environment strings
 * @param addEnv/*www. j  ava  2s  . c  o m*/
 * @return
 */
public static String[] getEnvironment(String[] addEnv) {
    List<String> list = new ArrayList<String>();
    Map<String, String> sysEnv = System.getenv();
    for (Entry<String, String> entry : sysEnv.entrySet()) {
        list.add(entry.getKey() + "=" + entry.getValue());
    }
    if (addEnv != null) {
        list.addAll(Arrays.asList(addEnv));
    }
    // to avoid ClassCastException when casting Object[] to String[]
    String[] res = new String[list.size()];
    for (int i = 0; i < res.length; i++) {
        res[i] = list.get(i);
    }
    return res;
}

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

public RuntimeUtils() {
    this(System.getenv(), ManagementFactory.getRuntimeMXBean(), System.getProperties());
}

From source file:com.teradata.tempto.internal.configuration.ConfigurationVariableResolver.java

private Configuration replaceEnvVariables(Configuration configuration) {
    return resolveVariables(configuration, System.getenv());
}

From source file:org.cloudfoundry.samples.handson.ex4.EnvVariablesController.java

/**
 * Use the out variable to dump the contents of the environment variables.
 * /*ww  w . ja v a2s  .c  om*/
 * Notice how CloudFoundry instructs the app about services it provides
 * inside variables named {@code VCAP_something}.
 */
@RequestMapping("/ex4")
public void dump(HttpServletResponse response) throws Exception {
    @SuppressWarnings("unused")
    PrintWriter out = response.getWriter();

    Map<String, String> env = System.getenv();
    for (Entry<String, String> envi : env.entrySet()) {
        out.write(envi.getKey() + " => " + envi.getValue() + "\n");
    }

    // ...
}

From source file:com.sixt.service.framework.servicetest.helper.DockerComposeHelper.java

/**
 * Set environment variable "registryServer" to the host and port specified by
 * docker/*from   w w  w. j  ava  2s  . c  o m*/
 */
public static void setConsulEnvironment(DockerComposeRule docker) {
    DockerPort consul = docker.containers().container("consul").port(8500);
    Map<String, String> newEnv = new HashMap<>();
    newEnv.put(ServiceProperties.REGISTRY_SERVER_KEY, consul.inFormat("$HOST:$EXTERNAL_PORT"));
    newEnv.putAll(System.getenv());
    setEnv(newEnv);
}

From source file:com.nsn.squirrel.tab.utils.PathUtils.java

/**
 * Default path can be different for various OS
 * //from w w  w . j  a  v a  2s.c o  m
 * @return default path
 */
public static Path getDefaultPath() {

    Path defaultPath = Paths.get(""); //$NON-NLS-1$
    if (SystemUtils.IS_OS_WINDOWS) {
        defaultPath = Paths.get("C:\\"); //$NON-NLS-1$
    } else if (SystemUtils.IS_OS_MAC_OSX) {
        defaultPath = Paths.get(System.getenv().get("HOME")); //$NON-NLS-1$
    }
    return defaultPath;
}

From source file:gov.nih.nci.cabig.caaers.tools.ExcelImporter.java

/**
 * Check if datasource.properties file exisits.
  * If it does not then create oracle and postgres templates under
  * $USER_HOME/.caaers//*from w ww . ja  v  a  2s  . co  m*/
 * @throws Exception
 */
private static void checkDsPropertiesExistence() throws Exception {
    String userHome = System.getenv().get("HOME");
    String caaersDbTemplateDir = userHome + "/.caaers";
    File file = new File(caaersDbTemplateDir + "/datasource.properties");
    if (file.exists()) {
        //datasource.properties file exists
    } else {
        File oraTemplate = getResources("classpath*:dbtemplates/oracle.datasource.properties")[0].getFile();
        File postgresTemplate = getResources("classpath*:dbtemplates/postgres.datasource.properties")[0]
                .getFile();
        FileUtils.copyFileToDirectory(oraTemplate, new File(caaersDbTemplateDir));
        FileUtils.copyFileToDirectory(postgresTemplate, new File(caaersDbTemplateDir));
    }
}

From source file:com.enonic.cms.web.boot.BootEnvironment.java

private void resolveHomeDir() {
    final HomeResolver resolver = new HomeResolver();
    resolver.addSystemProperties(System.getenv());
    resolver.addSystemProperties(System.getProperties());
    resolver.resolve();//w  w w. ja va 2 s.  c  om
}

From source file:io.fabric8.spring.boot.internal.InternalServiceRegistar.java

@Override
public Service getService(String serviceName) {
    Map<String, String> env = System.getenv();
    String prefix = serviceName.toUpperCase();
    String serviceHost = env.get(prefix + HOST_SUFFIX);

    String defaultPortName = prefix + SERVICE_PORT;
    String namedPortPrefix = defaultPortName + "_";

    List<ServicePort> servicePorts = new ArrayList<>();
    for (Map.Entry<String, String> entry : env.entrySet()) {
        String key = entry.getKey();
        if (key.startsWith(namedPortPrefix)) {
            String name = key.substring(namedPortPrefix.length());
            String portValue = entry.getValue();
            String protocolValue = env.get(key + "_" + PROTO_SUFFIX);
            servicePorts.add(/* w  ww . j a v  a 2  s  . c  o  m*/
                    new ServicePortBuilder().withName(name.toLowerCase()).withPort(Integer.parseInt(portValue))
                            .withProtocol(protocolValue != null ? protocolValue : "TCP").build());
        }
    }

    //Check if we need to fallback to single port.
    if (servicePorts.isEmpty()) {
        String portValue = env.get(defaultPortName);
        String protocolValue = env.get(defaultPortName + PROTO_SUFFIX);

        servicePorts.add(new ServicePortBuilder().withPort(Integer.parseInt(portValue))
                .withProtocol(protocolValue != null ? protocolValue : "TCP").build());
    }

    return new ServiceBuilder().withNewMetadata().withName(serviceName).endMetadata().withNewSpec()
            .withPortalIP(serviceHost).withPorts(servicePorts).endSpec().build();
}

From source file:cane.brothers.e4.commander.utils.PathUtils.java

/**
 * Default path can be different for various OS
 * //from   w w  w.  j  ava  2s.  com
 * @return default path
 */
public static Path getDefaultPath() {
    Path defaultPath = Paths.get(""); //$NON-NLS-1$

    if (SystemUtils.IS_OS_WINDOWS) {
        defaultPath = Paths.get("C:\\"); //$NON-NLS-1$
    } else if (SystemUtils.IS_OS_MAC_OSX) {
        defaultPath = Paths.get(System.getenv().get("HOME")); //$NON-NLS-1$
    }
    return defaultPath;
}