List of usage examples for java.lang System getenv
public static String getenv(String name)
From source file:fridgegameinstaller.installation.java
public void preinstall(int ram, boolean shader) { System.out.println("Installing..."); //check Modpack Update progmsg.setText("Checking for Modpack Update..."); if (true) {//from w w w . ja v a 2 s .co m progmsg.setText("Locating .minecraft..."); //set .minecraft location System.out.println(DEF.sysos); if (DEF.sysos.indexOf("win") >= 0) { mcloc = System.getenv("appdata") + "/.minecraft"; } if (DEF.sysos.indexOf("mac") >= 0) { mcloc = System.getProperty("user.home") + "/Library/Application Support/minecraft"; } if (DEF.sysos.indexOf("nix") >= 0 || DEF.sysos.indexOf("nux") >= 0 || DEF.sysos.indexOf("aix") > 0) { mcloc = System.getProperty("user.home") + "/.minecraft"; } if (mcloc == null) { mainFrame.errorMsg("No support for this OS.Try to install manually.", "Error"); } //old Modpack version existing? if (checkModpackUpdate()) { System.out.println("installing.."); System.out.println(System.getenv("appdata")); uninstall(); install(ram); if (shader) { installShader(); } prgbar.setValue(100); progmsg.setText("100%"); mainFrame.errorMsg("Installation finished!", "100%"); mainFrame.setFormToPostInstallation(); try { String url = "http://www.fridgegame.com/credits"; if (Desktop.isDesktopSupported()) { Desktop.getDesktop().browse(new URI(url)); } else { Runtime.getRuntime().exec("xdg-open " + url); } } catch (URISyntaxException | IOException e) { e.printStackTrace(); } } else { } } else { mainFrame.errorMsg( "The modpack is up to date.If you want to reinstall it to fix errors delete the fridgegame_version.fg file in your .minecraft", "Error"); mainFrame.setFormToPostInstallation(); } }
From source file:com.joyent.manta.config.IntegrationTestConfigContext.java
public static boolean encryptionEnabled() { String sysProp = System.getProperty(MapConfigContext.MANTA_CLIENT_ENCRYPTION_ENABLED_KEY); String envVar = System.getenv(EnvVarConfigContext.MANTA_CLIENT_ENCRYPTION_ENABLED_ENV_KEY); return BooleanUtils.toBoolean(sysProp) || BooleanUtils.toBoolean(envVar); }
From source file:com.redhat.developers.msa.aloha.AlohaVerticle.java
public AlohaVerticle() { String zipkingServer = System.getenv("ZIPKIN_SERVER_URL"); Builder builder = new Brave.Builder("aloha"); if (null == zipkingServer) { // Default configuration BRAVE = builder.build();/*from w ww .j a v a 2s . co m*/ System.out.println("No ZIPKIN_SERVER_URL defined. Printing zipkin traces to console."); } else { // Brave configured for a Server BRAVE = builder.spanCollector(HttpSpanCollector.create(System.getenv("ZIPKIN_SERVER_URL"), new EmptySpanCollectorMetricsHandler())).build(); } }
From source file:com.ibm.watson.WatsonTranslate.java
private static JSONObject getVcapServices() { String envServices = System.getenv("VCAP_SERVICES"); if (envServices == null) return null; JSONObject sysEnv = null;/* w ww.j a va 2 s. c o m*/ try { sysEnv = JSONObject.parse(envServices); } catch (IOException e) { // Do nothing, fall through to defaults logger.error("Error parsing VCAP_SERVICES: {} ", e.getMessage()); } return sysEnv; }
From source file:examples.mail.IMAPUtils.java
/** * Parse the URI and use the details to connect to the IMAP(S) server and login. * * @param uri the URI to use, e.g. imaps://user:pass@imap.mail.yahoo.com/folder * or imaps://user:pass@imap.googlemail.com/folder * @param defaultTimeout initial timeout (in milliseconds) * @param listener for tracing protocol IO (may be null) * @return the IMAP client - connected and logged in * @throws IOException if any problems occur *///from w w w . ja v a 2 s . com static IMAPClient imapLogin(URI uri, int defaultTimeout, ProtocolCommandListener listener) throws IOException { final String userInfo = uri.getUserInfo(); if (userInfo == null) { throw new IllegalArgumentException("Missing userInfo details"); } String[] userpass = userInfo.split(":"); if (userpass.length != 2) { throw new IllegalArgumentException("Invalid userInfo details: '" + userInfo + "'"); } String username = userpass[0]; String password = userpass[1]; /* * If the initial password is: * '*' - replace it with a line read from the system console * '-' - replace it with next line from STDIN * 'ABCD' - if the input is all upper case, use the field as an environment variable name * * Note: there are no guarantees that the password cannot be snooped. * * Even using the console may be subject to memory snooping, * however it should be safer than the other methods. * * STDIN may require creating a temporary file which could be read by others * Environment variables may be visible by using PS */ if ("-".equals(password)) { // stdin BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); password = in.readLine(); } else if ("*".equals(password)) { // console Console con = System.console(); // Java 1.6 if (con != null) { char[] pwd = con.readPassword("Password for " + username + ": "); password = new String(pwd); } else { throw new IOException("Cannot access Console"); } } else if (password.equals(password.toUpperCase(Locale.ROOT))) { // environment variable name final String tmp = System.getenv(password); if (tmp != null) { // don't overwrite if variable does not exist (just in case password is all uppers) password = tmp; } } final IMAPClient imap; final String scheme = uri.getScheme(); if ("imaps".equalsIgnoreCase(scheme)) { System.out.println("Using secure protocol"); imap = new IMAPSClient(true); // implicit } else if ("imap".equalsIgnoreCase(scheme)) { imap = new IMAPClient(); } else { throw new IllegalArgumentException("Invalid protocol: " + scheme); } final int port = uri.getPort(); if (port != -1) { imap.setDefaultPort(port); } imap.setDefaultTimeout(defaultTimeout); if (listener != null) { imap.addProtocolCommandListener(listener); } final String server = uri.getHost(); System.out.println("Connecting to server " + server + " on " + imap.getDefaultPort()); try { imap.connect(server); System.out.println("Successfully connected"); } catch (IOException e) { throw new RuntimeException("Could not connect to server.", e); } if (!imap.login(username, password)) { imap.disconnect(); throw new RuntimeException("Could not login to server. Check login details."); } return imap; }
From source file:com.stimulus.archiva.plugin.Startup.java
public void init(ActionServlet actionServlet, ModuleConfig config) throws ServletException { logger.info(Config.getConfig().getProductName() + " v" + Config.getConfig().getApplicationVersion() + " started at " + new Date()); try {/* w ww . j a v a2 s. c om*/ Config conf = Config.getConfig(); String appPath; int retries = 0; do { try { Thread.sleep(100); } catch (Exception e) { } appPath = actionServlet.getServletConfig().getServletContext().getRealPath("/"); retries++; } while (appPath == null && retries < 10); if (appPath == null) { logger.debug("failed to retrieve application path from servlet context."); String catalinaPath = System.getenv("CATALINA_HOME"); String contextPath = actionServlet.getServletConfig().getServletContext().getContextPath(); if (catalinaPath != null && contextPath != null) { if (catalinaPath.endsWith(File.separator)) catalinaPath = catalinaPath.substring(0, catalinaPath.length() - 1); appPath = catalinaPath + File.separator + "webapps" + contextPath; logger.debug("constructed application path from catalina.home {appPath='" + appPath + "'}"); } else { logger.fatal( "failed to retrieve application path from servlet context or reconstruct from catalina home."); logger.fatal( "please remove the entire server/work/Catalina directory, browser cache, and restart the server."); throw new ServletException("failed to retrieve application path from servlet context."); } } FileSystem fs = Config.getFileSystem(); fs.outputSystemInfo(); fs.setApplicationPath(appPath); if (!fs.checkAllSystemPaths()) { logger.fatal("server cannot find one or more required system paths."); System.exit(1); } if (!fs.checkStartupPermissions()) { logger.fatal("failed to startup. directory and file read/write permissions not defined correctly."); System.exit(1); } fs.initLogging(); fs.initCrypto(); fs.clearViewDirectory(); fs.clearTempDirectory(); conf.init(MessageService.getFetchMessageCallback()); conf.loadSettings(MailArchivaPrincipal.SYSTEM_PRINCIPAL); conf.registerServices(); conf.getServices().startAll(); logger.debug("startup sequence is complete"); } catch (Exception e) { logger.fatal("failed to execute startup cause: ", e); System.exit(1); return; } }
From source file:alluxio.cli.validation.HdfsValidationTask.java
private boolean validateHdfsSettingParity(Map<String, String> optionsMap) { String serverHadoopConfDirPath; if (optionsMap.containsKey(HADOOP_CONF_DIR_OPTION.getOpt())) { serverHadoopConfDirPath = optionsMap.get(HADOOP_CONF_DIR_OPTION.getOpt()); } else {/* w ww . j a va2s . c o m*/ serverHadoopConfDirPath = System.getenv(HADOOP_CONF_DIR_ENV_VAR); } if (serverHadoopConfDirPath == null) { System.out.println("Path to server-side hadoop configuration unspecified," + " skipping validation for HDFS properties."); return true; } String serverCoreSiteFilePath = PathUtils.concatPath(serverHadoopConfDirPath, "/core-site.xml"); String serverHdfsSiteFilePath = PathUtils.concatPath(serverHadoopConfDirPath, "/hdfs-site.xml"); // If Configuration does not contain the key, then a {@link RuntimeException} will be thrown // before calling the {@link String#split} method. String[] clientHadoopConfFilePaths = Configuration.get(PropertyKey.UNDERFS_HDFS_CONFIGURATION).split(":"); String clientCoreSiteFilePath = null; String clientHdfsSiteFilePath = null; for (String path : clientHadoopConfFilePaths) { try { String[] pathComponents = PathUtils.getPathComponents(path); if (pathComponents.length < 1) { continue; } if (pathComponents[pathComponents.length - 1].equals("core-site.xml")) { clientCoreSiteFilePath = path; } else if (pathComponents[pathComponents.length - 1].equals("hdfs-site.xml")) { clientHdfsSiteFilePath = path; } } catch (InvalidPathException e) { System.out.format("%s is an invalid path. Skip HDFS config parity check.%n", path); return true; } } if (clientCoreSiteFilePath == null || clientCoreSiteFilePath.isEmpty()) { System.out.println( "Cannot locate the client-side core-site.xml," + " skipping validation for HDFS properties."); return true; } if (clientHdfsSiteFilePath == null || clientHdfsSiteFilePath.isEmpty()) { System.out.println( "Cannot locate the client-side hdfs-site.xml," + " skipping validation for HDFS properties."); return true; } return compareConfigurations(clientCoreSiteFilePath, serverCoreSiteFilePath) && compareConfigurations(clientHdfsSiteFilePath, serverHdfsSiteFilePath); }
From source file:io.instacount.client.InstacountClientTest.java
@BeforeClass public static void before() { final AbstractInstacountClientParams params = new AbstractInstacountClientParams(false) { @Override/*from w w w. ja v a2 s .com*/ public String getInstacountApplicationId() { return Preconditions.checkNotNull(System.getenv("INSTACOUNT_APPLICATION_ID"), "System Env variable 'INSTACOUNT_APPLICATION_ID' not specified!"); } @Override public String getInstacountReadOnlyApplicationKey() { return Preconditions.checkNotNull(System.getenv("INSTACOUNT_READ_ONLY_KEY"), "System Env variable 'INSTACOUNT_READ_ONLY_KEY' not specified!"); } @Override public String getInstacountReadWriteApplicationKey() { return Preconditions.checkNotNull(System.getenv("INSTACOUNT_READ_WRITE_KEY"), "System Env variable 'INSTACOUNT_READ_WRITE_KEY' not specified!"); } }; final String accessToken = System.getenv("GOOGLE_ACCOUNTS_OAUTH_ACCESS_TOKEN"); if (!StringUtils.isBlank(accessToken)) { final InstacountOAuth2BearerRequestInterceptor oauth2 = new InstacountOAuth2BearerRequestInterceptor.Impl( accessToken); client = Instacount.Builder.build(params, oauth2); } else { client = Instacount.Builder.build(params); } }
From source file:com.redhat.red.koji.build.Options.java
public boolean parseArgs(final String[] args) throws CmdLineException { final int cols = (System.getenv("COLUMNS") == null ? 100 : Integer.valueOf(System.getenv("COLUMNS"))); final ParserProperties props = ParserProperties.defaults().withUsageWidth(cols); final CmdLineParser parser = new CmdLineParser(this, props); boolean canStart = true; parser.parseArgument(args);//w ww . j a va 2 s.co m if (isHelp()) { printUsage(parser, null); canStart = false; } if (isWriteConfig()) { File config = getConfigFile(); Logger logger = LoggerFactory.getLogger(getClass()); logger.info("Writing default configuration file to: {}", config); if (config.isDirectory()) { config = new File(config, "buildfinder.conf"); } if (config.exists()) { File backup = new File(config.getPath() + ".bak"); logger.info("Backing up existing configuration to: {}", backup); config.renameTo(backup); } if (config.getParentFile() != null) { config.getParentFile().mkdirs(); } try (InputStream in = Thread.currentThread().getContextClassLoader() .getResourceAsStream(DEFAULT_CONFIG_RESOURCE); OutputStream out = new FileOutputStream(config)) { if (in == null) { logger.error("Cannot find default configuration in the classpath: {}", DEFAULT_CONFIG_FILE); } else { IOUtils.copy(in, out); } } catch (IOException e) { logger.error("Failed to write config file: " + config, e); } finally { canStart = false; } } return canStart; }
From source file:edu.umd.cs.buildServer.BuildServerTestHarness.java
@Override public void initConfig() throws IOException { if (System.getenv("PMD_HOME") != null) getConfig().setProperty(PMD_HOME, System.getenv("PMD_HOME")); getConfig().setProperty(LOG_DIRECTORY, "console"); // FIXME: this is also wrong in general, but might allow me to do some // testing// ww w . j a va 2s .c om getConfig().setProperty(SUPPORTED_COURSE_LIST, "CMSC433"); getConfig().setProperty(DEBUG_VERBOSE, "true"); getConfig().setProperty(DEBUG_DO_NOT_LOOP, "true"); getConfig().setProperty(DEBUG_PRESERVE_SUBMISSION_ZIPFILES, "true"); if (Boolean.getBoolean("debug.security")) getConfig().setProperty(DEBUG_SECURITY, "true"); if (Boolean.getBoolean("runStudentTests")) getConfig().setProperty(RUN_STUDENT_TESTS, "true"); String tools = System.getenv("tools.java"); if (tools != null) getConfig().setProperty(ConfigurationKeys.INSPECTION_TOOLS_PFX + "java", tools); String performCodeCoverage = System.getenv("PERFORM_CODE_COVERAGE"); if ("true".equals(performCodeCoverage)) getConfig().setProperty(CODE_COVERAGE, "true"); // TODO move the location of the Clover DB to the build directory. // NOTE: This requires changing the security.policy since Clover needs // to be able // to read, write and create files in the directory. String cloverDBPath = "/tmp/myclover.db." + Long.toHexString(nextRandomLong()); getConfig().setProperty(CLOVER_DB, cloverDBPath); }