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:org.craftercms.core.util.template.impl.spel.SpELStringTemplateCompilerTest.java

@Test
public void testCompiler() throws Exception {
    StringWriter output = new StringWriter();

    compiler.compile(new IdentifiableStringTemplateSource("template", TEMPLATE)).process(beanFactory, output);

    String expected = String.format(PROCESSED_TEMPLATE, person.getFirstName(), person.getLastName(),
            System.getProperty("os.name"), System.getenv("PATH"));
    assertEquals(expected, output.toString());
}

From source file:com.ibm.watson.movieapp.dialog.rest.WDSBlueMixProxyResource.java

/**
 * /* w w w. j a va 2s.com*/
 */
private static void loadStaticBluemixProperties() {
    String envServices = System.getenv("VCAP_SERVICES"); //$NON-NLS-1$
    if (envServices != null) {
        UtilityFunctions.logger.info(Messages.getString("WDSBlueMixProxyResource.VCAP_SERVICES_ENV_VAR_FOUND")); //$NON-NLS-1$
        JsonObject services = new JsonParser().parse(envServices).getAsJsonObject();
        UtilityFunctions.logger
                .info(Messages.getString("WDSBlueMixProxyResource.VCAP_SERVICES_JSONOBJECT_SUCCESS")); //$NON-NLS-1$
        JsonArray arr = (JsonArray) services.get("dialog"); //$NON-NLS-1$
        if (arr.size() > 0) {
            services = arr.get(0).getAsJsonObject();
            JsonObject credentials = services.get("credentials").getAsJsonObject(); //$NON-NLS-1$
            wds_base_url = credentials.get("url").getAsString(); //$NON-NLS-1$
            if (credentials.get("username") != null && !credentials.get("username").isJsonNull()) { //$NON-NLS-1$ //$NON-NLS-2$
                username = credentials.get("username").getAsString(); //$NON-NLS-1$
                UtilityFunctions.logger.info(Messages.getString("WDSBlueMixProxyResource.FOUND_USERNAME")); //$NON-NLS-1$
            }
            if (credentials.get("password") != null && !credentials.get("password").isJsonNull()) { //$NON-NLS-1$ //$NON-NLS-2$
                password = credentials.get("password").getAsString(); //$NON-NLS-1$
                UtilityFunctions.logger.info(Messages.getString("WDSBlueMixProxyResource.FOUND_PASSWORD")); //$NON-NLS-1$
            }
        }
    } else {
        UtilityFunctions.logger.error(Messages.getString("WDSBlueMixProxyResource.VCAP_SERVICES_CANNOT_LOAD")); //$NON-NLS-1$
    }

    envServices = System.getenv("DIALOG_ID"); //$NON-NLS-1$
    if (envServices != null) {
        dialog_id = envServices;
        UtilityFunctions.logger.info(Messages.getString("WDSBlueMixProxyResource.DIALOG_ACCOUNT_ID_SUCCESS")); //$NON-NLS-1$
    } else {
        UtilityFunctions.logger.error(Messages.getString("WDSBlueMixProxyResource.DIALOG_ACCOUNT_ID_FAIL")); //$NON-NLS-1$
    }
}

From source file:locksdemo.RedisServer.java

private Statement failOrSkip(Exception exception) {
    String serversRequired = System.getenv(EXTERNAL_SERVERS_REQUIRED);
    if ("true".equalsIgnoreCase(serversRequired)) {
        logger.error(this.resourceDescription + " IS REQUIRED BUT NOT AVAILABLE", exception);
        fail(this.resourceDescription + " IS NOT AVAILABLE");
        // Never reached, here to satisfy method signature
        return null;
    } else {//  w  w w. j a va2s .  c o m
        logger.error(this.resourceDescription + " IS NOT AVAILABLE, SKIPPING TESTS", exception);
        return new Statement() {

            @Override
            public void evaluate() throws Throwable {
                Assume.assumeTrue(
                        "Skipping test due to " + RedisServer.this.resourceDescription + " not being available",
                        false);
            }
        };
    }
}

From source file:com.nike.cerberus.command.CerberusCommand.java

public String getEnvironment() {
    String calculatedEnv = StringUtils.isNotBlank(environment) ? environment
            : System.getenv("CERBERUS_CLI_ENV");

    if (StringUtils.isBlank(calculatedEnv)) {
        throw new IllegalArgumentException(
                "Failed to determine environment, checked 'CERBERUS_CLI_ENV' env var and -e, --env, --environment command options, options must go before the command");
    }// w w w.  j  a v  a 2s  . c  o m

    return calculatedEnv;
}

From source file:org.drugis.trialverse.config.SocialConfig.java

@Override
public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
    final String key = System.getenv("TRIALVERSE_OAUTH_GOOGLE_KEY");
    final String secret = System.getenv("TRIALVERSE_OAUTH_GOOGLE_SECRET");
    cfConfig.addConnectionFactory(new GoogleConnectionFactory(key, secret));
}

From source file:io.fabric8.maven.enricher.fabric8.CdEnricher.java

private String getBuildId() {
    String buildId = System.getenv("BUILD_ID");
    if (buildId == null) {
        buildId = System.getProperty("BUILD_ID");
    }//from  ww w  .  j  ava  2  s.c om
    return buildId;
}

From source file:azkaban.jobs.builtin.JavaJobRunnerMain.java

public JavaJobRunnerMain() throws Exception {
    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            cancelJob();//  ww  w.  j  a va2  s .c om
        }
    });

    try {
        _jobName = System.getenv(ProcessJob.JOB_NAME_ENV);
        String propsFile = System.getenv(ProcessJob.JOB_PROP_ENV);

        _logger = Logger.getRootLogger();
        _logger.removeAllAppenders();
        ConsoleAppender appender = new ConsoleAppender(DEFAULT_LAYOUT);
        appender.activateOptions();
        _logger.addAppender(appender);

        Properties prop = new Properties();
        prop.load(new BufferedReader(new FileReader(propsFile)));

        _logger.info("Running job " + _jobName);
        String className = prop.getProperty(JOB_CLASS);
        if (className == null) {
            throw new Exception("Class name is not set.");
        }
        _logger.info("Class name " + className);

        // Create the object.
        _javaObject = getObject(_jobName, className, prop);
        if (_javaObject == null) {
            _logger.info("Could not create java object to run job: " + className);
            throw new Exception("Could not create running object");
        }

        _cancelMethod = prop.getProperty(CANCEL_METHOD_PARAM, DEFAULT_CANCEL_METHOD);

        String runMethod = prop.getProperty(RUN_METHOD_PARAM, DEFAULT_RUN_METHOD);
        _logger.info("Invoking method " + runMethod);
        _javaObject.getClass().getMethod(runMethod, new Class<?>[] {}).invoke(_javaObject);
        _isFinished = true;

        // Get the generated properties and store them to disk, to be read by ProcessJob.
        try {
            final Method generatedPropertiesMethod = _javaObject.getClass()
                    .getMethod(GET_GENERATED_PROPERTIES_METHOD, new Class<?>[] {});
            Props outputGendProps = (Props) generatedPropertiesMethod.invoke(_javaObject, new Object[] {});
            outputGeneratedProperties(outputGendProps);
        } catch (NoSuchMethodException e) {
            _logger.info(String.format(
                    "Apparently there isn't a method[%s] on object[%s], using empty Props object instead.",
                    GET_GENERATED_PROPERTIES_METHOD, _javaObject));
            outputGeneratedProperties(new Props());
        }
    } catch (Exception e) {
        _isFinished = true;
        throw e;
    }
}

From source file:org.drugis.addis.config.SocialConfig.java

@Override
public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
    final String key = System.getenv("ADDIS_CORE_OAUTH_GOOGLE_KEY");
    final String secret = System.getenv("ADDIS_CORE_OAUTH_GOOGLE_SECRET");
    cfConfig.addConnectionFactory(new GoogleConnectionFactory(key, secret));
}

From source file:com.thoughtworks.go.util.HttpService.java

@Autowired(required = false)
public HttpService(GoAgentServerHttpClient httpClient, AgentRegistry agentRegistry) {
    this(new HttpClientFactory(httpClient), agentRegistry,
            !"true".equalsIgnoreCase(System.getenv("GO_USE_TOKEN_AUTH")));
}

From source file:net.rim.ejde.internal.util.EnvVarUtils.java

static public String resolveSystemVar(String var) {
    String sysVar = System.getenv(var);

    if (StringUtils.isEmpty(sysVar))
        return var;

    return sysVar;
}