List of usage examples for java.lang System getenv
public static String getenv(String name)
From source file:com.ibm.health.HealthData.java
private static JSONObject getVcapServices() { String envServices = System.getenv("VCAP_SERVICES"); JSONObject sysEnv = null;/*from w w w . j a v a 2 s . c om*/ if (envServices == null) { logger.info("VCAP Services not found, using predfined meta-information"); return null; } try { sysEnv = JSONObject.parse(envServices); } catch (Exception e) { logger.error("Error parsing VCAP_SERVICES: {}", e.getMessage()); } return sysEnv; }
From source file:io.kodokojo.config.module.AwsModule.java
@Provides @Singleton//from ww w . ja v a 2 s . c o m DnsManager provideDnsManager(ApplicationConfig applicationConfig, AwsConfig awsConfig) { AWSCredentials credentials = null; try { DefaultAWSCredentialsProviderChain defaultAWSCredentialsProviderChain = new DefaultAWSCredentialsProviderChain(); credentials = defaultAWSCredentialsProviderChain.getCredentials(); } catch (RuntimeException e) { LOGGER.warn("Unable to retrieve AWS credentials."); } if (StringUtils.isNotBlank(System.getenv("NO_DNS")) || credentials == null) { LOGGER.info("Using NoOpDnsManager as DnsManger implementation"); return new NoOpDnsManager(); } else { LOGGER.info("Using Route53DnsManager as DnsManger implementation"); return new Route53DnsManager(applicationConfig.domain(), Region.getRegion(Regions.fromName(awsConfig.region()))); } }
From source file:org.wso2.carbon.buzzword.tag.cloud.sample.BuzzwordDAO.java
public Buzzword[] getBuzzWordList() throws Exception { String apiEndpointUrl = System.getenv("API_ENDPOINT_URL"); logger.info("API_ENDPOINT_URL : " + apiEndpointUrl); try {/*ww w.j ava 2 s . c om*/ HttpClient client = getHttpClient(); HttpGet apiMethod = new HttpGet(apiEndpointUrl); apiMethod.addHeader("Authorization", "Bearer " + getAccessToken()); HttpResponse response = client.execute(apiMethod); if (HttpStatus.SC_OK == response.getStatusLine().getStatusCode()) { return formatDataToBuzzWords(getStringFromInputStream(response.getEntity().getContent())); } else { logger.log(Level.SEVERE, "Error occurred invoking the api endpoint. Http Status : " + response.getStatusLine().getStatusCode()); throw new Exception("Failed to get Buzzwords from backend API:" + apiEndpointUrl); } } catch (HttpException e) { logger.log(Level.SEVERE, "Error occurred while invoking API endpoint.", e); throw new Exception("Failed to get Buzzwords from backend API:" + apiEndpointUrl); } catch (IOException e) { logger.log(Level.SEVERE, "Error occurred while invoking API endpoint.", e); throw new Exception("Failed to get Buzzwords from backend API:" + apiEndpointUrl); } }
From source file:com.ibm.watson.WatsonVRTraining.util.images.PhotoCaptureFrame.java
PhotoCaptureFrame() { jp = new JPanel(); jp.setLayout(new BoxLayout(jp, BoxLayout.Y_AXIS)); JScrollPane scrollPane = new JScrollPane(jp); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); scrollPane.setPreferredSize(new Dimension(dim.width / 2 - 40, dim.height - 117)); JButton btn = new JButton("Upload Image"); btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(System.getenv("user.home")); fc.setFileFilter(new JPEGImageFileFilter()); int res = fc.showOpenDialog(null); // We have an image! try { if (res == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); //SharedResources.sharedCache.getCapturedImageList().add(file); File tmpf_name = File.createTempFile("tmp", "." + FilenameUtils.getExtension(file.getName())); System.out.println("cp " + file.getPath() + " " + AppConstants.vr_process_img_dir_path + File.separator + tmpf_name.getName()); new CommandsUtils().executeCommand("bash", "-c", "cp " + file.getPath() + " " + AppConstants.vr_process_img_dir_path + File.separator + tmpf_name.getName()); }/* ww w . ja v a 2 s. co m*/ } catch (Exception iOException) { } } }); ImageRemainingProcessingLabel = new JLabel("REMAINIG IMAGES:0"); ImageRemainingProcessingLabel.setHorizontalAlignment(SwingConstants.LEFT); ImageRemainingProcessingLabel.setFont(new Font("Arial", Font.BOLD, 13)); ImagebeingProcessedLabel = new JLabel(" PROCESSING IMAGES:0"); ImagebeingProcessedLabel.setHorizontalAlignment(SwingConstants.LEFT); ImagebeingProcessedLabel.setFont(new Font("Arial", Font.BOLD, 13)); appIDLabel = new JLabel("APP-ID:" + AppConstants.unique_app_id); appIDLabel.setHorizontalAlignment(SwingConstants.LEFT); appIDLabel.setFont(new Font("Arial", Font.BOLD, 13)); headerPanel = new JPanel(new FlowLayout()); headerPanel.add(ImageRemainingProcessingLabel); headerPanel.add(ImagebeingProcessedLabel); headerPanel.add(btn); headerPanel.add(appIDLabel); headerPanel.setSize(new Dimension(getWidth(), 10)); JPanel contentPane = new JPanel(); contentPane.add(headerPanel); contentPane.add(scrollPane); f = new JFrame("IBM Watson Visual Prediction Window"); f.setContentPane(contentPane); f.setSize(dim.width / 2 - 30, dim.height - 40); f.setLocation(dim.width / 2, 0); f.setResizable(false); f.setPreferredSize(new Dimension(dim.width / 2 - 30, dim.height - 60)); f.setVisible(true); }
From source file:com.netscape.cmstools.profile.ProfileEditCLI.java
public void execute(String[] args) throws Exception { // Always check for "--help" prior to parsing if (Arrays.asList(args).contains("--help")) { printHelp();/*from w ww . ja va2s .c om*/ return; } CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length < 1) { throw new Exception("No Profile ID specified."); } String profileId = cmdArgs[0]; ProfileClient profileClient = profileCLI.getProfileClient(); // read profile into temporary file byte[] orig = profileClient.retrieveProfileRaw(profileId); ProfileCLI.checkConfiguration(orig, false /* requireProfileId */, true /* requireDisabled */); Path tempFile = Files.createTempFile("pki", ".cfg"); try { Files.write(tempFile, orig); // invoke editor on temporary file String editor = System.getenv("EDITOR"); String[] command; if (editor == null || editor.trim().isEmpty()) { command = new String[] { "/usr/bin/env", "vi", tempFile.toString() }; } else { command = new String[] { editor.trim(), tempFile.toString() }; } ProcessBuilder pb = new ProcessBuilder(command); pb.inheritIO(); int exitCode = pb.start().waitFor(); if (exitCode != 0) { throw new Exception("Exited abnormally."); } // read data from temporary file and modify if changed byte[] cur = ProfileCLI.readRawProfileFromFile(tempFile); if (!Arrays.equals(cur, orig)) { profileClient.modifyProfileRaw(profileId, cur); } System.out.write(cur); } finally { Files.delete(tempFile); } }
From source file:net.erdfelt.android.sdkfido.local.LocalAndroidPlatforms.java
/** * Attempt to find the local java sdk using the most common environment variables. * /*from ww w . j av a2 s .c om*/ * @return the local android java sdk directory * @throws IOException * if unable to load the default local java sdk */ public static File findLocalJavaSdk() throws IOException { StringBuilder err = new StringBuilder(); err.append("Unable to find the Local Android Java SDK Folder."); // Check Environment Variables First String envKeys[] = { "ANDROID_HOME", "ANDROID_SDK_ROOT" }; for (String envKey : envKeys) { File sdkHome = getEnvironmentVariableDir(err, envKey); if (sdkHome == null) { continue; // skip, not found on that key } LocalAndroidPlatforms platforms = new LocalAndroidPlatforms(sdkHome); if (platforms.valid()) { return sdkHome; } } // Check Path for possible android.exe (or similar) List<String> searchBins = new ArrayList<String>(); if (SystemUtils.IS_OS_WINDOWS) { searchBins.add("adb.exe"); searchBins.add("emulator.exe"); searchBins.add("android.exe"); } else { searchBins.add("adb"); searchBins.add("emulator"); searchBins.add("android"); } String pathParts[] = StringUtils.split(System.getenv("PATH"), File.pathSeparatorChar); for (String searchBin : searchBins) { err.append("\nSearched PATH for ").append(searchBin); for (String pathPart : pathParts) { File pathDir = new File(pathPart); LOG.fine("Searching Path: " + pathDir); File bin = new File(pathDir, searchBin); if (bin.exists() && bin.isFile() && bin.canExecute()) { File homeDir = bin.getParentFile().getParentFile(); LOG.fine("Possible Home Dir: " + homeDir); LocalAndroidPlatforms platforms = new LocalAndroidPlatforms(homeDir); if (platforms.valid) { return homeDir; } } } err.append(", not found."); } throw new FileNotFoundException(err.toString()); }
From source file:com.varaneckas.hawkscope.util.PathUtils.java
/** * Interprets the location/*ww w .j a v a2 s . c om*/ * * It can either be a full path, a java property, * like ${user.home} (default) or environmental variable like ${$JAVA_HOME}. * * @param location * @return */ public static String interpret(final String location) { if (!location.matches(".*" + INTERPRET_REGEX + ".*")) { return location; } else { String newLocation = location; try { final Pattern grep = Pattern.compile(INTERPRET_REGEX); final Matcher matcher = grep.matcher(location); while (matcher.find()) { log.debug("Parsing: " + matcher.group(1)); String replacement; if (matcher.group(1).startsWith("$")) { replacement = System.getenv(matcher.group(1).substring(1)); } else { replacement = System.getProperty(matcher.group(1)); } newLocation = newLocation.replaceFirst(quote(matcher.group()), replacement.replaceAll(Constants.REGEX_BACKSLASH, Constants.REGEX_SLASH)); } } catch (final Exception e) { log.warn("Failed parsing location: " + location, e); } return newLocation; } }
From source file:com.ibm.bi.dml.yarn.DMLAppMaster.java
/** * /*w w w .ja v a2 s.c o m*/ * @param args * @throws YarnException * @throws IOException */ public void runApplicationMaster(String[] args) throws YarnException, IOException { _conf = new YarnConfiguration(); //obtain application ID String containerIdString = System.getenv(Environment.CONTAINER_ID.name()); ContainerId containerId = ConverterUtils.toContainerId(containerIdString); _appId = containerId.getApplicationAttemptId().getApplicationId(); LOG.info("SystemML appplication master (applicationID: " + _appId + ")"); //initialize clients to ResourceManager AMRMClient<ContainerRequest> rmClient = AMRMClient.createAMRMClient(); rmClient.init(_conf); rmClient.start(); //register with ResourceManager rmClient.registerApplicationMaster("", 0, ""); //host, port for rm communication LOG.debug("Registered the SystemML application master with resource manager"); //start status reporter to ResourceManager DMLAppMasterStatusReporter reporter = new DMLAppMasterStatusReporter(rmClient, 10000); reporter.start(); LOG.debug("Started status reporter (heartbeat to resource manager)"); //set DMLscript app master context DMLScript.setActiveAM(); //parse input arguments String[] otherArgs = new GenericOptionsParser(_conf, args).getRemainingArgs(); //run SystemML CP FinalApplicationStatus status = null; try { //core dml script execution (equivalent to non-AM runtime) boolean success = DMLScript.executeScript(_conf, otherArgs); if (success) status = FinalApplicationStatus.SUCCEEDED; else status = FinalApplicationStatus.FAILED; } catch (DMLScriptException ex) { LOG.error(DMLYarnClient.APPMASTER_NAME + ": Failed to executed DML script due to stop call:\n\t" + ex.getMessage()); status = FinalApplicationStatus.FAILED; writeMessageToHDFSWorkingDir(ex.getMessage()); } catch (Exception ex) { LOG.error(DMLYarnClient.APPMASTER_NAME + ": Failed to executed DML script.", ex); status = FinalApplicationStatus.FAILED; } finally { //stop periodic status reports reporter.stopStatusReporter(); LOG.debug("Stopped status reporter"); //unregister resource manager client rmClient.unregisterApplicationMaster(status, "", ""); LOG.debug("Unregistered the SystemML application master"); } }
From source file:com.excella.deploy.agent.core.UnixShellCommand.java
private String getJBossHome() { String home = "/opt/data/jboss"; String env = System.getenv("JBOSS_HOME"); log.debug("JBOSS_HOME is set to [" + env + "]"); if (env != null) { home = env;/*from ww w .j a v a 2 s . com*/ } return home; }
From source file:io.github.collaboratory.LauncherTest.java
@Test public void testCWLProgrammatic() throws Exception { File iniFile = FileUtils.getFile("src", "test", "resources", "launcher.ini"); File cwlFile = FileUtils.getFile("src", "test", "resources", "collab.cwl"); File jobFile = FileUtils.getFile("src", "test", "resources", "collab-cwl-job-pre.json"); ByteArrayOutputStream stdout = new ByteArrayOutputStream(); ByteArrayOutputStream stderr = new ByteArrayOutputStream(); if (System.getenv("AWS_ACCESS_KEY") == null || System.getenv("AWS_SECRET_KEY") == null) { expectedEx.expect(AmazonClientException.class); expectedEx.expectMessage("Unable to load AWS credentials from any provider in the chain"); }/*from w w w.j av a 2 s . c om*/ final LauncherCWL launcherCWL = new LauncherCWL(iniFile.getAbsolutePath(), cwlFile.getAbsolutePath(), jobFile.getAbsolutePath()); launcherCWL.run(CommandLineTool.class); assertTrue(!stdout.toString().isEmpty()); }