List of usage examples for java.lang System getenv
public static String getenv(String name)
From source file:bibibi.configs.ProductionProfile.java
@Bean public BasicDataSource dataSource() throws URISyntaxException { URI dbUri = new URI(System.getenv("DATABASE_URL")); String username = dbUri.getUserInfo().split(":")[0]; String password = dbUri.getUserInfo().split(":")[1]; String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath(); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setUrl(dbUrl);//from www. ja v a 2s . c o m basicDataSource.setUsername(username); basicDataSource.setPassword(password); return basicDataSource; }
From source file:Connector.Embeddable.java
public void getConnection() { try {//from w ww .ja v a 2s . c o m String envServices = System.getenv("VCAP_SERVICES"); JSONParser parser = new JSONParser(); Object obj = parser.parse(envServices); JSONObject jsonObject = (JSONObject) obj; JSONArray vcapArray = (JSONArray) jsonObject.get("erservice"); JSONObject vcap = (JSONObject) vcapArray.get(0); JSONObject credentials = (JSONObject) vcap.get("credentials"); url = credentials.get("url").toString(); password = credentials.get("password").toString(); userid = credentials.get("userid").toString(); } catch (ParseException ex) { } }
From source file:ezbake.common.openshift.OpenShiftUtil.java
public static HostAndPort getThriftPrivateInfo() { String ip = Preconditions.checkNotNull(System.getenv("OPENSHIFT_JAVA_THRIFTRUNNER_IP")); String port = Preconditions.checkNotNull(System.getenv("OPENSHIFT_JAVA_THRIFTRUNNER_TCP_PORT")); return HostAndPort.fromParts(ip, NumberUtils.toInt(port, -1)); }
From source file:com.twosigma.beakerx.groovy.evaluator.GroovyClassLoaderFactory.java
public static GroovyClassLoader newEvaluator(Imports imports, Classpath classpath, String outDir, ImportCustomizer icz, ClassLoader parent) { try {//from w w w . j a v a 2s . co m Class.forName("org.codehaus.groovy.control.customizers.ImportCustomizer"); } catch (ClassNotFoundException e1) { String gjp = System.getenv(GROOVY_JAR_PATH); String errorMsg = null; if (gjp != null && !gjp.isEmpty()) { errorMsg = "Groovy libary not found, GROOVY_JAR_PATH = " + gjp; } else { errorMsg = "Default groovy libary not found. No GROOVY_JAR_PATH variable set."; } throw new GroovyNotFoundException(errorMsg); } icz = addImportsCustomizer(icz, imports); CompilerConfiguration config = new CompilerConfiguration().addCompilationCustomizers(icz); String acloader_cp = String.join(File.pathSeparatorChar + "", classpath.getPathsAsStrings()); config.setClasspath(acloader_cp); return new GroovyClassLoader(parent, config); }
From source file:mesosphere.dcos.hazelcast.DcosHazelcastApp.java
private static void setPropertyIfPresent(Config config, String configParam, String envParam, String defaultValue) {//from w w w.ja v a 2 s. c o m String env = System.getenv(envParam); if (StringUtils.isNotEmpty(env)) { config.setProperty(configParam, env); } else { config.setProperty(configParam, defaultValue); } }
From source file:com.thoughtworks.go.agent.bootstrapper.BootstrapperLoggingHelper.java
private static void setupDefaultLog4j() { String logFile = System.getenv("LOG_FILE"); System.out.println("logFile Environment Variable= " + logFile); try {//from w w w .j a v a 2s.c o m if (logFile == null) { logFile = "go-agent-bootstrapper.log"; } System.out.println("Logging to " + logFile); BasicConfigurator.configure(new FileAppender(LOG4J_PATTERN, logFile)); Logger.getRootLogger().setLevel(Level.INFO); } catch (IOException e) { BasicConfigurator.configure(new ConsoleAppender(LOG4J_PATTERN)); Logger.getRootLogger().setLevel(Level.INFO); Log LOG = LogFactory.getLog(BootstrapperLoggingHelper.class); LOG.warn("Unable to initialize log4j file-appender: " + logFile, e); LOG.warn("Using console-appender instead"); } }
From source file:eu.optimis.service_manager.rest.util.ConfigManager.java
public static String getConfigFilePath(String configFile) throws Exception { String optimisHome = optimis_Home; if (optimisHome == null) { optimis_Home = System.getenv("OPTIMIS_HOME"); optimisHome = "/opt/optimis"; log.warn("Please set environment variable OPTIMIS_HOME. Using default /opt/optimis."); }//w w w .j a v a 2 s .c o m File fileObject = new File(optimisHome.concat(configFile)); //If not exists, copy property files from the source code %OPTIMIS_HOME% if (!fileObject.exists()) { createDefaultConfigFile(fileObject); } return optimisHome.concat(configFile); }
From source file:com.github.moscaville.contactsdb.util.AirtableAuthorizationInterceptor.java
public AirtableAuthorizationInterceptor() { AIRTABLE_API_KEY = System.getenv("AIRTABLE_API_KEY"); }
From source file:com.cloudera.sqoop.manager.MySQLTestUtils.java
/** @return the current username. */ public static String getCurrentUser() { // First, check the $USER environment variable. String envUser = System.getenv("USER"); if (null != envUser) { return envUser; }// w w w . j av a 2s . c o m // Try `whoami` String[] whoamiArgs = new String[1]; whoamiArgs[0] = "whoami"; Process p = null; BufferedReader r = null; try { p = Runtime.getRuntime().exec(whoamiArgs); InputStream is = p.getInputStream(); r = new BufferedReader(new InputStreamReader(is)); return r.readLine(); } catch (IOException ioe) { LOG.error("IOException reading from `whoami`: " + ioe.toString()); return null; } finally { // close our stream. if (null != r) { try { r.close(); } catch (IOException ioe) { LOG.warn("IOException closing input stream from `whoami`: " + ioe.toString()); } } // wait for whoami to exit. while (p != null) { try { int ret = p.waitFor(); if (0 != ret) { LOG.error("whoami exited with error status " + ret); // suppress original return value from this method. return null; } } catch (InterruptedException ie) { continue; // loop around. } } } }
From source file:es.us.mwm.testcloudfoundry.DBClient.java
public DBClient() { try {/*from w ww . ja va2 s . c o m*/ JsonNode rootNode = new ObjectMapper().readTree(System.getenv("VCAP_SERVICES")); JsonNode innerNode = rootNode.get("cleardb").get(0); if (innerNode != null) { JsonNode aField = innerNode.get("credentials"); if (aField != null) { String host = aField.get("hostname").asText(); String database = aField.get("name").asText(); String username = aField.get("username").asText(); String password = aField.get("password").asText(); conn = DriverManager.getConnection("jdbc:mysql://" + host + ":3306/" + database, username, password); } } } catch (SQLException ex) { log.log(Level.SEVERE, ex.toString(), ex); } catch (IOException ex) { log.log(Level.SEVERE, ex.toString(), ex); } }