Improved cmd options for Indexer

Change-Id: Iff3d796d96ee5d9f5fd1eeeb738272360020e6c0
diff --git a/pom.xml b/pom.xml
index 1bd0551..7d1d578 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
   <!--
       ** Server
       # Start the server with
-      $ mvn exec:java
+      $ mvn compile exec:java
 
       # Or after packaging
       $ mvn clean package
diff --git a/src/main/java/de/ids_mannheim/korap/index/Indexer.java b/src/main/java/de/ids_mannheim/korap/index/Indexer.java
index 6eb8099..1cc5221 100644
--- a/src/main/java/de/ids_mannheim/korap/index/Indexer.java
+++ b/src/main/java/de/ids_mannheim/korap/index/Indexer.java
@@ -4,12 +4,13 @@
 import java.io.*;
 import org.apache.lucene.store.MMapDirectory;
 import de.ids_mannheim.korap.KrillIndex;
+import static de.ids_mannheim.korap.util.KrillProperties.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * This is a runnable indexer tool for
- * Krill. Although the preferred index method
+ * Standalone indexer tool for Krill.
+ * Although the preferred index method
  * is using the standalone server system,
  * this tool may be more suitable for your needs
  * (especially as it is way faster).
@@ -18,10 +19,12 @@
  */
 public class Indexer {
     KrillIndex index;
-    String indexDir;
     int count;
     int commitCount;
 
+    private static String propFile = "krill.properties";
+    private static String path = null;
+
     // Init logger
     private final static Logger log = LoggerFactory.getLogger(KrillIndex.class);
 
@@ -30,22 +33,22 @@
      * Construct a new indexer object.
      * 
      * @param prop
-     *            A {@link Properties} object with
-     *            at least the following information:
-     *            <tt>krill.indexDir</tt>.
+     *            A {@link Properties} object.
      * @throws IOException
      */
     public Indexer (Properties prop) throws IOException {
-        this.indexDir = prop.getProperty("krill.indexDir");
+        if (this.path == null) {
+            this.path = prop.getProperty("krill.indexDir");
+        };
 
-        System.out.println("Index to " + this.indexDir);
+        System.out.println("Index to " + this.path);
 
         // Default to 1000 documents till the next commit
         String commitCount = prop.getProperty("krill.index.commit.count",
                 "1000");
 
         // Create a new index object based on the directory
-        this.index = new KrillIndex(new MMapDirectory(new File(indexDir)));
+        this.index = new KrillIndex(new MMapDirectory(new File(this.path)));
         this.count = 0;
         this.commitCount = Integer.parseInt(commitCount);
     };
@@ -95,7 +98,7 @@
             this.index.commit();
         }
         catch (IOException e) {
-            System.err.println("Unable to commit to index " + this.indexDir);
+            System.err.println("Unable to commit to index " + this.path);
         };
         System.out.println("done.");
     };
@@ -111,21 +114,42 @@
      * @throws IOException
      */
     public static void main (String[] argv) throws IOException {
-        Properties prop = new Properties();
 
-        // Needed at least 2 parameters
-        if (argv.length < 2) {
+        int i = 0;
+        boolean last = false;
+        for (i = 0; i < argv.length; i += 2) {
+            switch (argv[i]) {
+                case "--config":
+                case "-cfg":
+                    propFile = argv[i + 1];
+                    break;
+                case "--dir":
+                case "-d":
+                    path = argv[i + 1];
+                    break;
+            default:
+                last = true;
+                break;
+            };
 
-            String jar = new File(Indexer.class.getProtectionDomain()
-                    .getCodeSource().getLocation().getPath()).getName();
-            System.out.println("Usage: java -jar " + jar
-                    + " [propfile] [directories]*");
-            return;
+            if (last)
+                break;
         };
 
+        /*
+          String jar = new File(Indexer.class.getProtectionDomain()
+          .getCodeSource().getLocation().getPath()).getName();
+          System.out.println("Usage: java -jar " + jar
+          + "--config [propfile] [directories]*");
+          return;
+        */
+
         // Load properties
-        InputStream fr = new FileInputStream(argv[0]);
-        prop.load(fr);
+        /*
+          InputStream fr = new FileInputStream(argv[0]);
+          prop.load(fr);
+        */
+        Properties prop = loadProperties(propFile);
 
         // Get indexer object
         Indexer ki = new Indexer(prop);
@@ -134,7 +158,7 @@
         System.out.println();
 
         // Iterate over list of directories
-        for (String arg : Arrays.copyOfRange(argv, 1, argv.length)) {
+        for (String arg : Arrays.copyOfRange(argv, i, argv.length)) {
             File f = new File(arg);
             if (f.isDirectory())
                 ki.parse(f);
diff --git a/src/main/java/de/ids_mannheim/korap/server/Node.java b/src/main/java/de/ids_mannheim/korap/server/Node.java
index b1fe9e5..19554e4 100644
--- a/src/main/java/de/ids_mannheim/korap/server/Node.java
+++ b/src/main/java/de/ids_mannheim/korap/server/Node.java
@@ -68,28 +68,28 @@
      * 
      * @return Grizzly HTTP server.
      */
-    public static HttpServer startServer (String[] args) {
+    public static HttpServer startServer (String[] argv) {
         LogManager.getLogManager().reset();
         SLF4JBridgeHandler.install();
 
 
-        for (int i = 0; i < args.length; i += 2) {
-            switch (args[i]) {
+        for (int i = 0; i < argv.length; i += 2) {
+            switch (argv[i]) {
                 case "--config":
                 case "-cfg":
-                    propFile = args[i + 1];
+                    propFile = argv[i + 1];
                     break;
                 case "--port":
                 case "-p":
-                    port = Integer.valueOf(args[i + 1]);
+                    port = Integer.valueOf(argv[i + 1]);
                     break;
                 case "--name":
                 case "-n":
-                    name = args[i + 1];
+                    name = argv[i + 1];
                     break;
                 case "--dir":
                 case "-d":
-                    path = args[i + 1];
+                    path = argv[i + 1];
                     break;
             };
         };
@@ -149,17 +149,17 @@
      * 
      * </dl>
      * 
-     * @param args
+     * @param argv
      *            No special arguments required. Supported arguments
      *            are listed above.
      * @throws IOException
      */
-    public static void main (String[] args) throws IOException {
+    public static void main (String[] argv) throws IOException {
 
 
         // WADL available at BASE_URI + application.wadl
         // Start the server with krill properties or given defaults
-        final HttpServer server = startServer(args);
+        final HttpServer server = startServer(argv);
 
         // Establish shutdown hook
         Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {