Philipp Bauch 6 лет назад
Родитель
Сommit
bf911c1a79
2 измененных файлов с 535 добавлено и 498 удалено
  1. 372 341
      jplag/src/main/java/jplag/options/CommandLineOptions.java
  2. 163 157
      jplag/src/main/java/jplag/options/Options.java

+ 372 - 341
jplag/src/main/java/jplag/options/CommandLineOptions.java

@@ -14,75 +14,80 @@ import jplag.Language;
 import jplag.Program;
 import jplag.Program;
 
 
 public class CommandLineOptions extends Options {
 public class CommandLineOptions extends Options {
-    private String[] args;
 
 
-    public String[] getArgs() {
-        return args;
-    }
+  private String[] args;
 
 
-    public CommandLineOptions(String[] args) throws jplag.ExitException {
-        this(args, null);
-    }
+  public String[] getArgs() {
+    return args;
+  }
 
 
-    public CommandLineOptions(String[] args, String cmdInString)
-            throws jplag.ExitException {
-        this.args = args;
+  public CommandLineOptions(String[] args) throws jplag.ExitException {
+    this(args, null);
+  }
 
 
-        initialize(args);
+  public CommandLineOptions(String[] args, String cmdInString)
+      throws jplag.ExitException {
+    this.args = args;
 
 
-        // @Changed by Moritz Kroll 26.02.2005
-        // set to default language if not specified
-        // changed by Emeric 22-03-05 commandLine set to be compatible with
-        // the web service requirements
+    initialize(args);
 
 
-        if (languageName == null)
-            languageName = languages[0];
-        if (cmdInString != null)
-            commandLine = cmdInString;
-    }
+    // @Changed by Moritz Kroll 26.02.2005
+    // set to default language if not specified
+    // changed by Emeric 22-03-05 commandLine set to be compatible with
+    // the web service requirements
 
 
-    private void initialize(String[] args) throws jplag.ExitException {
-        int i = 0;
-        try {
-            for (i = 0; i < args.length; i++)
-                if (args[i].startsWith("-"))
-                    i = scanOption(args, i);
-                else
-                    this.root_dir = args[i];
-        }
-		catch (NumberFormatException e) {
-            throw new jplag.ExitException("Bad parameter for option '"
-                    + args[i] + "': " + args[i + 1] + " is not a "
-                    + "positive integer!", ExitException.BAD_PARAMETER);
+      if (languageName == null) {
+          languageName = languages[0];
+      }
+      if (cmdInString != null) {
+          commandLine = cmdInString;
+      }
+  }
+
+  private void initialize(String[] args) throws jplag.ExitException {
+    int i = 0;
+    try {
+        for (i = 0; i < args.length; i++) {
+            if (args[i].startsWith("-")) {
+                i = scanOption(args, i);
+            } else {
+                this.root_dir = args[i];
+            }
         }
         }
-        if (args.length == 0) {
-            usage();
-        } else {
-            for (i = 0; i < args.length; i++)
-                this.commandLine += args[i] + " ";
+    } catch (NumberFormatException e) {
+      throw new jplag.ExitException("Bad parameter for option '"
+          + args[i] + "': " + args[i + 1] + " is not a "
+          + "positive integer!", ExitException.BAD_PARAMETER);
+    }
+    if (args.length == 0) {
+      usage();
+    } else {
+        for (i = 0; i < args.length; i++) {
+            this.commandLine += args[i] + " ";
         }
         }
-
-        System.gc();
     }
     }
 
 
-    private boolean scanOption(String arg) throws jplag.ExitException {
-        if (arg.equals("-s")) {
-            this.read_subdirs = true;
-        } else if (arg.equals("-external")) { // hidden option!
-            System.out.println("External search activated!");
-            this.externalSearch = true;
-        } else if (arg.equals("-skipparse")) { // hidden option!
-            System.out.println("Skip parse activated!");
-            this.skipParse = true;
-        } else if (arg.equals("-diff")) { // hidden option!
-            System.out.println("Diff-Report activated!");
-            this.diff_report = true;
-        } else if (arg.equals("-L")) { // hidden option!
-            printAllLanguages();
+    System.gc();
+  }
 
 
-        } else if (arg.startsWith("-v") && arg.length() > 2) {
-            for (int i = 2; i < arg.length(); i++)
-                switch (arg.charAt(i)) {
+  private boolean scanOption(String arg) throws jplag.ExitException {
+    if (arg.equals("-s")) {
+      this.read_subdirs = true;
+    } else if (arg.equals("-external")) { // hidden option!
+      System.out.println("External search activated!");
+      this.externalSearch = true;
+    } else if (arg.equals("-skipparse")) { // hidden option!
+      System.out.println("Skip parse activated!");
+      this.skipParse = true;
+    } else if (arg.equals("-diff")) { // hidden option!
+      System.out.println("Diff-Report activated!");
+      this.diff_report = true;
+    } else if (arg.equals("-L")) { // hidden option!
+      printAllLanguages();
+
+    } else if (arg.startsWith("-v") && arg.length() > 2) {
+        for (int i = 2; i < arg.length(); i++) {
+            switch (arg.charAt(i)) {
                 case 'q':
                 case 'q':
                     this.verbose_quiet = true;
                     this.verbose_quiet = true;
                     break;
                     break;
@@ -104,309 +109,335 @@ public class CommandLineOptions extends Options {
                     break;
                     break;
                 default:
                 default:
                     return false;
                     return false;
-                }
-        } else
-            return false;
-        return true;
+            }
+        }
+    } else {
+        return false;
     }
     }
+    return true;
+  }
 
 
-    private boolean found1 = false;
+  private boolean found1 = false;
 
 
 
 
-    private int scanOption(String[] args, int i)
-		throws NumberFormatException, jplag.ExitException
-    {
-        String arg = args[i];
-        if (arg.equals("-S") && i + 1 < args.length) {
-            sub_dir = args[i + 1];
-            i++;
-        } else if (arg.equals("-o") && i + 1 < args.length) {
-            output_file = args[i + 1];
-            i++;
-        } else if (arg.equals("-bc") && i + 1 < args.length) {
-			// Will be validated later as root_dir is not set yet
-            useBasecode = true;
-            basecode = args[i + 1];
-            i++;
-        } else if (arg.equals("-d") && i + 1 < args.length) {
-            // original directory - when used in the server environment.
-            debugParser = true;
-            original_dir = args[i + 1];
-            i++;
-        } else if (arg.equals("--") && i + 1 < args.length) {
-            root_dir = args[i + 1];
-            i++;
-        } else if (arg.equals("-x") && i + 1 < args.length) {
-            exclude_file = args[i + 1];
-            i++;
-        } else if (arg.equals("-clang") && i + 1 < args.length) {
-            countryTag = args[i+1];
-            countryTag.toLowerCase();
-            i++;
-        } else if (arg.equals("-i") && i + 1 < args.length) {
-            include_file = args[i + 1];
-            i++;
-        } else if (arg.equals("-t") && i + 1 < args.length) {
-            min_token_match = Integer.parseInt(args[i + 1]);
-            if (min_token_match < 1) {
-                throw new jplag.ExitException(
-                    "Illegal value: Minimum token length is less or " +
-                    "equal zero!",ExitException.BAD_SENSITIVITY_OF_COMPARISON);
-            }
-            min_token_match_set = true;
-            i++;
-        } else if (arg.equals("-m") && i + 1 < args.length) {
-            String tmp = args[i + 1];
-                    int index;
-            if ((index = tmp.indexOf("%")) != -1) {
-                store_percent = true;
-                tmp = tmp.substring(0, index);
-            }
-            if ((store_matches = Integer.parseInt(tmp)) < 0)
-                throw new NumberFormatException();
-            if (store_matches > MAX_RESULT_PAIRS)
-                store_matches = MAX_RESULT_PAIRS;
-            i++;
-        } else if (arg.equals("-r") && i + 1 < args.length) {
-            result_dir = args[i + 1];
-            i++;
-        } else if (arg.equals("-l") && i + 1 < args.length) {
-			// Will be validated later when the language routines are chosen
-            languageIsFound = true;
-            languageName = args[i + 1].toLowerCase();
-            i++;
-        } else if (arg.equals("-p") && i + 1 < args.length) {
-            String suffixstr = args[i + 1];          
+  private int scanOption(String[] args, int i)
+      throws NumberFormatException, jplag.ExitException {
+    String arg = args[i];
+    if (arg.equals("-S") && i + 1 < args.length) {
+      sub_dir = args[i + 1];
+      i++;
+    } else if (arg.equals("-o") && i + 1 < args.length) {
+      output_file = args[i + 1];
+      i++;
+    } else if (arg.equals("-bc") && i + 1 < args.length) {
+      // Will be validated later as root_dir is not set yet
+      useBasecode = true;
+      basecode = args[i + 1];
+      i++;
+    } else if (arg.equals("-d") && i + 1 < args.length) {
+      // original directory - when used in the server environment.
+      debugParser = true;
+      original_dir = args[i + 1];
+      i++;
+    } else if (arg.equals("--") && i + 1 < args.length) {
+      root_dir = args[i + 1];
+      i++;
+    } else if (arg.equals("-x") && i + 1 < args.length) {
+      exclude_file = args[i + 1];
+      i++;
+    } else if (arg.equals("-clang") && i + 1 < args.length) {
+      countryTag = args[i + 1];
+      countryTag.toLowerCase();
+      i++;
+    } else if (arg.equals("-i") && i + 1 < args.length) {
+      include_file = args[i + 1];
+      i++;
+    } else if (arg.equals("-t") && i + 1 < args.length) {
+      min_token_match = Integer.parseInt(args[i + 1]);
+      if (min_token_match < 1) {
+        throw new jplag.ExitException(
+            "Illegal value: Minimum token length is less or " +
+                "equal zero!", ExitException.BAD_SENSITIVITY_OF_COMPARISON);
+      }
+      min_token_match_set = true;
+      i++;
+    } else if (arg.equals("-m") && i + 1 < args.length) {
+      String tmp = args[i + 1];
+      int index;
+      if ((index = tmp.indexOf("%")) != -1) {
+        store_percent = true;
+        tmp = tmp.substring(0, index);
+      }
+        if ((store_matches = Integer.parseInt(tmp)) < 0) {
+            throw new NumberFormatException();
+        }
+        if (store_matches > MAX_RESULT_PAIRS) {
+            store_matches = MAX_RESULT_PAIRS;
+        }
+      i++;
+    } else if (arg.equals("-r") && i + 1 < args.length) {
+      result_dir = args[i + 1];
+      i++;
+    } else if (arg.equals("-l") && i + 1 < args.length) {
+      // Will be validated later when the language routines are chosen
+      languageIsFound = true;
+      languageName = args[i + 1].toLowerCase();
+      i++;
+    } else if (arg.equals("-p") && i + 1 < args.length) {
+      String suffixstr = args[i + 1];
+      if (suffixstr.equals("")) {
+        i++;
+      } else {
+        Vector<String> vsuffies = new Vector<String>();
+        StringTokenizer st = new StringTokenizer(suffixstr, ",");
+        while (st.hasMoreTokens()) {
+          suffixstr = st.nextToken();
+          suffixstr.trim();
             if (suffixstr.equals("")) {
             if (suffixstr.equals("")) {
-            	i++;
-            }
-            else {
-                Vector<String> vsuffies = new Vector<String>();
-                StringTokenizer st = new StringTokenizer(suffixstr, ",");
-                while (st.hasMoreTokens()) {
-    				suffixstr = st.nextToken();
-    				suffixstr.trim();
-                    if (suffixstr.equals(""))
-                        continue;
-                    vsuffies.addElement(suffixstr);
-                }
-                suffixes = new String[vsuffies.size()];
-                vsuffies.copyInto(suffixes);
-                suffixes_set = true;
-                i++;
+                continue;
             }
             }
-        } else if (arg.equals("-f") && i + 1 < args.length && this.exp) {
-            this.filter = new jplag.filter.Filter(args[i + 1]);
-            this.filtername = args[i + 1];
-            i++; // EXPERIMENT!!
-        } else if (arg.equals("-filter") && i + 1 < args.length) {
-            System.out.println("Filter activated!");
-            jplag.text.Parser parser = new jplag.text.Parser();
-            // This Parser object doesn't have its "program" attribute
-			// initialized but the initializeFilter method doesn't use it anyway
-            try {
-                parser.initializeFilter(args[i + 1]);
-            } catch (java.io.FileNotFoundException e) {
-                throw new jplag.ExitException("Filter file not found!",
-						ExitException.BAD_PARAMETER);
+          vsuffies.addElement(suffixstr);
+        }
+        suffixes = new String[vsuffies.size()];
+        vsuffies.copyInto(suffixes);
+        suffixes_set = true;
+        i++;
+      }
+    } else if (arg.equals("-f") && i + 1 < args.length && this.exp) {
+      this.filter = new jplag.filter.Filter(args[i + 1]);
+      this.filtername = args[i + 1];
+      i++; // EXPERIMENT!!
+    } else if (arg.equals("-filter") && i + 1 < args.length) {
+      System.out.println("Filter activated!");
+      jplag.text.Parser parser = new jplag.text.Parser();
+      // This Parser object doesn't have its "program" attribute
+      // initialized but the initializeFilter method doesn't use it anyway
+      try {
+        parser.initializeFilter(args[i + 1]);
+      } catch (java.io.FileNotFoundException e) {
+        throw new jplag.ExitException("Filter file not found!",
+            ExitException.BAD_PARAMETER);
+      }
+      i++;
+    } else if (arg.equals("-compmode") && i + 1 < args.length) {
+      comparisonMode = Integer.parseInt(args[i + 1]);
+        if (comparisonMode < COMPMODE_NORMAL || comparisonMode > COMPMODE_REVISION) {
+            throw new jplag.ExitException("Illegal comparison mode: \"" + comparisonMode + "\"");
+        }
+      i++;
+    } else if (arg.equals("-compare") && i + 1 < args.length) {
+        if ((this.compare = Integer.parseInt(args[i + 1])) < 0) {
+            throw new NumberFormatException();
+        }
+      System.out.println("Special comparison activated. Parameter: "
+          + this.compare);
+      i++;
+    } else if (arg.equals("-clustertype") && i + 1 < args.length) {
+      this.clustering = true;
+      String tmp = args[i + 1].toLowerCase();
+        if (tmp.equals("min")) {
+            this.clusterType = MIN_CLUSTER;
+        } else if (tmp.equals("max")) {
+            this.clusterType = MAX_CLUSTER;
+        } else if (tmp.equals("avr")) {
+            this.clusterType = AVR_CLUSTER;
+        } else {
+            throw new jplag.ExitException("Illegal clustertype: \"" + tmp
+                + "\"\nAvailable types are 'min', 'max' and 'avr'!");
+        }
+
+      System.out.println("Clustering activated; type: "
+          + args[i + 1].toUpperCase());
+      i++;
+    } else if (arg.equals("-threshold") && i + 1 < args.length) {
+      if (args[i + 1].equals("")) {
+        throw new jplag.ExitException("Threshold-list is empty!");
+      }
+      try {
+        int number = 0;
+        String help;
+        StringTokenizer st = new StringTokenizer(args[i + 1], ",");
+        while (st.hasMoreTokens()) {
+          help = st.nextToken();
+          help.trim();
+            if (help.equals("")) {
+                continue;
             }
             }
-            i++;
-        } else if (arg.equals("-compmode") && i + 1 < args.length) {
-            comparisonMode = Integer.parseInt(args[i + 1]);
-            if (comparisonMode < COMPMODE_NORMAL || comparisonMode > COMPMODE_REVISION)
-                throw new jplag.ExitException("Illegal comparison mode: \"" + comparisonMode + "\"");
-            i++;
-        } else if (arg.equals("-compare") && i + 1 < args.length) {
-            if ((this.compare = Integer.parseInt(args[i + 1])) < 0)
+            if (Float.parseFloat(help) < 0) {
                 throw new NumberFormatException();
                 throw new NumberFormatException();
-            System.out.println("Special comparison activated. Parameter: "
-                    + this.compare);
-            i++;
-        } else if (arg.equals("-clustertype") && i + 1 < args.length) {
-            this.clustering = true;
-            String tmp = args[i + 1].toLowerCase();
-            if (tmp.equals("min"))
-                this.clusterType = MIN_CLUSTER;
-            else if (tmp.equals("max"))
-                this.clusterType = MAX_CLUSTER;
-            else if (tmp.equals("avr"))
-                this.clusterType = AVR_CLUSTER;
-            else 
-                throw new jplag.ExitException("Illegal clustertype: \"" + tmp
-                        + "\"\nAvailable types are 'min', 'max' and 'avr'!");
-			
-            System.out.println("Clustering activated; type: "
-                    + args[i + 1].toUpperCase());
-            i++;
-        } else if (arg.equals("-threshold") && i + 1 < args.length) {
-            if (args[i + 1].equals("")) {
-                throw new jplag.ExitException("Threshold-list is empty!");
             }
             }
-            try {
-                int number = 0;
-                String help;
-                StringTokenizer st = new StringTokenizer(args[i + 1], ",");
-                while (st.hasMoreTokens()) {
-                    help = st.nextToken();
-                    help.trim();
-                    if (help.equals(""))
-                        continue;
-                    if (Float.parseFloat(help) < 0)
-                        throw new NumberFormatException();
-                    number++;
-                }
-                if (number == 0) {
-                    throw new jplag.ExitException("No threshold given!");
-                }
-                this.threshold = new float[number];
-                st = new StringTokenizer(args[i + 1], ",");
-                number = 0;
-                while (st.hasMoreTokens()) {
-                    help = st.nextToken();
-                    help.trim();
-                    if (help.equals(""))
-                        continue;
-                    this.threshold[number++] = Float.parseFloat(help);
-                }
-            } catch (NoSuchElementException e) {
-                throw new jplag.ExitException(
-                        "Error parsing '-threshold' option!");
-            }
-            System.out.print("Thresholds: ");
-            for (int x = 0; x < this.threshold.length; x++)
-                System.out.print(this.threshold[x] + " ");
-            System.out.println();
-            i++;
-        } else if (arg.equals("-themewords") && i + 1 < args.length) {
-            if (args[i + 1].equals("")) {
-                throw new jplag.ExitException("Themeword-list is empty!");
+          number++;
+        }
+        if (number == 0) {
+          throw new jplag.ExitException("No threshold given!");
+        }
+        this.threshold = new float[number];
+        st = new StringTokenizer(args[i + 1], ",");
+        number = 0;
+        while (st.hasMoreTokens()) {
+          help = st.nextToken();
+          help.trim();
+            if (help.equals("")) {
+                continue;
             }
             }
-            try {
-                int number = 0;
-                String help;
-                StringTokenizer st = new StringTokenizer(args[i + 1], ",");
-                while (st.hasMoreTokens()) {
-                    help = st.nextToken();
-                    help.trim();
-                    if (help.equals(""))
-                        continue;
-                    if (Integer.parseInt(help) < 0)
-                        throw new NumberFormatException();
-                    number++;
-                }
-                if (number == 0) {
-                    throw new jplag.ExitException("No themeword given!");
-                }
-                this.themewords = new int[number];
-                st = new StringTokenizer(args[i + 1], ",");
-                number = 0;
-                while (st.hasMoreTokens()) {
-                    help = st.nextToken();
-                    help.trim();
-                    if (help.equals(""))
-                        continue;
-                    this.themewords[number++] = Integer.parseInt(help);
-                }
-            } catch (NoSuchElementException e) {
-                throw new jplag.ExitException(
-                        "Error parsing '-themewords' option!");
+          this.threshold[number++] = Float.parseFloat(help);
+        }
+      } catch (NoSuchElementException e) {
+        throw new jplag.ExitException(
+            "Error parsing '-threshold' option!");
+      }
+      System.out.print("Thresholds: ");
+        for (int x = 0; x < this.threshold.length; x++) {
+            System.out.print(this.threshold[x] + " ");
+        }
+      System.out.println();
+      i++;
+    } else if (arg.equals("-themewords") && i + 1 < args.length) {
+      if (args[i + 1].equals("")) {
+        throw new jplag.ExitException("Themeword-list is empty!");
+      }
+      try {
+        int number = 0;
+        String help;
+        StringTokenizer st = new StringTokenizer(args[i + 1], ",");
+        while (st.hasMoreTokens()) {
+          help = st.nextToken();
+          help.trim();
+            if (help.equals("")) {
+                continue;
             }
             }
-            System.out.print("Themewords: ");
-            for (int x = 0; x < this.themewords.length; x++)
-                System.out.print(this.themewords[x] + " ");
-            System.out.println();
-            i++;
-        } else if (arg.equals("-title") && i+1 < args.length) {
-            if (args[i + 1].equals("")) {
-                throw new jplag.ExitException("Title is empty!");
+            if (Integer.parseInt(help) < 0) {
+                throw new NumberFormatException();
             }
             }
-            this.title = args[i + 1];
-            i++;
-        } else if (arg.equals("-c") && i + 2 < args.length){
-            this.fileListMode = true;
-            while (i + 1 < args.length){
-                this.fileList.add(args[i + 1]);
-                i++;
+          number++;
+        }
+        if (number == 0) {
+          throw new jplag.ExitException("No themeword given!");
+        }
+        this.themewords = new int[number];
+        st = new StringTokenizer(args[i + 1], ",");
+        number = 0;
+        while (st.hasMoreTokens()) {
+          help = st.nextToken();
+          help.trim();
+            if (help.equals("")) {
+                continue;
             }
             }
-        } else if (!scanOption(arg))
-            throw new jplag.ExitException("Unknown option: " + arg,
-                    ExitException.BAD_PARAMETER);
+          this.themewords[number++] = Integer.parseInt(help);
+        }
+      } catch (NoSuchElementException e) {
+        throw new jplag.ExitException(
+            "Error parsing '-themewords' option!");
+      }
+      System.out.print("Themewords: ");
+        for (int x = 0; x < this.themewords.length; x++) {
+            System.out.print(this.themewords[x] + " ");
+        }
+      System.out.println();
+      i++;
+    } else if (arg.equals("-title") && i + 1 < args.length) {
+      if (args[i + 1].equals("")) {
+        throw new jplag.ExitException("Title is empty!");
+      }
+      this.title = args[i + 1];
+      i++;
+    } else if (arg.equals("-c") && i + 2 < args.length) {
+      this.fileListMode = true;
+      while (i + 1 < args.length) {
+        this.fileList.add(args[i + 1]);
+        i++;
+      }
+    } else if (!scanOption(arg)) {
+        throw new jplag.ExitException("Unknown option: " + arg,
+            ExitException.BAD_PARAMETER);
+    }
 
 
-        if (!languageIsFound && i >= args.length - 2)
-            throw new jplag.ExitException("No language found...",
-                    ExitException.BAD_LANGUAGE_ERROR);
+      if (!languageIsFound && i >= args.length - 2) {
+          throw new jplag.ExitException("No language found...",
+              ExitException.BAD_LANGUAGE_ERROR);
+      }
 
 
-        return i;
-    }
+    return i;
+  }
+
+  public void initializeSecondStep(Program program) throws jplag.ExitException {
 
 
-	public void initializeSecondStep(Program program) throws jplag.ExitException {
+      for (int j = 0; j < languages.length - 1; j += 2) {
+          if (languageName.equals(languages[j])) {
+              try {
+                  Constructor<?>[] languageConstructors = Class.forName(languages[j + 1])
+                      .getDeclaredConstructors();
+                  Constructor<?> cons = languageConstructors[0];
+                  Object[] ob = {program};
+                  // All Language have to have a program as Constructor
+                  // Parameter
+                  // ->public Language(ProgramI prog)
+                  Language tmp = (Language) cons.newInstance(ob);
+                  this.language = tmp;
+                  System.out
+                      .println(
+                          "Language accepted: " + tmp.name() + "\nCommand line: "
+                              + this.commandLine);
+                  found1 = true;
+              } catch (ClassNotFoundException e) {
+                  System.out.println(e.getMessage());
+              } catch (IllegalAccessException e) {
+                  System.out.println(e.getMessage());
+              } catch (InstantiationException e) {
+                  System.out.println(e.getMessage());
+              } catch (Exception e) {
+                  e.printStackTrace();
+                  throw new jplag.ExitException("Illegal value: Language instantiation failed",
+                      ExitException.BAD_LANGUAGE_ERROR);
+              }
+          }
+      }
+    if (!found1) {
+      throw new jplag.ExitException(
+          "Illegal value: Language instantiation failed: Unknown language \"" + languageName + "\"",
+          ExitException.BAD_LANGUAGE_ERROR);
+    }
 
 
-		for (int j = 0; j < languages.length - 1; j += 2)
-			if (languageName.equals(languages[j]))
-				try {
-					Constructor<?>[] languageConstructors = Class.forName(languages[j + 1]).getDeclaredConstructors();
-					Constructor<?> cons = languageConstructors[0];
-					Object[] ob = { program };
-					// All Language have to have a program as Constructor
-					// Parameter
-					// ->public Language(ProgramI prog)
-					Language tmp = (Language) cons.newInstance(ob);
-					this.language = tmp;
-					System.out.println("Language accepted: " + tmp.name() + "\nCommand line: " + this.commandLine);
-					found1 = true;
-				} catch (ClassNotFoundException e) {
-					System.out.println(e.getMessage());
-				} catch (IllegalAccessException e) {
-					System.out.println(e.getMessage());
-				} catch (InstantiationException e) {
-					System.out.println(e.getMessage());
-				} catch (Exception e) {
-					e.printStackTrace();
-					throw new jplag.ExitException("Illegal value: Language instantiation failed", ExitException.BAD_LANGUAGE_ERROR);
-				}
-		if (!found1) {
-			throw new jplag.ExitException("Illegal value: Language instantiation failed: Unknown language \"" + languageName + "\"",
-					ExitException.BAD_LANGUAGE_ERROR);
-		}
+    // defaults
+      if (!min_token_match_set) {
+          this.min_token_match = this.language.min_token_match();
+      }
+      if (!suffixes_set) {
+          this.suffixes = this.language.suffixes();
+      }
+    checkBasecodeOption();
+  }
 
 
-		// defaults
-		if (!min_token_match_set)
-			this.min_token_match = this.language.min_token_match();
-		if (!suffixes_set)
-			this.suffixes = this.language.suffixes();
-		checkBasecodeOption();
-	}
-	
-    /**
-     * This method checks whether the basecode directory value is valid
-     */
-    private void checkBasecodeOption() throws jplag.ExitException {
-        if (useBasecode) {
-            if (basecode == null || basecode.equals("")) {
-				throw new ExitException("Basecode option used but none " +
-						"specified!",ExitException.BAD_PARAMETER);
-            }
-            String baseC = root_dir + File.separator + basecode;
-            if (!(new File(root_dir)).exists()) {
-				throw new ExitException("Root directory \"" + root_dir
-						+ "\" doesn't exist!",ExitException.BAD_PARAMETER);
-            }
-            File f = new File(baseC);
-            if (!f.exists()) {	// Basecode dir doesn't exist.
-				throw new ExitException("Basecode directory \"" + baseC
-						+ "\" doesn't exist!",ExitException.BAD_PARAMETER);
-            }
-            if(sub_dir != null && sub_dir.length()!=0) {
-            	f = new File(baseC, sub_dir);
-            	if(!f.exists()) {
-            		throw new ExitException("Basecode directory doesn't contain"
-            				+ " the subdirectory \"" + sub_dir + "\"!",
-            				ExitException.BAD_PARAMETER);
-            	}
-            }
-            System.out.println("Basecode directory \"" + baseC
-            		+ "\" will be used");
+  /**
+   * This method checks whether the basecode directory value is valid
+   */
+  private void checkBasecodeOption() throws jplag.ExitException {
+    if (useBasecode) {
+      if (basecode == null || basecode.equals("")) {
+        throw new ExitException("Basecode option used but none " +
+            "specified!", ExitException.BAD_PARAMETER);
+      }
+      String baseC = root_dir + File.separator + basecode;
+      if (!(new File(root_dir)).exists()) {
+        throw new ExitException("Root directory \"" + root_dir
+            + "\" doesn't exist!", ExitException.BAD_PARAMETER);
+      }
+      File f = new File(baseC);
+      if (!f.exists()) {  // Basecode dir doesn't exist.
+        throw new ExitException("Basecode directory \"" + baseC
+            + "\" doesn't exist!", ExitException.BAD_PARAMETER);
+      }
+      if (sub_dir != null && sub_dir.length() != 0) {
+        f = new File(baseC, sub_dir);
+        if (!f.exists()) {
+          throw new ExitException("Basecode directory doesn't contain"
+              + " the subdirectory \"" + sub_dir + "\"!",
+              ExitException.BAD_PARAMETER);
         }
         }
+      }
+      System.out.println("Basecode directory \"" + baseC
+          + "\" will be used");
     }
     }
+  }
 
 
 }
 }

+ 163 - 157
jplag/src/main/java/jplag/options/Options.java

@@ -4,7 +4,7 @@
  * all type of options will be derivated from the abstract class Options. A simple implementation
  * all type of options will be derivated from the abstract class Options. A simple implementation
  * is for exmaple a class that initialize commandline options.
  * is for exmaple a class that initialize commandline options.
  *
  *
- * 
+ *
  */
  */
 package jplag.options;
 package jplag.options;
 
 
@@ -17,232 +17,238 @@ import java.util.List;
 
 
 /**
 /**
  * @Author Emeric Kwemou 30.01.2005
  * @Author Emeric Kwemou 30.01.2005
- *  
  */
  */
 public abstract class Options {
 public abstract class Options {
-	protected boolean suffixes_set = false;
 
 
-	protected boolean min_token_match_set = false;
+  protected boolean suffixes_set = false;
+
+  protected boolean min_token_match_set = false;
+
+  /**
+   * The available languages - the first language in the array is the default language.
+   */
+  protected static String[] languages = {// @formatter:off
+      "java19", "jplag.java19.Language",
+      "java17", "jplag.java17.Language",
+      "java15", "jplag.java15.Language",
+      "java15dm", "jplag.java15.LanguageWithDelimitedMethods",
+      "java12", "jplag.java.Language",
+      "java11", "jplag.javax.Language",
+      "python3", "jplag.python3.Language",
+      "c/c++", "jplag.cpp.Language",
+      "c#-1.2", "jplag.csharp.Language",
+      "char", "jplag.chars.Language",
+      "text", "jplag.text.Language",
+      "scheme", "jplag.scheme.Language",
+  };// @formatter:on
 
 
-	/**
-	 * The available languages - the first language in the array is the default language.
-	 */
-	protected static String[] languages = {// @formatter:off
-			"java19", "jplag.java19.Language",
-			"java17", "jplag.java17.Language",
-			"java15", "jplag.java15.Language",
-			"java15dm", "jplag.java15.LanguageWithDelimitedMethods",
-			"java12", "jplag.java.Language",
-			"java11", "jplag.javax.Language",
-			"python3","jplag.python3.Language",
-			"c/c++", "jplag.cpp.Language",
-			"c#-1.2", "jplag.csharp.Language",
-			"char", "jplag.chars.Language",
-			"text", "jplag.text.Language",
-			"scheme", "jplag.scheme.Language",
-			};// @formatter:on
+  public static final int MIN_CLUSTER = 1;
+  public static final int MAX_CLUSTER = 2;
+  public static final int AVR_CLUSTER = 3;
 
 
-	public static final int MIN_CLUSTER = 1;
-	public static final int MAX_CLUSTER = 2;
-	public static final int AVR_CLUSTER = 3;
+  // Program OPTIONS
+  public boolean verbose_quiet = false;
 
 
-	// Program OPTIONS
-	public boolean verbose_quiet = false;
+  public boolean verbose_long = false;
 
 
-	public boolean verbose_long = false;
+  public boolean verbose_parser = false;
 
 
-	public boolean verbose_parser = false;
+  public boolean verbose_details = false;
 
 
-	public boolean verbose_details = false;
+  // use to detect a language in the initilalisation
+  public boolean languageIsFound = false;
 
 
-	// use to detect a language in the initilalisation
-	public boolean languageIsFound = false;
+  public String sub_dir = null;
 
 
-	public String sub_dir = null;
+  public String root_dir = null;
 
 
-	public String root_dir = null;
+  public String original_dir = null;
 
 
-	public String original_dir = null;
-	
-	public String title = "";
+  public String title = "";
 
 
-	public String output_file = null;
+  public String output_file = null;
 
 
-	public String exclude_file = null;
+  public String exclude_file = null;
 
 
-	public String include_file = null;
+  public String include_file = null;
 
 
-	public boolean read_subdirs = false;
+  public boolean read_subdirs = false;
 
 
-	public int store_matches = 30;
+  public int store_matches = 30;
 
 
-	public boolean store_percent = false; // is the number "store_matches"
+  public boolean store_percent = false; // is the number "store_matches"
 
 
-	// a percentage?
-	public static final int MAX_RESULT_PAIRS = 1000;
+  // a percentage?
+  public static final int MAX_RESULT_PAIRS = 1000;
 
 
-	public String result_dir = "result";
+  public String result_dir = "result";
 
 
-	public static final int COMPMODE_NORMAL = 0;
-	public static final int COMPMODE_REVISION = 1;
+  public static final int COMPMODE_NORMAL = 0;
+  public static final int COMPMODE_REVISION = 1;
 
 
-	public int comparisonMode = COMPMODE_NORMAL;
+  public int comparisonMode = COMPMODE_NORMAL;
 
 
-	public int min_token_match;
+  public int min_token_match;
 
 
-	public String[] suffixes;
+  public String[] suffixes;
 
 
-	public boolean exp = false; // EXPERIMENT
+  public boolean exp = false; // EXPERIMENT
 
 
-	public boolean diff_report = false; // special "diff" report
+  public boolean diff_report = false; // special "diff" report
 
 
-	public jplag.filter.Filter filter = null;
+  public jplag.filter.Filter filter = null;
 
 
-	public String filtername = "."; // == no filter
+  public String filtername = "."; // == no filter
 
 
-	public String basecode = "";
+  public String basecode = "";
 
 
-	public String commandLine = "";
+  public String commandLine = "";
 
 
-	// "Ronald Kostoff" specials
-	public boolean externalSearch = false;
+  // "Ronald Kostoff" specials
+  public boolean externalSearch = false;
 
 
-	public boolean skipParse = false;
+  public boolean skipParse = false;
 
 
-	public boolean clustering = false;
+  public boolean clustering = false;
 
 
-	public boolean useBasecode = false;
+  public boolean useBasecode = false;
 
 
-	public String languageName = null;
+  public String languageName = null;
 
 
-	public String countryTag = "en";
+  public String countryTag = "en";
 
 
-	public float[] threshold = null;
+  public float[] threshold = null;
 
 
-	public int[] themewords = { 15 };
+  public int[] themewords = {15};
 
 
-	public int clusterType = 0;
+  public int clusterType = 0;
 
 
-	public int compare = 0; // 0 = deactivated
+  public int compare = 0; // 0 = deactivated
 
 
-	public SimilarityMatrix similarity = null;
+  public SimilarityMatrix similarity = null;
 
 
-	public jplag.Language language;
+  public jplag.Language language;
 
 
-	//compare list of files options
-	public boolean fileListMode = false;
+  //compare list of files options
+  public boolean fileListMode = false;
 
 
-	public List<String> fileList = new ArrayList<String>();
+  public List<String> fileList = new ArrayList<String>();
 
 
-	// "FINAL" OPTIONS
-	public boolean debugParser = false;
+  // "FINAL" OPTIONS
+  public boolean debugParser = false;
 
 
-	// END OPTIONS
+  // END OPTIONS
 
 
-	public static final int PARSING = 100;
-	public static final int PARSING_WARNINGS = 101;
-	public static final int COMPARING = 200;
-	public static final int GENERATING_RESULT_FILES = 250;
-	public static final int SUBMISSION_ABORTED = 405;
+  public static final int PARSING = 100;
+  public static final int PARSING_WARNINGS = 101;
+  public static final int COMPARING = 200;
+  public static final int GENERATING_RESULT_FILES = 250;
+  public static final int SUBMISSION_ABORTED = 405;
 
 
-	private int int_progress = 0;
+  private int int_progress = 0;
 
 
-	private int state = 50;
+  private int state = 50;
 
 
-	private boolean forceStop = false;
+  private boolean forceStop = false;
 
 
-	public void forceProgramToStop() {
-		forceStop = true;
-	}
+  public void forceProgramToStop() {
+    forceStop = true;
+  }
 
 
-	public boolean isForceStop() {
-		return forceStop;
-	}
+  public boolean isForceStop() {
+    return forceStop;
+  }
 
 
-	public int getProgress() {
-		return int_progress;
-	}
+  public int getProgress() {
+    return int_progress;
+  }
 
 
-	public int getState() {
-		return state;
-	}
+  public int getState() {
+    return state;
+  }
 
 
-	public void setProgress(int progress) throws jplag.ExitException {
-		int_progress = progress;
-		if (forceStop)
+  public void setProgress(int progress) throws jplag.ExitException {
+    int_progress = progress;
+		if (forceStop) {
 			throw new jplag.ExitException("Submission aborted",
 			throw new jplag.ExitException("Submission aborted",
 					SUBMISSION_ABORTED);
 					SUBMISSION_ABORTED);
-	}
-
-	public abstract void initializeSecondStep(Program program)
-			throws jplag.ExitException;
-
-	// TODO control how the exclusion file is handled by the Program
-
-	public static void usage() {
-		System.out.print(Program.name_long
-						+ ", Copyright (c) 2004-2017 KIT - IPD Tichy, Guido Malpohl, and others.\n"
-						+ "Usage: JPlag [ options ] <root-dir> [-c file1 file2 ...]\n"
-						+ " <root-dir>        The root-directory that contains all submissions.\n\n"
-						+ "options are:\n"
-						+ " -v[qlpd]        (Verbose)\n"
-						+ "                 q: (Quiet) no output\n"
-						+ "                 l: (Long) detailed output\n"
-						+ "                 p: print all (p)arser messages\n"
-						+ "                 d: print (d)etails about each submission\n"
-						+ " -d              (Debug) parser. Non-parsable files will be stored.\n"
-						+ " -S <dir>        Look in directories <root-dir>/*/<dir> for programs.\n"
-						+ "                 (default: <root-dir>/*)\n"
-						+ " -s              (Subdirs) Look at files in subdirs too (default: deactivated)\n\n"
-						+ " -p <suffixes>   <suffixes> is a comma-separated list of all filename suffixes\n"
-						+ "                 that are included. (\"-p ?\" for defaults)\n\n"
-						+ " -o <file>       (Output) The Parserlog will be saved to <file>\n"
-						+ " -x <file>       (eXclude) All files named in <file> will be ignored\n"
-						+ " -t <n>          (Token) Tune the sensitivity of the comparison. A smaller\n"
-						+ "                 <n> increases the sensitivity.\n"
-						+ " -m <n>          (Matches) Number of matches that will be saved (default:20)\n"
-						+ " -m <p>%         All matches with more than <p>% similarity will be saved.\n"
-						+ " -r <dir>        (Result) Name of directory in which the web pages will be\n"
-						+ "                 stored (default: result)\n"
-						+ " -bc <dir>       Name of the directory which contains the basecode (common framework)\n"
-						+ " -c [files]      Compare a list of files. Should be the last one.\n"
-						+ " -l <language>   (Language) Supported Languages:\n                 ");
-		for (int i = 0; i < languages.length - 2; i += 2)
+		}
+  }
+
+  public abstract void initializeSecondStep(Program program)
+      throws jplag.ExitException;
+
+  // TODO control how the exclusion file is handled by the Program
+
+  public static void usage() {
+    System.out.print(Program.name_long
+        + ", Copyright (c) 2004-2017 KIT - IPD Tichy, Guido Malpohl, and others.\n"
+        + "Usage: JPlag [ options ] <root-dir> [-c file1 file2 ...]\n"
+        + " <root-dir>        The root-directory that contains all submissions.\n\n"
+        + "options are:\n"
+        + " -v[qlpd]        (Verbose)\n"
+        + "                 q: (Quiet) no output\n"
+        + "                 l: (Long) detailed output\n"
+        + "                 p: print all (p)arser messages\n"
+        + "                 d: print (d)etails about each submission\n"
+        + " -d              (Debug) parser. Non-parsable files will be stored.\n"
+        + " -S <dir>        Look in directories <root-dir>/*/<dir> for programs.\n"
+        + "                 (default: <root-dir>/*)\n"
+        + " -s              (Subdirs) Look at files in subdirs too (default: deactivated)\n\n"
+        + " -p <suffixes>   <suffixes> is a comma-separated list of all filename suffixes\n"
+        + "                 that are included. (\"-p ?\" for defaults)\n\n"
+        + " -o <file>       (Output) The Parserlog will be saved to <file>\n"
+        + " -x <file>       (eXclude) All files named in <file> will be ignored\n"
+        + " -t <n>          (Token) Tune the sensitivity of the comparison. A smaller\n"
+        + "                 <n> increases the sensitivity.\n"
+        + " -m <n>          (Matches) Number of matches that will be saved (default:20)\n"
+        + " -m <p>%         All matches with more than <p>% similarity will be saved.\n"
+        + " -r <dir>        (Result) Name of directory in which the web pages will be\n"
+        + "                 stored (default: result)\n"
+        + " -bc <dir>       Name of the directory which contains the basecode (common framework)\n"
+        + " -c [files]      Compare a list of files. Should be the last one.\n"
+        + " -l <language>   (Language) Supported Languages:\n                 ");
+		for (int i = 0; i < languages.length - 2; i += 2) {
 			System.out.print(languages[i] + (i == 0 ? " (default), " : ", "));
 			System.out.print(languages[i] + (i == 0 ? " (default), " : ", "));
-		System.out.println(languages[languages.length - 2]);
-	}
+		}
+    System.out.println(languages[languages.length - 2]);
+  }
 
 
-	protected static void printAllLanguages() throws jplag.ExitException {
-		for (int i = 0; i < languages.length - 1; i += 2)
+  protected static void printAllLanguages() throws jplag.ExitException {
+		for (int i = 0; i < languages.length - 1; i += 2) {
 			try {
 			try {
 				Language langClass = (Language) Class.forName(languages[i + 1])
 				Language langClass = (Language) Class.forName(languages[i + 1])
 						.newInstance();
 						.newInstance();
 				System.out.println(languages[i]);
 				System.out.println(languages[i]);
 				String suffixes[] = langClass.suffixes();
 				String suffixes[] = langClass.suffixes();
-				for (int j = 0; j < suffixes.length; j++)
+				for (int j = 0; j < suffixes.length; j++) {
 					System.out.print(suffixes[j]
 					System.out.print(suffixes[j]
 							+ (j + 1 < suffixes.length ? "," : "\n"));
 							+ (j + 1 < suffixes.length ? "," : "\n"));
+				}
 				System.out.println(langClass.min_token_match());
 				System.out.println(langClass.min_token_match());
 			} catch (ClassNotFoundException e) {
 			} catch (ClassNotFoundException e) {
 			} catch (IllegalAccessException e) {
 			} catch (IllegalAccessException e) {
 			} catch (InstantiationException e) {
 			} catch (InstantiationException e) {
 			}
 			}
-		throw new jplag.ExitException("printAllLanguages exited");
-	}
-
-	public String getCountryTag() {
-		return this.countryTag;
-	}
-	/**
-	 * @return Returns the title.
-	 */
-	public String getTitle() {
-		return title;
-	}
-	/**
-	 * @param title The title to set.
-	 */
-	public void setTitle(String title) {
-		this.title = title;
-	}
+		}
+    throw new jplag.ExitException("printAllLanguages exited");
+  }
+
+  public String getCountryTag() {
+    return this.countryTag;
+  }
+
+  /**
+   * @return Returns the title.
+   */
+  public String getTitle() {
+    return title;
+  }
+
+  /**
+   * @param title The title to set.
+   */
+  public void setTitle(String title) {
+    this.title = title;
+  }
 }
 }