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;
......@@ -41,7 +25,7 @@ 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
/*Logger Fields*/
public static final Logger logger = Logger.getLogger("mohawk");
private String Logger_filepath = "mohawk-converter.log.csv";
private String Logger_folderpath = "logs";
......@@ -51,7 +35,7 @@ public class ConverterInstance {
private Boolean WriteCSVFileHeader = true;
private String resultsFile = "latest_Mohawk-T_Converter_Results.csv";
// Helpers
/* Helpers*/
public SpecHelper specHelper = new SpecHelper();
public MohawkTiming timing = new MohawkTiming();
public FileExtensions fileExt = new FileExtensions();
......@@ -65,9 +49,7 @@ public class ConverterInstance {
setupLoggerOptions(cmd, options);
if (setupReturnImmediatelyOptions(cmd, options)) {
return null;
}
if (setupReturnImmediatelyOptions(cmd, options)) { return null; }
/* Timing */timing.startTimer("totalTime");
......@@ -82,9 +64,7 @@ public class ConverterInstance {
try {
CommandLine cmd = init(args);
if (cmd == null) {
return 0;
}
if (cmd == null) { return 0; }
/* Timing */timing.startTimer("loadFile");
specHelper.loadSpecFiles();
......@@ -95,41 +75,34 @@ public class ConverterInstance {
File specFile = specHelper.specFiles.get(i - 1);
/* Timing */timing.startTimer("parseFile (" + i + ")");
logger.info("Processing File (" + i + "/"
+ specHelper.specFiles.size() + "): "
logger.info("Processing File (" + i + "/" + specHelper.specFiles.size() + "): "
+ specFile.getAbsolutePath());
MohawkTARBACParser parser = specHelper
.parseMohawkTFile(specFile);
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");
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");
logger.info("No errors found while parsing file, continuing on to converting");
}
// ONLY reductions instead of full reductions up here
/*ONLY reductions instead of full reductions up here*/
if (cmd.hasOption(OptionString.ONLYREDUCTION.toString())) {
String onlyOpt = cmd.getOptionValue(
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());
workableRules = roleHelper.removeEnableDisableRules(m.getAllRules());
m2.generatorName = "Remove CanEnable v1";
} else if (onlyOpt.equals("enable2")) {
workableRules = roleHelper
.removeEnableDisableRulesv2(m.getAllRules());
workableRules = roleHelper.removeEnableDisableRulesv2(m.getAllRules());
m2.generatorName = "Remove CanEnable v2";
}
......@@ -142,64 +115,47 @@ public class ConverterInstance {
m2.addRules(workableRules);
FileWriter fw = new FileWriter(
specFile.getAbsolutePath() + "_ONLY_"
+ onlyOpt);
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 + ")");
logger.info("[CONVERTING] Converting to ASAPTime NSA... " + specFile.getName());
/* Timing */timing.startTimer("convertToASAPTimeNSA (" + i + ")");
ConvertToASAPTimeNSA toASAPTimeNSA = new ConvertToASAPTimeNSA(
timing);
ConvertToASAPTimeNSA toASAPTimeNSA = new ConvertToASAPTimeNSA(timing);
toASAPTimeNSA.convert(m, specFile, true);
if (toASAPTimeNSA.lastError == null) {
logger.info(
"[SUCCESS] Successfully converted to ASAPTimeNSA's Input Format");
logger.info("[SUCCESS] Successfully converted to ASAPTimeNSA's Input Format");
} else {
logger.warning(
"[FAILURE] Failed to convert to ASAPTimeNSA's Input Format; Error code "
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");
/* 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 + ")");
logger.info("[CONVERTING] Converting to ASAPTime SA... " + specFile.getName());
/* Timing */timing.startTimer("convertToASAPTimeSA (" + i + ")");
ConvertToASAPTimeSA toASAPTimeSA = new ConvertToASAPTimeSA(
timing);
ConvertToASAPTimeSA toASAPTimeSA = new ConvertToASAPTimeSA(timing);
toASAPTimeSA.convert(m, specFile, true);
if (toASAPTimeSA.lastError == null) {
logger.info(
"[SUCCESS] Successfully converted to ASAPTimeSA's Input Format");
logger.info("[SUCCESS] Successfully converted to ASAPTimeSA's Input Format");
} else {
logger.warning(
"[FAILURE] Failed to convert to ASAPTimeSA's Input Format; Error code "
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");
/* Timing */timing.stopTimer("convertToASAPTimeSA (" + i + ")");
logger.info("[CONVERTING] ...Done Converting to ASAPTime SA");
}
if (cmd.hasOption(OptionString.TO_TROLE.toString())
......@@ -284,47 +240,19 @@ public class ConverterInstance {
/* 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");
}
ConvertToNuSMV toNuSMV = new ConvertToNuSMV(timing);
toNuSMV.convert(m, specFile, true);
if (toNuSMV.lastError == null) {
logger.info(
"[SUCCESS] Successfully converted to Mohawk's Input Format");
logger.info("[SUCCESS] Successfully converted to Mohawk's Input Format");
} else {
logger.warning(
"[FAILURE] Failed to convert to Mohawk's Input Format; Error code "
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("convertToNuSMV (" + i + ")");
logger.info("[CONVERTING] ...Done Converting to Mohawk");
}
}
}
......@@ -342,7 +270,7 @@ public class ConverterInstance {
logger.info("[EOF] Converter Instance done running");
for (Handler h : logger.getHandlers()) {
h.close();// must call h.close or a .LCK file will remain.
h.close();/* must call h.close or a .LCK file will remain.*/
}
return 0;
}
......@@ -374,17 +302,14 @@ public class ConverterInstance {
@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");
/* 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
/* Add Logging Level Options*/
options.addOption(OptionBuilder.withArgName("quiet|debug|verbose")
.withDescription(
"quiet - Be extra quiet only errors are shown;\n"
......@@ -416,7 +341,7 @@ public class ConverterInstance {
"The file where the result should be stored")
.hasArg().create(OptionString.RESULTSFILE.toString()));
// custom Console Logging Options
/* custom Console Logging Options*/
options.addOption(OptionBuilder.withArgName("num")
.withDescription(
"The maximum width of the console (default 120)")
......@@ -426,7 +351,7 @@ public class ConverterInstance {
"The new line string when wrapping a long line (default '\\n ')")
.hasArg().create(OptionString.LINESTR.toString()));
// Add File IO Options
/* 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")
......@@ -438,7 +363,7 @@ public class ConverterInstance {
+ "Default:'" + specHelper.fileExt + "'")
.hasArg().create(OptionString.SPECEXT.toString()));
// Add Functional Options
/* Add Functional Options*/
options.addOption(OptionString.BULK.toString(), false,
"Use the folder that rbacspec points to and run against all *.spec");
......@@ -457,10 +382,12 @@ public class ConverterInstance {
"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_NUSMV.toString(), false,
"Convert input SPEC file to NuSMV 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
/* ONLY Commands (limits the reduction steps*/
options.addOption(OptionBuilder.withArgName("reduction")
.withDescription(
"Only reduce using one reduction (overwrites the 'TO_' commands:\n"
......@@ -480,10 +407,10 @@ public class ConverterInstance {
private void setupLoggerOptions(CommandLine cmd, Options options)
throws SecurityException, IOException {
// Logging Level
/* Logging Level*/
logger.setUseParentHandlers(false);
consoleHandler.setFormatter(new MohawkConsoleFormatter());
setLoggerLevel(Level.FINE);// Default Level
setLoggerLevel(Level.FINE);/* Default Level*/
if (cmd.hasOption(OptionString.LOGLEVEL.toString())) {
String loglevel = cmd
.getOptionValue(OptionString.LOGLEVEL.toString());
......@@ -500,31 +427,31 @@ public class ConverterInstance {
consoleHandler.setLevel(LoggerLevel);
logger.addHandler(consoleHandler);
// Add CSV File Headers
/* Add CSV File Headers*/
if (cmd.hasOption(OptionString.NOHEADER.toString())) {
WriteCSVFileHeader = false;
}
// Set Logger Folder
/* Set Logger Folder*/
if (cmd.hasOption(OptionString.LOGFOLDER.toString())) {
Logger_folderpath = cmd
.getOptionValue(OptionString.LOGFOLDER.toString());
}
// Set File Logger
/* Set File Logger*/
if (cmd.hasOption(OptionString.LOGFILE.toString())) {
// Check if no log file was requested
/* Check if no log file was requested*/
if (cmd.getOptionValue(OptionString.LOGFILE.toString())
.equals("n")) {
// Create no log file
/* Create no log file*/
Logger_filepath = "";
} else if (cmd.getOptionValue(OptionString.LOGFILE.toString())
.equals("u")) {
// Create a unique log file
/* Create a unique log file*/
Logger_filepath = "mohawk-log.%u.%g.txt";
} else {
try {
// Create a log file with a specific name
/* Create a log file with a specific name*/
File logfile = new File(Logger_folderpath + File.separator
+ cmd.getOptionValue(
OptionString.LOGFILE.toString()));
......@@ -536,8 +463,7 @@ public class ConverterInstance {
if (WriteCSVFileHeader) {
FileOutputStream writer = new FileOutputStream(logfile,
true);// Always
// append!
true);/* Always append!*/
writer.write(
MohawkCSVFileFormatter.csvHeaders().getBytes());
writer.flush();
......@@ -550,7 +476,7 @@ public class ConverterInstance {
}
}
}
// Add Logger File Handler
/* Add Logger File Handler*/
if (!Logger_filepath.isEmpty()) {
File logfile = new File(Logger_folderpath);
logfile.mkdirs();
......@@ -576,13 +502,13 @@ public class ConverterInstance {
}
if (cmd.hasOption(OptionString.VERSION.toString())) {
// keep it as simple as possible for the version
/* 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
/* keep it as simple as possible for the version*/
System.out.println(AUTHORS);
return true;
}
......@@ -591,7 +517,7 @@ public class ConverterInstance {
}
private void setupSpecOptions(CommandLine cmd, Options options) {
// Grab the SPEC file
/* Grab the SPEC file*/
if (cmd.hasOption(OptionString.SPECFILE.toString())) {
logger.fine("[OPTION] Using a specific SPEC File: "
+ cmd.getOptionValue(OptionString.SPECFILE.toString()));
......@@ -611,7 +537,7 @@ public class ConverterInstance {
+ specHelper.fileExt);
}
// Load more than one file from the SPEC File?
/* Load more than one file from the SPEC File?*/
if (cmd.hasOption(OptionString.BULK.toString())) {
logger.fine("[OPTION] Bulk SPEC File inclusion: Enabled");
specHelper.bulk = true;
......@@ -621,7 +547,7 @@ public class ConverterInstance {
}
private void setupUserPreferenceOptions(CommandLine cmd, Options options) {
// Set the Console's Max Width
/* Set the Console's Max Width*/
if (cmd.hasOption(OptionString.MAXW.toString())) {
logger.fine("[OPTION] Setting the console's maximum width");
String maxw = "";
......@@ -637,7 +563,7 @@ public class ConverterInstance {
logger.fine("[OPTION] Default Console Maximum Width Used");
}
// Set the Console's Wrap String
/* Set the Console's Wrap String*/
if (cmd.hasOption(OptionString.LINESTR.toString())) {
logger.fine("[OPTION] Setting the console's new line string");
((MohawkConsoleFormatter) consoleHandler
......
package mohawk.converter.to.nusmv;
import java.io.File;
import java.io.*;
import java.nio.file.Files;
import java.util.*;
import java.util.logging.Logger;
import org.stringtemplate.v4.ST;
import mohawk.converter.to.ConvertTo;
import mohawk.global.pieces.MohawkT;
import mohawk.global.helper.RoleHelper;
import mohawk.global.helper.TimeIntervalHelper;
import mohawk.global.pieces.*;
import mohawk.global.timing.MohawkTiming;
public class ConvertToNuSMV extends ConvertTo {
public static final Logger logger = Logger.getLogger("mohawk");
/** Change this number to change from Reduction 2 to Reduction 3. */
public static final Integer reduction = 3;
public boolean shortRolenames = false;
public ConvertToNuSMV(MohawkTiming timing) {
super(timing);
tPrefix = "ConvertToNuSMV";
}
@Override
public String getFileExtenstion() {
return ".smv";
}
@Override
public String convert(MohawkT m, File file, Boolean writeToFile) {
logger.warning("[ERROR] Pick a specific Reduction to NuSMV");
lastError = "Pick a specific Reduction to NuSMV";
try {
// Deep Copy Helpers
/* Timing */timing.startTimer(tPrefix + "_" + "deepcopy");
RoleHelper roleHelper = new RoleHelper(m.roleHelper);
TimeIntervalHelper timeIntervalHelper = new TimeIntervalHelper(m.timeIntervalHelper);
Query workableQuery = new Query(m.query);
/* Timing */timing.stopTimer(tPrefix + "_" + "deepcopy");
/* Timing */timing.startTimer(tPrefix + "_" + "sortRolesReduceTimeslots");
// Reduce Roles to Integers
roleHelper.allowZeroRole = false;// roles start from 1 NOT 0!
roleHelper.setupSortedRoles();
// Reduce TimeIntervals to Timeslots
timeIntervalHelper.allowZeroTimeslot = false;// time-slots start from t1 NOT t0!
// Reduction (2)
timeIntervalHelper.reduceToTimeslots();
/* Timing */timing.stopTimer(tPrefix + "_" + "sortRolesReduceTimeslots");
Set<Role> adminRoles = RoleHelper.getAdministratorRoles(m.getAllRules(), false);
Integer caRuleCount = m.canAssign.numberOfRules();
Integer crRuleCount = m.canRevoke.numberOfRules();
Integer ceRuleCount = m.canEnable.numberOfRules();
Integer cdRuleCount = m.canDisable.numberOfRules();
/* Generate a list of users (roles + 1) to loop through */
ArrayList<Integer> users = new ArrayList<>(roleHelper.numberOfRoles() + 1);
for (int i = 1; i <= roleHelper.numberOfRoles() + 1; i++) {
users.add(i);
}
Set<RoleTimeSlot> roleTimeslots = new HashSet<>();
for (Rule r : m.canAssign.getRules()) {
roleTimeslots.addAll(RoleTimeSlot.grabAll(r));
}
// Generate the Converted String
/* Timing */timing.startTimer(tPrefix + "_" + "template");
String template = ConvertTo.readFile(this.getClass().getResource("nusmvTemplate.st"));
ST st = new ST(template);
st.add("numRoles", roleHelper.numberOfRoles());
st.add("numAdminRoles", adminRoles.size());
st.add("numTimeSlots", timeIntervalHelper.sizeReduced());