summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/process/AbstractMain.java
diff options
context:
space:
mode:
authorogattaz <olivier@gattaz.com>2014-06-05 16:51:07 +0200
committerogattaz <olivier@gattaz.com>2014-06-05 16:51:07 +0200
commit2fd193d7936084de91eae46e8c2763914d87ab71 (patch)
treeb136ed97e535f11d4b3433d16c26570c89430ce4 /src/main/java/com/c2kernel/process/AbstractMain.java
parent1225792532f77e6e8f4a9addfc0c0a6cf56e89b8 (diff)
parente73468fd08cc27aa31f76a27c916e45d5987c628 (diff)
Merge branch 'master' of ssh://dev.cccs.uwe.ac.uk:22/var/git/cristal-kernel
Diffstat (limited to 'src/main/java/com/c2kernel/process/AbstractMain.java')
-rw-r--r--src/main/java/com/c2kernel/process/AbstractMain.java71
1 files changed, 28 insertions, 43 deletions
diff --git a/src/main/java/com/c2kernel/process/AbstractMain.java b/src/main/java/com/c2kernel/process/AbstractMain.java
index 03807f0..e241ee2 100644
--- a/src/main/java/com/c2kernel/process/AbstractMain.java
+++ b/src/main/java/com/c2kernel/process/AbstractMain.java
@@ -17,6 +17,7 @@ import java.io.PrintStream;
import java.util.Enumeration;
import java.util.Properties;
+import com.c2kernel.process.resource.BadArgumentsException;
import com.c2kernel.utils.FileStringUtility;
import com.c2kernel.utils.Logger;
@@ -29,54 +30,31 @@ abstract public class AbstractMain
{
public static boolean runningAsWrapper = false;
- /**************************************************************************
- *
- **************************************************************************/
- static protected void usage()
- {
- System.out.println();
- System.out.println("USAGE: com.c2kernel.process.AbstractMain \n" +
- " -config <server/client config file> \n" +
- " [-connect <LC connect file> ] (or LocalCentre in conf)\n" +
- " [-h] [-help] \n" +
- " [-logLevel 0-19] \n" +
- " [-logFile <path to log file>]");
- Logger.die("Initialisation error");
- }
/**************************************************************************
* reading and setting input paramaters
**************************************************************************/
- public static Properties readC2KArgs( String[] args ) {
+ public static Properties readC2KArgs( String[] args ) throws BadArgumentsException {
Properties c2kProps;
Properties argProps = new Properties();
int logLevel = 0;
PrintStream logStream = System.out;
- if (args == null) return argProps;
-
int i = 0;
while( i < args.length ) {
if (args[i].startsWith("-") && args[i].length()>1) {
String key = args[i].substring(1);
- if (argProps.containsKey(key)) {
- System.err.println("Argument "+args[i]+" given twice");
- usage();
- }
+ if (argProps.containsKey(key))
+ throw new BadArgumentsException("Argument "+args[i]+" given twice");
String value = "";
if (!args[i+1].startsWith("-"))
value = args[++i];
argProps.put(key, value);
i++;
}
- else {
- System.err.println("Bad argument: "+args[i]);
- usage();
- }
- }
-
- if( argProps.containsKey("h") || argProps.containsKey("help")) {
- usage();
+ else
+ throw new BadArgumentsException("Bad argument: "+args[i]);
+
}
if (argProps.containsKey("logFile"))
@@ -84,7 +62,7 @@ abstract public class AbstractMain
logStream = new PrintStream(new FileOutputStream(argProps.getProperty("logFile"), true));
} catch (FileNotFoundException e) {
e.printStackTrace();
- System.err.println("Logfile "+argProps.getProperty("logFile")+" cannot be created");
+ throw new BadArgumentsException("Logfile "+argProps.getProperty("logFile")+" cannot be created");
}
// Set up log stream
@@ -100,9 +78,11 @@ abstract public class AbstractMain
}
String configPath = argProps.getProperty("config");
- if (configPath == null || !new File(configPath).exists()) {
- System.err.println("Config file "+configPath+" not found");
- }
+ if (configPath == null)
+ throw new BadArgumentsException("Config file not specified");
+
+ if (!new File(configPath).exists())
+ throw new BadArgumentsException("Config file "+configPath+" not found");
else
Logger.msg(0, "Config file: "+configPath);
@@ -110,17 +90,22 @@ abstract public class AbstractMain
c2kProps = FileStringUtility.loadConfigFile(argProps.getProperty("config") );
c2kProps.putAll(argProps); // args overlap config
- if (c2kProps.containsKey("connect")) {
- String connectFile = c2kProps.getProperty("connect");
+ String connectFile = c2kProps.getProperty("connect");
+ if (connectFile == null)
+ throw new BadArgumentsException("Connect file not specified");
+
+ if (!new File(connectFile).exists())
+ throw new BadArgumentsException("Connect file "+connectFile+" not found");
+ else
Logger.msg(0, "Connect file: "+connectFile);
- FileStringUtility.appendConfigFile( c2kProps, connectFile);
-
- if (!c2kProps.containsKey("LocalCentre")) {
- String connectFileName = new File(connectFile).getName();
- String centreId = connectFileName.substring(0, connectFileName.lastIndexOf(".clc"));
- c2kProps.setProperty("LocalCentre", centreId);
- }
- }
+
+ FileStringUtility.appendConfigFile( c2kProps, connectFile);
+
+ if (!c2kProps.containsKey("LocalCentre")) {
+ String connectFileName = new File(connectFile).getName();
+ String centreId = connectFileName.substring(0, connectFileName.lastIndexOf(".clc"));
+ c2kProps.setProperty("LocalCentre", centreId);
+ }
c2kProps.putAll(argProps); // args override connect file too
Logger.msg(7, "AbstractMain::standardSetUp() - readC2KArgs() DONE.");