Commit 95a99da6 authored by Jonathan Shahen's avatar Jonathan Shahen
Browse files

added a CUI and a made execProcess in the NuSMV class accessible

parent a84bfcc4
......@@ -28,7 +28,6 @@
<attribute name="javadoc_location" value="http://www.stringtemplate.org/api/"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mohawk-T Globals"/>
<classpathentry kind="output" path="bin"/>
</classpath>
package mohawk;
import java.util.ArrayList;
import java.util.Scanner;
import org.apache.commons.cli.Options;
public class MohawkCUI {
public static void main(String[] args) {
MohawkInstance inst = new MohawkInstance();
ArrayList<String> argv = new ArrayList<String>();
String cmd = "";
Scanner user_input = new Scanner(System.in);
Options options = new Options();
inst.setupOptions(options);
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("-noheader -mode bmc -run all -rbacspec data/regressiontests/positive1.spec !exit");
System.out.println("-noheader -mode bmc -run all -rbacspec data/regressiontests/positive2.spec !exit");
System.out.println("-noheader -mode bmc -run all -rbacspec data/regressiontests/positive3.spec !exit");
System.out.println(" !exit");
System.out.println(" !exit");
System.out.println("");
}
}
......@@ -36,6 +36,7 @@ import org.apache.commons.lang3.StringUtils;
public class MohawkInstance {
private final String VERSION = "v2.0.1";
private static final String AUTHORS = "Jonathan Shahen <jmshahen@uwaterloo.ca>; Karthick Jayaraman";
// Logger Fields
public static final Logger logger = Logger.getLogger("mohawk");
......@@ -132,7 +133,7 @@ public class MohawkInstance {
}
@SuppressWarnings("static-access")
private void setupOptions(Options options) {
public void setupOptions(Options options) {
// Add Information Options
options.addOption("help", false, "Print this message");
options.addOption("version", false, "Prints the version (" + VERSION + ") information");
......@@ -219,6 +220,29 @@ public class MohawkInstance {
.hasArg().create("run"));
}
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",
StringUtils.repeat("-", maxw) + "\nAuthors: " + AUTHORS + "\n" + StringUtils.repeat("-", 20), options,
StringUtils.repeat("-", maxw), true);
}
private void setupSmvSpecOptions(CommandLine cmd, Options options) {
// Load in SPEC Files
// SMV File
......@@ -391,21 +415,9 @@ public class MohawkInstance {
}
}
private Boolean setupReturnImmediatelyOptions(CommandLine cmd, Options options) {
private Boolean setupReturnImmediatelyOptions(CommandLine cmd, Options options) throws Exception {
if (cmd.hasOption("help") == true || cmd.getOptions().length < 1) {
HelpFormatter f = new HelpFormatter();
if (cmd.hasOption("maxw")) {
try {
Integer maxw = Integer.decode(cmd.getOptionValue("maxw"));
f.printHelp(maxw, "mohawk", StringUtils.repeat("-", maxw), options, StringUtils.repeat("-", maxw),
true);
} catch (Exception e) {
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);
}
printHelp(cmd, options);
return true;
}
......
......@@ -39,6 +39,7 @@ import java.util.List;
*
*/
public class NuSMV {
public static Process execProcess = null;
/**
*
......@@ -65,7 +66,7 @@ public class NuSMV {
// Run the NuSMV engine
ProcessBuilder builder = new ProcessBuilder(commands);
builder.redirectErrorStream(true); // combine the Error into the normal stream
Process execProcess = builder.start();
execProcess = builder.start();
execProcess.getOutputStream().write(smvmodel.getBytes());
execProcess.getOutputStream().flush();
......
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