package edu.pdx.cs410J.grader;

import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;

public class GraderTools {

  public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
    String tool = null;
    List<String> toolArgs = new ArrayList<>();
    for (String arg : args) {
      if (tool == null) {
        tool = arg;

      } else {
        toolArgs.add(arg);
      }
    }

    if (tool == null) {
      usage("Missing tool");
    }

    invokeMainMethod(getToolClass(tool), toolArgs.toArray(new String[toolArgs.size()]));
  }

  private static Class getToolClass(String tool) {
    switch (tool) {
      case "gradebook":
        return GradeBookGUI.class;

      case "fetch":
        return FetchAndProcessGraderEmail.class;

      case "importFromD2L" :
        return GradesFromD2LImporter.class;

      case "importFromProjectReports" :
        return ProjectGradesImporter.class;

      case "mailFileToStudent" :
        return StudentFileMailer.class;

      default:
        usage("Unknown tool: " + tool);
        return null;
    }
  }

  @SuppressWarnings("unchecked")
  private static void invokeMainMethod(Class aClass, String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    Method main = aClass.getMethod("main", args.getClass());
    main.invoke(aClass, new Object[] { args });

  }

  private static void usage(String message) {
    PrintStream err = System.err;
    err.println("** " + message);
    err.println();
    err.println("Executes one of the Grader tools");
    err.println();
    err.println("usage: GraderTools tool toolArg*");
    err.println("  tool                        The tool to execute");
    err.println("    gradebook                 The Grade Book GUI");
    err.println("    fetch                     Fetch student surveys or projects from the Grader's");
    err.println("                              emails account");
    err.println("    importFromD2L             Import grades from a D2L CSV");
    err.println("    importFromProjectReports  Import grades from graded project reports");
    err.println("    mailFileToStudent         Email text files to students");
    err.println("  toolArg                     A command line argument to send to the tool");
    err.println();

    System.exit(1);
  }
}

@@ -155,17 +155,48 @@
 va.util.
-*
+ArrayList;%0Aimport java.util.List
 ;%0A%0Apubli
@@ -602,24 +602,48 @@
 l%22);%0A    %7D%0A%0A
+    configureLogger();%0A%0A
     invokeMa
@@ -720,24 +720,248 @@
 ()%5D));%0A  %7D%0A%0A
+  private static void configureLogger() %7B%0A    // Oddly enough, attempts to access the Logger end up causes a ClassNotFoundException%0A    System.setProperty(%22java.util.logging.SimpleFormatter.format%22, %22%254$s %255$s%256$s%25n%22);%0A  %7D%0A%0A
   private st

Configure the JUL Loggers to only print out the level name.