Commit 8715e660 authored by Jonathan Shahen's avatar Jonathan Shahen

updated CUI, fixed Instance (always returning the help message), and moving...

updated CUI, fixed Instance (always returning the help message), and moving reduction classes to the global repo (just in case the generator needs them)
parent d8f4ce67
......@@ -4,9 +4,7 @@ import java.util.ArrayList;
import java.util.Scanner;
import java.util.logging.Logger;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.commons.lang3.StringUtils;
public class ConverterCUI {
public static final Logger logger = Logger.getLogger("mohawk-converter");
......@@ -19,20 +17,50 @@ public class ConverterCUI {
Options options = new Options();
inst.setupOptions(options);
HelpFormatter f = new HelpFormatter();
f.printHelp(120, "mohawk", StringUtils.repeat("-", 80), options, StringUtils.repeat("-", 80), true);
inst.printHelp(options, 120);
printCommonCommands();
System.out.print("Enter Commandline Argument ('!exit' to run): ");
String quotedStr = "";
while (true) {
cmd = user_input.next();
if (quotedStr.isEmpty() && cmd.startsWith("\"")) {
System.out.println("Starting: " + cmd);
quotedStr = cmd.substring(1);
continue;
}
if (!quotedStr.isEmpty() && cmd.endsWith("\"")) {
System.out.println("Ending: " + cmd);
argv.add(quotedStr + " " + cmd.substring(0, cmd.length() - 1));
quotedStr = "";
continue;
}
if (!quotedStr.isEmpty()) {
quotedStr = quotedStr + " " + cmd;
continue;
}
if (cmd.equals("!exit")) {
break;
}
argv.add(cmd);
}
user_input.close();
System.out.println("Commands: " + argv);
inst.run(argv.toArray(new String[1]));
}
public static void printCommonCommands() {
System.out.println("\n\n--- Common Commands ---");
System.out.println("-to_uzun -rbacspec data/regressiontests/positive1.spec -loglevel debug !exit");
System.out.println("-to_uzun -rbacspec data/regressiontests/positive2.spec -loglevel debug !exit");
System.out.println("-to_uzun -rbacspec data/regressiontests/positive3.spec -loglevel debug !exit");
System.out.println("-to_uzun -rbacspec data/regressiontests/positive4.spec -loglevel debug !exit");
System.out.println("");
}
}
......@@ -167,6 +167,28 @@ public class ConverterInstance {
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
......@@ -313,22 +335,9 @@ public class ConverterInstance {
}
}
private Boolean setupReturnImmediatelyOptions(CommandLine cmd, Options options) {
if (cmd.hasOption("help") == true || cmd.getArgs().length == 0) {
HelpFormatter f = new HelpFormatter();
if (cmd.hasOption("maxw")) {
try {
Integer maxw = Integer.decode(cmd.getOptionValue("maxw"));
f.printHelp(maxw, "mohawk", StringUtils.repeat("-", maxw) + "\nAuthors: " + AUTHORS + "\n"
+ StringUtils.repeat("-", 20), options, StringUtils.repeat("-", maxw), true);
} catch (Exception e) {
e.printStackTrace();
System.out.println("An error occured when trying to print out the help options!");
}
} else {
f.printHelp(80, "mohawk", StringUtils.repeat("-", 80), options, StringUtils.repeat("-", 80), true);
}
private Boolean setupReturnImmediatelyOptions(CommandLine cmd, Options options) throws Exception {
if (cmd.hasOption("help") == true || cmd.getOptions().length == 0) {
printHelp(cmd, options);
return true;
}
......
package mohawk.converter.pieces.rules;
import mohawk.global.helper.RoleHelper;
import mohawk.global.helper.TimeIntervalHelper;
import mohawk.global.pieces.Role;
import mohawk.global.pieces.Rule;
public class ASAPTimeNSA_Rule {
public String ruleType;
public Integer startTime;
public Integer finishTime;
public Integer role;
public Integer[] precondition;
public Integer[] roleSchedule;
public ASAPTimeNSA_Rule(Rule r, RoleHelper rh, TimeIntervalHelper tih) {
ruleType = r._type.toUzun();
startTime = r._adminTimeInterval.getStartTime();
finishTime = r._adminTimeInterval.getFinishTime();
role = rh.indexOf(r._role);
precondition = new Integer[rh.size()];
for (int i = 0; i < rh.size(); i++) {
Role role = rh.get(i);
// Ignore
int loc = r._preconditions.indexOf(role.toLimitedRole());
if (loc != -1) {
role = r._preconditions.get(loc);
if (role._not) {
precondition[i] = -1;
} else {
precondition[i] = 1;
}
} else {
precondition[i] = 0;
}
}
roleSchedule = new Integer[tih.getNextTimeSlot()];
for (Integer i = 0; i < roleSchedule.length; i++) {
if (r._roleSchedule.contains(i)) {
roleSchedule[i] = 1;
} else {
roleSchedule[i] = 0;
}
}
}
}
package mohawk.converter.pieces.rules;
import mohawk.global.helper.RoleHelper;
import mohawk.global.helper.TimeIntervalHelper;
import mohawk.global.pieces.Role;
import mohawk.global.pieces.Rule;
public class ASAPTimeSA_Rule {
public String ruleType;
public Integer startTime;
public Integer finishTime;
public Integer role;
public Integer[] precondition;
public Integer[] roleSchedule;
public ASAPTimeSA_Rule(Rule r, RoleHelper rh, TimeIntervalHelper tih) {
ruleType = r._type.toUzun();
startTime = r._adminTimeInterval.getStartTime();
finishTime = r._adminTimeInterval.getFinishTime();
role = rh.indexOf(r._role);
precondition = new Integer[rh.size()];
for (int i = 0; i < rh.size(); i++) {
Role role = rh.get(i);
// Ignore
int loc = r._preconditions.indexOf(role.toLimitedRole());
if (loc != -1) {
role = r._preconditions.get(loc);
if (role._not) {
precondition[i] = -1;
} else {
precondition[i] = 1;
}
} else {
precondition[i] = 0;
}
}
roleSchedule = new Integer[tih.getNextTimeSlot()];
for (Integer i = 0; i < roleSchedule.length; i++) {
if (r._roleSchedule.contains(i)) {
roleSchedule[i] = 1;
} else {
roleSchedule[i] = 0;
}
}
}
}
package mohawk.converter.pieces.rules;
import mohawk.global.helper.RoleHelper;
import mohawk.global.helper.TimeIntervalHelper;
import mohawk.global.pieces.Role;
import mohawk.global.pieces.Rule;
public class Mohawk_Rule {
public String ruleType;
public Integer startTime;
public Integer finishTime;
public Integer role;
public Integer[] precondition;
public Integer[] roleSchedule;
public Mohawk_Rule(Rule r, RoleHelper rh, TimeIntervalHelper tih) {
ruleType = r._type.toUzun();
startTime = r._adminTimeInterval.getStartTime();
finishTime = r._adminTimeInterval.getFinishTime();
role = rh.indexOf(r._role);
precondition = new Integer[rh.size()];
for (int i = 0; i < rh.size(); i++) {
Role role = rh.get(i);
// Ignore
int loc = r._preconditions.indexOf(role.toLimitedRole());
if (loc != -1) {
role = r._preconditions.get(loc);
if (role._not) {
precondition[i] = -1;
} else {
precondition[i] = 1;
}
} else {
precondition[i] = 0;
}
}
roleSchedule = new Integer[tih.getNextTimeSlot()];
for (Integer i = 0; i < roleSchedule.length; i++) {
if (r._roleSchedule.contains(i)) {
roleSchedule[i] = 1;
} else {
roleSchedule[i] = 0;
}
}
}
}
package mohawk.converter.pieces.rules;
import mohawk.global.helper.RoleHelper;
import mohawk.global.helper.TimeIntervalHelper;
import mohawk.global.pieces.Role;
import mohawk.global.pieces.Rule;
public class TRedRole_Rule {
public String ruleType;
public Integer startTime;
public Integer finishTime;
public Integer role;
public Integer[] precondition;
public Integer[] roleSchedule;
public TRedRole_Rule(Rule r, RoleHelper rh, TimeIntervalHelper tih) {
ruleType = r._type.toUzun();
startTime = r._adminTimeInterval.getStartTime();
finishTime = r._adminTimeInterval.getFinishTime();
role = rh.indexOf(r._role);
precondition = new Integer[rh.size()];
for (int i = 0; i < rh.size(); i++) {
Role role = rh.get(i);
// Ignore
int loc = r._preconditions.indexOf(role.toLimitedRole());
if (loc != -1) {
role = r._preconditions.get(loc);
if (role._not) {
precondition[i] = -1;
} else {
precondition[i] = 1;
}
} else {
precondition[i] = 0;
}
}
roleSchedule = new Integer[tih.getNextTimeSlot()];
for (Integer i = 0; i < roleSchedule.length; i++) {
if (r._roleSchedule.contains(i)) {
roleSchedule[i] = 1;
} else {
roleSchedule[i] = 0;
}
}
}
}
package mohawk.converter.pieces.rules;
import mohawk.global.helper.RoleHelper;
import mohawk.global.helper.TimeIntervalHelper;
import mohawk.global.pieces.Role;
import mohawk.global.pieces.Rule;
public class TRedRule_Rule {
public String ruleType;
public Integer startTime;
public Integer finishTime;
public Integer role;
public Integer[] precondition;
public Integer[] roleSchedule;
public TRedRule_Rule(Rule r, RoleHelper rh, TimeIntervalHelper tih) {
ruleType = r._type.toUzun();
startTime = r._adminTimeInterval.getStartTime();
finishTime = r._adminTimeInterval.getFinishTime();
role = rh.indexOf(r._role);
precondition = new Integer[rh.size()];
for (int i = 0; i < rh.size(); i++) {
Role role = rh.get(i);
// Ignore
int loc = r._preconditions.indexOf(role.toLimitedRole());
if (loc != -1) {
role = r._preconditions.get(loc);
if (role._not) {
precondition[i] = -1;
} else {
precondition[i] = 1;
}
} else {
precondition[i] = 0;
}
}
roleSchedule = new Integer[tih.getNextTimeSlot()];
for (Integer i = 0; i < roleSchedule.length; i++) {
if (r._roleSchedule.contains(i)) {
roleSchedule[i] = 1;
} else {
roleSchedule[i] = 0;
}
}
}
}
......@@ -9,9 +9,9 @@ import java.nio.file.Files;
import java.util.logging.Logger;
import mohawk.converter.generated.MohawkTARBACParser;
import mohawk.converter.pieces.rules.TRedRule_Rule;
import mohawk.converter.to.ConvertTo;
import mohawk.global.pieces.Rule;
import mohawk.global.pieces.rules.TRedRule_Rule;
import org.stringtemplate.v4.ST;
......
......@@ -9,9 +9,9 @@ import java.nio.file.Files;
import java.util.logging.Logger;
import mohawk.converter.generated.MohawkTARBACParser;
import mohawk.converter.pieces.rules.TRedRule_Rule;
import mohawk.converter.to.ConvertTo;
import mohawk.global.pieces.Rule;
import mohawk.global.pieces.rules.TRedRule_Rule;
import org.stringtemplate.v4.ST;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment