package au.edu.mq.comp.junitGrading.commandLineUI;
import au.edu.mq.comp.common.Log;
import au.edu.mq.comp.common.OS;
import au.edu.mq.comp.common.SimpleFileIO;
import au.edu.mq.comp.junitGrading.GlobalSetting;
import au.edu.mq.comp.junitGrading.webUI.AutomarkWebApplication;
public class AutomarkCommandLineEntryPoint extends Object
{
public static String version()
{
return "(11:45a)-(Apr-28-2013)";
}
public static void printOptions()
{
Log.message("to run from commandline usage: Automark gradeClass configFile");
Log.message("to run from commandline usage: Automark gradeJUnit configFile");
Log.message(" to run as server usage: Automark server <portNo> <workingDirectory>");
}
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception
{
Log.message("Running from jar -> " + OS.pathToRunningJAR(JavaGraderDriver.class));
Log.message("Automark version:" + AutomarkCommandLineEntryPoint.version());
if(3 == args.length)
{
if(true == args[0].equalsIgnoreCase("server"))
{
int port = Integer.parseInt(args[1]);
String workingDir = args[2];
AutomarkWebApplication sparkServe = new AutomarkWebApplication(port, workingDir);
sparkServe.run();
}
else
{
Log.error("dont know option -->" + args[0]);
AutomarkCommandLineEntryPoint.printOptions();
}
}
else if(2 == args.length && true == args[0].equalsIgnoreCase("gradeClass"))
{
GlobalSetting.setDebugging(false);
Log.message("going to gradeClass");
Log.message("going to run with config file " + args[1]);
String pathToAutomarkFile = args[1];
java.io.File automarkFile = SimpleFileIO.makeFileFromPath(pathToAutomarkFile);
if(true == automarkFile.canRead())
{
JavaGraderDriver automark = new JavaGraderDriver();
SimpleFileIO.inCurrentWorkingDirectoryCreateDirectoryName("FeedBack");
String csvOutputString = automark.run(automarkFile);
if(false == csvOutputString.isEmpty())
{
SimpleFileIO.writeStringToTextFile(csvOutputString, "Result.csv");
Log.message("Wrote output csv file to -->" + "Result.csv");
}
}
else
{
Log.message(pathToAutomarkFile + " cannot be read or does not exist");
AutomarkCommandLineEntryPoint.printOptions();
}
}
else if(2 == args.length && true == args[0].equalsIgnoreCase("gradeJUnit"))
{
GlobalSetting.setDebugging(false);
Log.message("going to gradeJUnit");
Log.message("going to run with config file " + args[1]);
String pathToAutomarkFile = args[1];
java.io.File automarkFile = SimpleFileIO.makeFileFromPath(pathToAutomarkFile);
if(true == automarkFile.canRead())
{
GradeJUnitDriver graderDriver = new GradeJUnitDriver();
SimpleFileIO.inCurrentWorkingDirectoryCreateDirectoryName("FeedBack");
String csvOutputString = graderDriver.run(automarkFile);
}
else
{
Log.message(pathToAutomarkFile + " cannot be read or does not exist");
AutomarkCommandLineEntryPoint.printOptions();
}
}
else
{
AutomarkCommandLineEntryPoint.printOptions();
}
}
}