TavernerPOS - Source Code

Clone: 

git clone http://www.librarysmith.co.uk/tavernerPOS

 

viewgit/viewgit/inc/functions.php:49 Function create_function() is deprecated [8192]

Index » tavernerPOS : Commitdiff 962b5f

Add command line option -configFile to specify alternative configuration file

Matt Smith [15-10-30 14:56]
Add command line option -configFile to specify alternative configuration file
diff --git a/src/com/floreantpos/config/AppConfig.java b/src/com/floreantpos/config/AppConfig.java
old mode 100644
new mode 100755
index 99d28f9..ba03b82
--- a/src/com/floreantpos/config/AppConfig.java
+++ b/src/com/floreantpos/config/AppConfig.java
@@ -5,6 +5,7 @@ import java.io.File;
 import org.apache.commons.configuration.PropertiesConfiguration;

 import com.floreantpos.Database;
+import com.floreantpos.main.Application;

 public class AppConfig {

@@ -21,12 +22,14 @@ public class AppConfig {
 	private static final String PRINT_RECEIPT_ON_ORDER_SETTLE = "print_receipt_on_order_settle"; //$NON-NLS-1$
 	private static final String PRINT_RECEIPT_ON_ORDER_FINISH = "print_receipt_on_order_finish"; //$NON-NLS-1$

+
 	private static PropertiesConfiguration config;

 	static {
 		try {
 			//File workingDir = Application.getWorkingDir();
-			File configFile = new File("floreantpos.config.properties"); //$NON-NLS-1$
+
+			File configFile = new File(Application.getInstance().getConfigFile()); //$NON-NLS-1$
 			if(!configFile.exists()) {
 				configFile.createNewFile();
 			}
diff --git a/src/com/floreantpos/main/Application.java b/src/com/floreantpos/main/Application.java
index 47d02f2..9d4eca7 100755
--- a/src/com/floreantpos/main/Application.java
+++ b/src/com/floreantpos/main/Application.java
@@ -60,7 +60,7 @@ public class Application {
 	private static Log logger = LogFactory.getLog(Application.class);

 	private boolean developmentMode = false;
-
+	private String configFile = "floreantpos.config.properties";
 	private PluginManager pluginManager;

 	private Terminal terminal;
@@ -517,6 +517,14 @@ public class Application {
 		this.developmentMode = developmentMode;
 	}

+	public String getConfigFile() {
+		return this.configFile;
+	}
+
+	public void setConfigFile(String configFile) {
+		this.configFile=configFile;
+	}
+
 	public boolean isPriceIncludesTax() {
 		Restaurant restaurant = getRestaurant();
 		if (restaurant == null) {
diff --git a/src/com/floreantpos/main/Main.java b/src/com/floreantpos/main/Main.java
old mode 100644
new mode 100755
index d55e605..d26b88a
--- a/src/com/floreantpos/main/Main.java
+++ b/src/com/floreantpos/main/Main.java
@@ -13,7 +13,8 @@ import org.apache.commons.cli.Options;
 public class Main {

 	private static final String DEVELOPMENT_MODE = "developmentMode"; //$NON-NLS-1$
-
+	private static final String ALTERNATIVE_CONFIG = "configFile"; //$NON-NLS-1$
+
 	/**
 	 * @param args
 	 * @throws Exception
@@ -21,6 +22,8 @@ public class Main {
 	public static void main(String[] args) throws Exception {
 		Options options = new Options();
 		options.addOption(DEVELOPMENT_MODE, true, "State if this is developmentMode"); //$NON-NLS-1$
+		options.addOption(ALTERNATIVE_CONFIG, true, "Set alternative config file");
+
 		CommandLineParser parser = new BasicParser();
 		CommandLine commandLine = parser.parse(options, args);
 		String optionValue = commandLine.getOptionValue(DEVELOPMENT_MODE);
@@ -31,6 +34,12 @@ public class Main {
 			application.setDevelopmentMode(Boolean.valueOf(optionValue));
 		}

+		optionValue = commandLine.getOptionValue(ALTERNATIVE_CONFIG);
+		if (optionValue != null) {
+			application.setConfigFile(String.valueOf(optionValue));
+		}
+
+
 		application.start();
 	}

Add comment
These comments are moderated so so won't be published until reviewed.