Commit 52531b36 authored by Jonathan Shahen's avatar Jonathan Shahen

intermediate commit: pipeline works for converting to NuSMV, progress made on...

intermediate commit: pipeline works for converting to NuSMV, progress made on the template but more work still needed
parent 6b72b2d9
<NotepadPlus>
<UserLang name="Mohawk+T" ext=".mohawkt" udlVersion="2.1">
<Settings>
<Global caseIgnored="yes" allowFoldOfComments="yes" foldCompact="no" forcePureLC="0" decimalSeparator="0" />
<Prefix Keywords1="yes" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00// 01 02 03/* 04*/</Keywords>
<Keywords name="Numbers, prefix1">t</Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
<Keywords name="Numbers, extras1"></Keywords>
<Keywords name="Numbers, extras2"></Keywords>
<Keywords name="Numbers, suffix1"></Keywords>
<Keywords name="Numbers, suffix2"></Keywords>
<Keywords name="Numbers, range"></Keywords>
<Keywords name="Operators1">~ &amp; &lt; &gt; , { }</Keywords>
<Keywords name="Operators2">NOT TRUE</Keywords>
<Keywords name="Folders in code1, open">{</Keywords>
<Keywords name="Folders in code1, middle"></Keywords>
<Keywords name="Folders in code1, close">}</Keywords>
<Keywords name="Folders in code2, open"></Keywords>
<Keywords name="Folders in code2, middle"></Keywords>
<Keywords name="Folders in code2, close"></Keywords>
<Keywords name="Folders in comment, open"></Keywords>
<Keywords name="Folders in comment, middle"></Keywords>
<Keywords name="Folders in comment, close"></Keywords>
<Keywords name="Keywords1">CanAssign CanRevoke CanDisable CanEnable Query Expected</Keywords>
<Keywords name="Keywords2">UNKNOWN GOAL_REACHABLE REACHABLE</Keywords>
<Keywords name="Keywords3">GOAL_UNREACHABLE UNREACHABLE</Keywords>
<Keywords name="Keywords4"></Keywords>
<Keywords name="Keywords5"></Keywords>
<Keywords name="Keywords6"></Keywords>
<Keywords name="Keywords7"></Keywords>
<Keywords name="Keywords8"></Keywords>
<Keywords name="Delimiters">00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords>
</KeywordLists>
<Styles>
<WordsStyle name="DEFAULT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="COMMENTS" fgColor="00A600" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="256" />
<WordsStyle name="LINE COMMENTS" fgColor="00A600" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="0" />
<WordsStyle name="NUMBERS" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS1" fgColor="C8002A" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS2" fgColor="2A00FF" bgColor="FFFFFF" fontName="" fontStyle="4" nesting="0" />
<WordsStyle name="KEYWORDS3" fgColor="D75D00" bgColor="FFFFFF" fontName="" fontStyle="4" nesting="0" />
<WordsStyle name="KEYWORDS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="OPERATORS" fgColor="7F0055" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="FOLDER IN CODE1" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS1" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS3" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
</Styles>
</UserLang>
</NotepadPlus>
......@@ -54,7 +54,7 @@ public class ConverterCUI {
break;
}
if (cmd.equals("!prev")) {
if (cmd.equals("!p")) {
argv.clear();
argv.addAll(Arrays.asList(previousCmd.split(" ")));
break;
......@@ -67,7 +67,7 @@ public class ConverterCUI {
System.out.println("Commands: " + argv);
try {
if (!cmd.equals("!prev")) {
if (!cmd.equals("!p")) {
FileWriter fw;
fw = new FileWriter(previousCommandFilename, false);
fw.write(fullCommand.toString());
......@@ -147,13 +147,15 @@ public class ConverterCUI {
+ OptionString.LOGLEVEL.c("quiet") + "!exit");
System.out.println(OptionString.TO_MOHAWK.c() + OptionString.SPECFILE.c("data/bug/11-CA-no-role3.mohawk.T")
+ OptionString.LOGLEVEL.c("quiet") + "!exit");
System.out.println("");
System.out.println(OptionString.TO_NUSMV.c() + OptionString.SPECFILE.c("data/nusmv/test01.mohawkt") + "!exit");
System.out.println("");
try {
BufferedReader bfr = new BufferedReader(new FileReader(previousCommandFilename));
previousCmd = bfr.readLine();
bfr.close();
System.out.println("Previous Command ('!prev' to use the previous command): " + previousCmd);
System.out.println("Previous Command ('!p' to use the previous command): " + previousCmd);
} catch (IOException e) {
System.out.println("[ERROR] Unable to load previous command!");
}
......
package mohawk.converter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.*;
import java.util.ArrayList;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import java.util.logging.*;
import org.apache.commons.cli.*;
import org.apache.commons.lang3.StringUtils;
import mohawk.converter.helper.SpecHelper;
......@@ -28,8 +14,6 @@ import mohawk.converter.to.asaptime.ConvertToASAPTimeNSA;
import mohawk.converter.to.asaptime.ConvertToASAPTimeSA;
import mohawk.converter.to.mohawk.ConvertToMohawk;
import mohawk.converter.to.nusmv.ConvertToNuSMV;
import mohawk.converter.to.nusmv.ConvertToNuSMVReduction2;
import mohawk.converter.to.nusmv.ConvertToNuSMVReduction3;
import mohawk.converter.to.tred.ConvertToTRole;
import mohawk.global.FileExtensions;
import mohawk.global.helper.RoleHelper;
......@@ -39,639 +23,581 @@ import mohawk.global.pieces.Rule;
import mohawk.global.timing.MohawkTiming;
public class ConverterInstance {
private static final String VERSION = "v1.3.1";
private static final String AUTHORS = "Jonathan Shahen <jmshahen@uwaterloo.ca>";
// Logger Fields
public static final Logger logger = Logger.getLogger("mohawk");
private String Logger_filepath = "mohawk-converter.log.csv";
private String Logger_folderpath = "logs";
private ConsoleHandler consoleHandler = new ConsoleHandler();
private Level LoggerLevel;
private FileHandler fileHandler;
private Boolean WriteCSVFileHeader = true;
private String resultsFile = "latest_Mohawk-T_Converter_Results.csv";
// Helpers
public SpecHelper specHelper = new SpecHelper();
public MohawkTiming timing = new MohawkTiming();
public FileExtensions fileExt = new FileExtensions();
private CommandLine init(String[] args) throws Exception {
Options options = new Options();
setupOptions(options);
CommandLineParser cmdParser = new BasicParser();
CommandLine cmd = cmdParser.parse(options, args);
setupLoggerOptions(cmd, options);
if (setupReturnImmediatelyOptions(cmd, options)) {
return null;
}
/* Timing */timing.startTimer("totalTime");
setupUserPreferenceOptions(cmd, options);
setupSpecOptions(cmd, options);
setupResultOptions(cmd, options);
return cmd;
}
public int run(String[] args) {
try {
CommandLine cmd = init(args);
if (cmd == null) {
return 0;
}
/* Timing */timing.startTimer("loadFile");
specHelper.loadSpecFiles();
/* Timing */timing.stopTimer("loadFile");
logger.info("Spec File(s) to Convert: " + specHelper.specFiles);
for (Integer i = 1; i <= specHelper.specFiles.size(); i++) {
File specFile = specHelper.specFiles.get(i - 1);
/* Timing */timing.startTimer("parseFile (" + i + ")");
logger.info("Processing File (" + i + "/"
+ specHelper.specFiles.size() + "): "
+ specFile.getAbsolutePath());
MohawkTARBACParser parser = specHelper
.parseMohawkTFile(specFile);
/* Timing */timing.stopTimer("parseFile (" + i + ")");
MohawkT m = parser.mohawkT;
if (specHelper.error.errorFound) {
logger.warning(
"[PARSING ERROR] Skipping this file due to a parsing error");
continue;
} else {
logger.info(
"No errors found while parsing file, continuing on to converting");
}
// ONLY reductions instead of full reductions up here
if (cmd.hasOption(OptionString.ONLYREDUCTION.toString())) {
String onlyOpt = cmd.getOptionValue(
OptionString.ONLYREDUCTION.toString());
ArrayList<Rule> workableRules = null;
RoleHelper roleHelper = new RoleHelper(m.roleHelper);
MohawkT m2 = new MohawkT();
if (onlyOpt.equals("enable1")) {
workableRules = roleHelper
.removeEnableDisableRules(m.getAllRules());
m2.generatorName = "Remove CanEnable v1";
} else if (onlyOpt.equals("enable2")) {
workableRules = roleHelper
.removeEnableDisableRulesv2(m.getAllRules());
m2.generatorName = "Remove CanEnable v2";
}
if (workableRules != null) {
m2.query = m.query;
m2.roleHelper = m.roleHelper;
m2.timeIntervalHelper = m.timeIntervalHelper;
m2.expectedResult = m.expectedResult;
m2.addRules(workableRules);
FileWriter fw = new FileWriter(
specFile.getAbsolutePath() + "_ONLY_"
+ onlyOpt);
fw.write(m2.getString(null, true, true));
fw.close();
}
} else {
if (cmd.hasOption(OptionString.TO_ASAPTIME_NSA.toString())
|| cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info(
"[CONVERTING] Converting to ASAPTime NSA... "
+ specFile.getName());
/* Timing */timing
.startTimer("convertToASAPTimeNSA (" + i + ")");
ConvertToASAPTimeNSA toASAPTimeNSA = new ConvertToASAPTimeNSA(
timing);
toASAPTimeNSA.convert(m, specFile, true);
if (toASAPTimeNSA.lastError == null) {
logger.info(
"[SUCCESS] Successfully converted to ASAPTimeNSA's Input Format");
} else {
logger.warning(
"[FAILURE] Failed to convert to ASAPTimeNSA's Input Format; Error code "
+ toASAPTimeNSA.lastError);
}
/* Timing */timing
.stopTimer("convertToASAPTimeNSA (" + i + ")");
logger.info(
"[CONVERTING] ...Done Converting to ASAPTime NSA");
}
if (cmd.hasOption(OptionString.TO_ASAPTIME_SA.toString())
|| cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to ASAPTime SA... "
+ specFile.getName());
/* Timing */timing
.startTimer("convertToASAPTimeSA (" + i + ")");
ConvertToASAPTimeSA toASAPTimeSA = new ConvertToASAPTimeSA(
timing);
toASAPTimeSA.convert(m, specFile, true);
if (toASAPTimeSA.lastError == null) {
logger.info(
"[SUCCESS] Successfully converted to ASAPTimeSA's Input Format");
} else {
logger.warning(
"[FAILURE] Failed to convert to ASAPTimeSA's Input Format; Error code "
+ toASAPTimeSA.lastError);
}
/* Timing */timing
.stopTimer("convertToASAPTimeSA (" + i + ")");
logger.info(
"[CONVERTING] ...Done Converting to ASAPTime SA");
}
if (cmd.hasOption(OptionString.TO_TROLE.toString())
|| cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to TRole... "
+ specFile.getName());
/* Timing */timing
.startTimer("convertToTRole (" + i + ")");
ConvertToTRole toTRole = new ConvertToTRole(timing);
toTRole.convert(m, specFile, true);
if (toTRole.lastError == null) {
logger.info(
"[SUCCESS] Successfully converted to TRole Input Format");
} else {
logger.warning(
"[FAILURE] Failed to convert to TRole Input Format; Error code "
+ toTRole.lastError);
}
/* Timing */timing
.stopTimer("convertToTRole (" + i + ")");
logger.info("[CONVERTING] ...Done Converting to TRole");
}
if (cmd.hasOption(OptionString.TO_MOHAWK.toString())
|| cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to Mohawk... "
+ specFile.getName());
/* Timing */timing
.startTimer("convertToMohawk (" + i + ")");
ConvertToMohawk toMohawk = new ConvertToMohawk(timing);
if (cmd.hasOption(
OptionString.SHORT_ROLENAMES.toString())) {
logger.fine("[OPTION] Short Rolenames: Enabled");
toMohawk.shortRolenames = true;
} else {
logger.fine("[OPTION] Short Rolenames: Disabled");
}
toMohawk.convert(m, specFile, true);
if (toMohawk.lastError == null) {
logger.info(
"[SUCCESS] Successfully converted to Mohawk's Input Format");
} else {
logger.warning(
"[FAILURE] Failed to convert to Mohawk's Input Format; Error code "
+ toMohawk.lastError);
}
/* Timing */timing
.stopTimer("convertToMohawk (" + i + ")");
logger.info(
"[CONVERTING] ...Done Converting to Mohawk");
}
if (cmd.hasOption(OptionString.TO_MOHAWK_T.toString())) {
logger.info("[CONVERTING] Converting to Mohawk-T... "
+ specFile.getName());
/* Timing */timing
.startTimer("convertToMohawkT (" + i + ")");
FileWriter fw = new FileWriter(
specFile.getAbsolutePath() + "_2");
fw.write(m.getString("\n\n", true, true));
fw.close();
/* Timing */timing
.stopTimer("convertToMohawkT (" + i + ")");
logger.info(
"[CONVERTING] ...Done Converting to Mohawk-T");
}
if (cmd.hasOption(OptionString.TO_NUSMV.toString())
|| cmd.hasOption(OptionString.TO_ALL.toString())) {
logger.info("[CONVERTING] Converting to NuSMV... "
+ specFile.getName());
/* Timing */timing
.startTimer("convertToNuSMV (" + i + ")");
ConvertToNuSMV toNuSMV = null;
if (ConvertToNuSMV.reduction == 2) {
logger.info(
"[OPTION] Using ConvertToNuSMVReduction2");
toNuSMV = new ConvertToNuSMVReduction2(timing);
} else if (ConvertToNuSMV.reduction == 3) {
logger.info(
"[OPTION] Using ConvertToNuSMVReduction3");
toNuSMV = new ConvertToNuSMVReduction3(timing);
} else {
/* Timing */timing
.cancelTimer("convertToNuSMV (" + i + ")");
throw new Exception(
"[CONVERTING] Unknown Reduction number: "
+ ConvertToNuSMV.reduction);
}
if (cmd.hasOption(
OptionString.SHORT_ROLENAMES.toString())) {
logger.info("[OPTION] Short Rolenames: Enabled");
toNuSMV.shortRolenames = true;
} else {
logger.info("[OPTION] Short Rolenames: Disabled");
}
toNuSMV.convert(m, specFile, true);
if (toNuSMV.lastError == null) {
logger.info(
"[SUCCESS] Successfully converted to Mohawk's Input Format");
} else {
logger.warning(
"[FAILURE] Failed to convert to Mohawk's Input Format; Error code "
+ toNuSMV.lastError);
}
/* Timing */timing
.stopTimer("convertToNuSMV (" + i + ")");
logger.info(
"[CONVERTING] ...Done Converting to Mohawk");
}
}
}
/* Timing */timing.stopTimer("totalTime");
logger.info(timing.toString());
} catch (Exception e) {
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
logger.severe(errors.toString());
logger.severe(e.getMessage());
}
logger.info("[EOF] Converter Instance done running");
for (Handler h : logger.getHandlers()) {
h.close();// must call h.close or a .LCK file will remain.
}
return 0;
}
public void printHelp(CommandLine cmd, Options options) throws Exception {
if (cmd.hasOption("maxw")) {
try {
Integer maxw = Integer.decode(cmd.getOptionValue("maxw"));
printHelp(options, maxw);
} catch (Exception e) {
printHelp(options, 80);
e.printStackTrace();
throw new Exception(
"An error occured when trying to print out the help options!");
}
} else {
printHelp(options, 80);
}
}
public void printHelp(Options options, int maxw) {
HelpFormatter f = new HelpFormatter();
f.printHelp(maxw, "mohawk-converter",
StringUtils.repeat("-", maxw) + "\nAuthors: " + AUTHORS + "\n"
+ StringUtils.repeat("-", 20),
options, StringUtils.repeat("-", maxw), true);
}
@SuppressWarnings("static-access")
public void setupOptions(Options options) {
// Add Information Options
options.addOption(OptionString.HELP.toString(), false,
"Print this message");
options.addOption(OptionString.AUTHORS.toString(), false,
"Prints the authors");
options.addOption(OptionString.VERSION.toString(), false,
"Prints the version (" + VERSION + ") information");
options.addOption(OptionString.CHECKNUSMV.toString(), false,
"Checks that NuSMV is on the system and displays which version is installed");
// Add Logging Level Options
options.addOption(OptionBuilder.withArgName("quiet|debug|verbose")
.withDescription(
"quiet - Be extra quiet only errors are shown;\n"
+ "verbose - extra information is given for Verbose;\n"
+ "debug - Show debugging information;\n"
+ "Default is between debug and verbose level")
.hasArg().create(OptionString.LOGLEVEL.toString()));
options.addOption(OptionBuilder.withArgName("logfile|'n'|'u'")
.withDescription(
"The filepath where the log file should be created;\n"
+ "No file will be created when equal to 'n';\n"
+ "A unique filename will be created when equal to 'u';\n"
+ "default it creates a log called '"
+ Logger_filepath + "'")
.hasArg().create(OptionString.LOGFILE.toString()));
options.addOption(OptionBuilder.withArgName("folder path")
.withDescription(
"The path to the location that the logs should be placed, "
+ "default it puts the logs in the folder '"
+ Logger_folderpath + "'")
.hasArg().create(OptionString.LOGFOLDER.toString()));
options.addOption(OptionString.NOHEADER.toString(), false,
"Does not write the CSV file header to the output log");
options.addOption(
OptionBuilder.withArgName("csvfile")
.withDescription(
"The file where the result should be stored")
.hasArg().create(OptionString.RESULTSFILE.toString()));
// custom Console Logging Options
options.addOption(OptionBuilder.withArgName("num")
.withDescription(
"The maximum width of the console (default 120)")
.hasArg().create(OptionString.MAXW.toString()));
options.addOption(OptionBuilder.withArgName("string")
.withDescription(
"The new line string when wrapping a long line (default '\\n ')")
.hasArg().create(OptionString.LINESTR.toString()));
// Add File IO Options
options.addOption(OptionBuilder.withArgName("file|folder")
.withDescription(
"Path to the Mohawk-T Spec File, or Folder if the 'bulk' option is set")
.hasArg().create(OptionString.SPECFILE.toString()));
options.addOption(OptionBuilder.withArgName("extension")
.withDescription(
"File extention used when searching for SPEC files when the 'bulk' option is used. "
+ "Default:'" + specHelper.fileExt + "'")
.hasArg().create(OptionString.SPECEXT.toString()));
// Add Functional Options
options.addOption(OptionString.BULK.toString(), false,
"Use the folder that rbacspec points to and run against all *.spec");
options.addOption(OptionString.SHORT_ROLENAMES.toString(), false,
"Converted file will have short names (only works for to_mohawk)");
options.addOption(OptionString.TO_ASAPTIME_NSA.toString(), false,
"Convert input SPEC file to ASAPTime NSA format");
options.addOption(OptionString.TO_ASAPTIME_SA.toString(), false,
"Convert input SPEC file to ASAPTime SA format");
options.addOption(OptionString.TO_TROLE.toString(), false,
"Convert input SPEC file to TRole format");
options.addOption(OptionString.TO_TRULE.toString(), false,
"Convert input SPEC file to TRule format");
options.addOption(OptionString.TO_MOHAWK.toString(), false,
"Convert input SPEC file to Mohawk's ARBAC format");
options.addOption(OptionString.TO_MOHAWK_T.toString(), false,
"Convert input SPEC file to Mohawk-T's ATRBAC format");
options.addOption(OptionString.TO_ALL.toString(), false,
"Convert input SPEC file to All formats except Mohawk-T (Mohawk, ASAPTime NSA, ASAPTime SA, TRole, TRule)");
// ONLY Commands (limits the reduction steps
options.addOption(OptionBuilder.withArgName("reduction")
.withDescription(
"Only reduce using one reduction (overwrites the 'TO_' commands:\n"
+ " enable1 - Remove CanEnable/CanDisable Reduction V1,\n"
+ " enable2 - Remove CanEnable/CanDisable Reduction V2,\n"
+ " (others to be added)")
.hasArg().create(OptionString.ONLYREDUCTION.toString()));
}
public Level getLoggerLevel() {
return LoggerLevel;
}
public void setLoggerLevel(Level loggerLevel) {
LoggerLevel = loggerLevel;
}
private void setupLoggerOptions(CommandLine cmd, Options options)
throws SecurityException, IOException {
// Logging Level
logger.setUseParentHandlers(false);
consoleHandler.setFormatter(new MohawkConsoleFormatter());
setLoggerLevel(Level.FINE);// Default Level
if (cmd.hasOption(OptionString.LOGLEVEL.toString())) {
String loglevel = cmd
.getOptionValue(OptionString.LOGLEVEL.toString());
if (loglevel.equalsIgnoreCase("quiet")) {
setLoggerLevel(Level.WARNING);
} else if (loglevel.equalsIgnoreCase("debug")) {
setLoggerLevel(Level.FINEST);
} else if (loglevel.equalsIgnoreCase("verbose")) {
setLoggerLevel(Level.INFO);
}
}
logger.setLevel(LoggerLevel);
consoleHandler.setLevel(LoggerLevel);
logger.addHandler(consoleHandler);
// Add CSV File Headers
if (cmd.hasOption(OptionString.NOHEADER.toString())) {
WriteCSVFileHeader = false;
}
// Set Logger Folder
if (cmd.hasOption(OptionString.LOGFOLDER.toString())) {
Logger_folderpath = cmd
.getOptionValue(OptionString.LOGFOLDER.toString());
}
// Set File Logger
if (cmd.hasOption(OptionString.LOGFILE.toString())) {
// Check if no log file was requested
if (cmd.getOptionValue(OptionString.LOGFILE.toString())
.equals("n")) {
// Create no log file
Logger_filepath = "";
} else if (cmd.getOptionValue(OptionString.LOGFILE.toString())
.equals("u")) {
// Create a unique log file
Logger_filepath = "mohawk-log.%u.%g.txt";
} else {
try {
// Create a log file with a specific name
File logfile = new File(Logger_folderpath + File.separator
+ cmd.getOptionValue(
OptionString.LOGFILE.toString()));
if (!logfile.exists()) {
logfile.createNewFile();
}
Logger_filepath = logfile.getAbsolutePath();
if (WriteCSVFileHeader) {
FileOutputStream writer = new FileOutputStream(logfile,
true);// Always
// append!
writer.write(
MohawkCSVFileFormatter.csvHeaders().getBytes());
writer.flush();
writer.close();
}
} catch (IOException e) {
logger.severe(e.getMessage());
return;
}
}
}
// Add Logger File Handler
if (!Logger_filepath.isEmpty()) {
File logfile = new File(Logger_folderpath);
logfile.mkdirs();
if (!logfile.isDirectory()) {
logger.severe(
"logfolder did not contain a folder that exists or that could be created!");
}
fileHandler = new FileHandler(
Logger_folderpath + File.separator + Logger_filepath);
fileHandler.setLevel(getLoggerLevel());
fileHandler.setFormatter(new MohawkCSVFileFormatter());
logger.addHandler(fileHandler);
}
}
private Boolean setupReturnImmediatelyOptions(CommandLine cmd,
Options options) throws Exception {
if (cmd.hasOption(OptionString.HELP.toString()) == true
|| cmd.getOptions().length == 0) {
printHelp(cmd, options);
return true;
}
if (cmd.hasOption(OptionString.VERSION.toString())) {
// keep it as simple as possible for the version
System.out.println(VERSION);
return true;
}
if (cmd.hasOption(OptionString.AUTHORS.toString())) {
// keep it as simple as possible for the version
System.out.println(AUTHORS);
return true;
}
return false;
}
private void setupSpecOptions(CommandLine cmd, Options options) {
// Grab the SPEC file
if (cmd.hasOption(OptionString.SPECFILE.toString())) {
logger.fine("[OPTION] Using a specific SPEC File: "
+ cmd.getOptionValue(OptionString.SPECFILE.toString()));