1 package jester; 2 3 import java.io.*; 4 import java.util.Properties ; 5 6 public class RealConfiguration implements Configuration { 7 public static final String DEFAULT_CONFIGURATION_FILENAME = "jester.cfg"; 8 9 private Logger myLogger = new RealLogger(); 10 private Properties myProperties; 11 12 public RealConfiguration(String configFileName, PrintStream errorStream) throws IOException { 13 super(); 14 myProperties = new Properties (); 15 InputStream configPropertyFile = ClassLoader.getSystemResourceAsStream(configFileName); 16 if (configPropertyFile == null) { 17 configPropertyFile = getClass().getResourceAsStream(configFileName); 18 } 19 if (configPropertyFile != null) { 20 myProperties.load(configPropertyFile); 21 }else{ 22 errorStream.println("Warning - could not find "+DEFAULT_CONFIGURATION_FILENAME+" so using default configuration values."); 23 } 24 } 25 26 public RealConfiguration(String configFileName) throws IOException { 27 this(configFileName, System.err); 28 } 29 30 public String compilationCommand() { 31 return stringProperty("compilationCommand", "javac"); 32 } 33 private boolean isTrue(String value) { 34 return value.toLowerCase().equals("true"); 35 } 36 private boolean isTrueProperty(String propertyName, boolean defaultValue) { 37 String propertyValue = myProperties.getProperty(propertyName); 38 if(propertyValue==null){ 39 return defaultValue; 40 } 41 return isTrue(propertyValue); 42 } 43 public boolean shouldReportEagerly() { 44 return isTrueProperty("shouldReportEagerly", false); 45 } 46 public String sourceFileExtension() { 47 return stringProperty("sourceFileExtension", ".java"); 48 } 49 private String stringProperty(String propertyName, String defaultValue) { 50 String result = myProperties.getProperty(propertyName); 51 if (result == null) { 52 return defaultValue; 53 } 54 return result; 55 } 56 public String testRunningCommand() { 57 return stringProperty("testRunningCommand", "java jester.TestRunnerImpl"); 58 } 59 public String testsPassString() { 60 return stringProperty("testsPassString", "PASSED"); 61 } 62 public Logger getLogger() { 63 return myLogger; 64 } 65 public String xmlReportFileName() { 66 return stringProperty("xmlReportFileName", "jesterReport.xml"); 67 } 68 69 public boolean closeUIOnFinish() { 70 return isTrueProperty("closeUIOnFinish", true); 71 } 72 } | Popular Tags |