Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 28 29 package org.jruby.environment; 30 31 import java.io.BufferedReader ; 32 import java.io.File ; 33 import java.io.FileNotFoundException ; 34 import java.io.FileReader ; 35 import java.util.Map ; 36 37 import org.jruby.Ruby; 38 39 40 46 class OSEnvironmentReaderFromFile implements IOSEnvironmentReader { 47 48 private static final String JRUBY_ENVFILE = "jruby.envfile"; 49 50 private final OSEnvironment environmentReader = new OSEnvironment(); 51 52 53 56 public boolean isAccessible(Ruby runtime) { 57 String jrubyEnvFilename = System.getProperty(JRUBY_ENVFILE); 58 59 if (jrubyEnvFilename == null || jrubyEnvFilename.length() < 1) { 60 return false; 61 } 62 63 File jrubyEnvFile = new File (jrubyEnvFilename); 64 65 return (jrubyEnvFile.exists() && !jrubyEnvFile.isDirectory() && jrubyEnvFile.canRead()); 66 } 67 68 71 public Map getVariables(Ruby runtime) { 72 String jrubyEnvFilename = System.getProperty(JRUBY_ENVFILE); 73 74 Map envs = null; 75 76 if (jrubyEnvFilename == null || jrubyEnvFilename.length() < 1) { 77 environmentReader.handleException(new OSEnvironmentReaderExcepton("Property " + JRUBY_ENVFILE + " not defined.")); 78 } else { 79 BufferedReader reader = null; 80 try { 81 reader = new BufferedReader (new FileReader (jrubyEnvFilename)); 82 } catch (FileNotFoundException e) { 83 envs = null; 84 environmentReader.handleException(e); 86 } 87 envs = environmentReader.getVariablesFrom(reader); 88 } 89 return envs; 90 } 91 } 92
| Popular Tags
|