r107775 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107774‎ | r107775 | r107776 >
Date:15:17, 1 January 2012
Author:oren
Status:resolved (Comments)
Tags:
Comment:
improving testability under windows os
Modified paths:
  • /trunk/lucene-search-2/src/org/wikimedia/lsearch/config/Configuration.java (modified) (history)

Diff [purge]

Index: trunk/lucene-search-2/src/org/wikimedia/lsearch/config/Configuration.java
@@ -23,22 +23,13 @@
2424 */
2525 package org.wikimedia.lsearch.config;
2626
27 -import java.io.BufferedReader;
2827 import java.io.File;
2928 import java.io.FileInputStream;
3029 import java.io.FileNotFoundException;
3130 import java.io.IOException;
32 -import java.io.InputStreamReader;
33 -import java.net.Inet4Address;
3431 import java.net.MalformedURLException;
3532 import java.net.URL;
36 -import java.net.UnknownHostException;
37 -import java.util.ArrayList;
38 -import java.util.Hashtable;
3933 import java.util.Properties;
40 -import java.util.Vector;
41 -import java.util.regex.Matcher;
42 -import java.util.regex.Pattern;
4334
4435 import org.apache.log4j.BasicConfigurator;
4536 import org.apache.log4j.Level;
@@ -54,16 +45,22 @@
5546 */
5647 public class Configuration {
5748 private static Configuration instance;
58 - private static String configfile = null;
 49+ private static String configFile = null;
5950 private static String globalConfigUrl = null;
6051 private static boolean verbose = true; // print info and error messages
6152
6253 protected final String CONF_FILE_NAME = "lsearch.conf";
 54+ protected final String TEST_CONF_FILE_NAME = "lsearch.conf.test";
6355
 56+ /* os independent path component */
 57+ private final static String ETC_FOLDER = System.getProperty("file.separator") + "etc";
 58+ private final static String TEST_DATA_FOLDER = System.getProperty("file.separator") + "test-data";
 59+
 60+
6461 public static final String PATH_SEP = System.getProperty("file.separator");
6562
6663 public static void setConfigFile(String file) {
67 - configfile = file;
 64+ configFile = file;
6865 }
6966
7067 /** Returns an instance of Configuration singleton class */
@@ -72,24 +69,29 @@
7370 instance = new Configuration();
7471 return instance;
7572 }
 73+
7674 private Configuration() {
77 - if (configfile == null) {
 75+
 76+ if (configFile == null) {
7877 String home = System.getProperty("user.home");
7978 String [] paths;
80 - String filename = System.getProperty("file.separator")+CONF_FILE_NAME;
 79+ String filename = System.getProperty("file.separator") + CONF_FILE_NAME;
 80+ String testFilename = System.getProperty("file.separator") + TEST_CONF_FILE_NAME;
8181 if (home == null) {
8282 paths = new String[] {
83 - System.getProperty("user.dir")+filename,
84 - "/etc"+filename };
 83+ System.getProperty("user.dir") + filename,
 84+ ETC_FOLDER+filename };
8585 } else {
8686 paths = new String[] {
87 - home+System.getProperty("file.separator")+"."+CONF_FILE_NAME,
88 - System.getProperty("user.dir")+filename,
89 - "/etc"+filename };
 87+ home+System.getProperty("file.separator")+ "." + CONF_FILE_NAME, //home
 88+ System.getProperty("user.dir") + filename, //where invoked
 89+ ETC_FOLDER+filename, //in etc
 90+ System.getProperty("user.dir") +TEST_DATA_FOLDER + testFilename //in test-data
 91+ };
9092 }
91 - openProps(paths);
 93+ openPropertieFile(paths);
9294 } else {
93 - openProps(new String[] { configfile });
 95+ openPropertieFile(new String[] { configFile });
9496 }
9597
9698 if (getBoolean("Logging", "debug")) {
@@ -130,17 +132,24 @@
131133 }
132134 private Properties props;
133135
134 - private void openProps(String[] paths) {
 136+ /*
 137+ * trys to locate a properties file and open it.
 138+ */
 139+ private void openPropertieFile(String[] paths)
 140+ {
135141 props = new Properties();
 142+ String path="";
 143+
136144 for(int i=0;i<paths.length;i++){
137145 try {
138 - String path = paths[i];
 146+ path = paths[i];
139147 if(verbose)
140148 System.out.println("Trying config file at path "+path);
141149 props.load(new FileInputStream(new File(path)));
142 - configfile = path;
 150+ configFile = path;
143151 return;
144152 } catch (FileNotFoundException e3) {
 153+ System.err.println("file not found at "+path);
145154 // try the next one
146155 } catch (IOException e3) {
147156 System.err.println("Error: IO error reading config: " + e3.getMessage());
@@ -224,7 +233,4 @@
225234 public static void setGlobalConfigUrl(String globalConfigUrl) {
226235 Configuration.globalConfigUrl = globalConfigUrl;
227236 }
228 -
229 -
230 -
231237 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r108874Fix simple fixme on r107775reedy23:08, 13 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   17:43, 13 January 2012

Typo? openPropertieFile

The comments are indented weirdly:

+					System.getProperty("user.dir") +TEST_DATA_FOLDER + testFilename 										//in test-data

Status & tagging log