Skip to content
Snippets Groups Projects
Commit d7cc25e1 authored by René Schöne's avatar René Schöne
Browse files

Can run DrAST as a JAR now.

- removed DrAST config
- removed old Gradle subprojects
- changed Main to accept filename for input to be parsed
parent 5a2401b7
No related branches found
No related tags found
No related merge requests found
rootProject.name = 'ifm-refactoring-jastadd' rootProject.name = 'ifm-refactoring-jastadd'
include 'statemachine' include 'statemachine'
include 'trainbenchmark'
//include 'ragdoc-builder'
include 'ragdoc-view' include 'ragdoc-view'
...@@ -5,3 +5,4 @@ src/gen-res/ ...@@ -5,3 +5,4 @@ src/gen-res/
/bin/ /bin/
logs/ logs/
/doc/ /doc/
DrAST.cfg
#DrAST settings file.
#Mon Nov 18 17:23:41 CET 2019
normalEdgeWidth=1.0
showEdges=true
refEdgeWidth=2.0
NTA-depth=1
NTA-cached=1
dynamic-values=0
prevJar=build/libs/statemachine-0.1.jar
dashedVertexEdgeWidth=0.2
NTA-computed=0
normalVertexEdgeWidth=1.0
nodeThreshold=1000
showNodes=true
curvedEdges=true
dashedEdgeWidth=0.2
group 'de.tudresden.inf.st' group 'de.tudresden.inf.st'
version '2.0-SNAPSHOT' version '0.1'
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'jastadd' apply plugin: 'jastadd'
...@@ -62,25 +62,29 @@ buildscript { ...@@ -62,25 +62,29 @@ buildscript {
jar { jar {
manifest { manifest {
attributes( attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'de.tudresden.inf.st.statemachine.Main' 'Main-Class': 'de.tudresden.inf.st.statemachine.Main'
) )
} }
} }
task DrAST(type: JavaExec, dependsOn:jar) { task jarDrAst(type: Jar) {
group = "verification" group = "build"
description = 'run the DrAST visual debugger tool' description = 'create a jar to runthe DrAST visual debugger tool'
classpath = sourceSets.test.runtimeClasspath manifest {
main = 'de.tudresden.inf.st.statemachine.DrAstRunner' attributes 'Implementation-Title': 'DrAST visual debugger tool for StateMachine',
'Implementation-Version': project.version,
'Main-Class': 'de.tudresden.inf.st.statemachine.DrAstRunner'
}
archivesBaseName = 'drast-statemachine-all'
from { sourceSets.main.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
} }
String[] drastArguments = ['../libs/DrAST-1.2.2.jar'] task runDrAST(type: JavaExec, dependsOn:jar) {
task DrASTjar(type: JavaExec, dependsOn:jar) { group = "application"
group = "verification" description = 'run the DrAST visual debugger tool'
description = 'run the DrAST visual debugger tool as a JAR' classpath = sourceSets.main.runtimeClasspath
main = '-jar' main = 'de.tudresden.inf.st.statemachine.DrAstRunner'
args drastArguments
} }
def relastFiles = fileTree('src/main/jastadd/') { def relastFiles = fileTree('src/main/jastadd/') {
......
#!/bin/bash
java -Dlog4j2.disableJmx=true -jar build/libs/drast-statemachine-all-0.1.jar
...@@ -33,7 +33,7 @@ aspect JastAddAPIExtension { ...@@ -33,7 +33,7 @@ aspect JastAddAPIExtension {
return getLabel(); return getLabel();
} }
public String State.toString() { public String Element.toString() {
return getLabel(); return getLabel();
} }
} }
...@@ -38,14 +38,15 @@ public class DrAstRunner extends DrASTGUI { ...@@ -38,14 +38,15 @@ public class DrAstRunner extends DrASTGUI {
private static void openView() { private static void openView() {
guiHasBeenCreated = true; guiHasBeenCreated = true;
DrASTSettings.put(DrASTSettings.PREV_JAR, "build/libs/statemachine-0.1.jar"); DrASTSettings.put(DrASTSettings.PREV_JAR, "build/libs/statemachine-0.1.jar");
launch(new String[0]); DrASTSettings.put(DrASTSettings.PREV_TAIL_ARGS, "-Dlog4j2.disable.jmx=true");
launch();
con.onApplicationClose(); con.onApplicationClose();
} }
public void setRoot(Object root) { public void setRoot(Object root) {
long timeStart = System.currentTimeMillis(); long timeStart = System.currentTimeMillis();
DrAST newAst = new DrAST(root, TreeFilter.readFilter(con.getFilter())); DrAST newAst = new DrAST(root, TreeFilter.readFilter(con.getFilter()));
Log.info("Filter update: done after %d ms", new Object[]{System.currentTimeMillis() - timeStart}); Log.info("Filter update: done after %d ms", System.currentTimeMillis() - timeStart);
Platform.runLater(() -> { Platform.runLater(() -> {
mon.reset(newAst); mon.reset(newAst);
if (guiHasBeenCreated) { if (guiHasBeenCreated) {
...@@ -59,8 +60,8 @@ public class DrAstRunner extends DrASTGUI { ...@@ -59,8 +60,8 @@ public class DrAstRunner extends DrASTGUI {
public void start(Stage stage) throws Exception { public void start(Stage stage) throws Exception {
FXMLLoader loader = new FXMLLoader(); FXMLLoader loader = new FXMLLoader();
Parent rootView = (Parent)loader.load(this.getClass().getResource("/main.fxml").openStream()); Parent rootView = loader.load(this.getClass().getResource("/main.fxml").openStream());
con = (Controller)loader.getController(); con = loader.getController();
mon.setParentStage(stage); mon.setParentStage(stage);
mon.setController(con); mon.setController(con);
mon.setDrASTUI(this); mon.setDrASTUI(this);
......
package de.tudresden.inf.st.statemachine; package de.tudresden.inf.st.statemachine;
import de.tudresden.inf.st.statemachine.jastadd.model.*; import beaver.Parser;
import drast.model.DrAST; import de.tudresden.inf.st.statemachine.jastadd.model.State;
import de.tudresden.inf.st.statemachine.jastadd.model.StateMachine;
import de.tudresden.inf.st.statemachine.jastadd.model.Transition;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Set; import java.util.Set;
public class Main { public class Main {
@SuppressWarnings("WeakerAccess")
public static Object DrAST_root_node; public static Object DrAST_root_node;
public static void main(String[] args) { public static void main(String[] args) {
// manual construction of a simple statemachine if (args.length == 0) {
// (S) -- 1 --> (A) -- 3 --> (E) // manual construction of a simple statemachine
// ^ | // (S) -- 1 --> (B) -- 3 --> (E)
// \ / // ^ |
// `---- 2 ----* // \ /
StateMachine statemachine = new StateMachine(); // `---- 2 ----*
State start = new State(); StateMachine statemachine = new StateMachine();
start.setLabel("S"); State start = new State();
State stateA = new State(); start.setLabel("S");
stateA.setLabel("A"); State stateB = new State();
State end = new State(); stateB.setLabel("B");
end.setLabel("E"); State end = new State();
Transition t1 = new Transition(); end.setLabel("E");
t1.setLabel("1"); Transition t1 = new Transition();
Transition t2 = new Transition(); t1.setLabel("1");
t2.setLabel("2"); Transition t2 = new Transition();
Transition t3 = new Transition(); t2.setLabel("2");
t3.setLabel("3"); Transition t3 = new Transition();
t1.setFrom(start); t3.setLabel("3");
t1.setTo(stateA); t1.setFrom(start);
t2.setFrom(stateA); t1.setTo(stateB);
t2.setTo(start); t2.setFrom(stateB);
t3.setFrom(stateA); t2.setTo(start);
t3.setTo(end); t3.setFrom(stateB);
statemachine.addElement(start); t3.setTo(end);
statemachine.addElement(stateA); statemachine.addElement(start);
statemachine.addElement(end); statemachine.addElement(stateB);
statemachine.setInitial(start); statemachine.addElement(end);
statemachine.addFinal(end); statemachine.setInitial(start);
statemachine.addFinal(end);
// reachability analysis // reachability analysis
Set<Set<State>> sccs = statemachine.SCC(); Set<Set<State>> sccs = statemachine.SCC();
System.out.println("SCCs found:"); System.out.println("SCCs found:");
for (Set<State> scc : sccs) { for (Set<State> scc : sccs) {
System.out.println(scc); System.out.println(scc);
}
DrAST_root_node = statemachine;
} else {
// load the file given as first argument
try {
StateMachine stateMachine = ParserUtils.load(Paths.get(args[0]));
stateMachine.treeResolveAll();
DrAST_root_node = stateMachine;
} catch (IOException | Parser.Exception e) {
e.printStackTrace();
}
} }
DrAST_root_node = statemachine;
// DrAST.ui.DrASTUI debugger = new DrAST.ui.DrASTUI(statemachine);
} }
} }
package de.tudresden.inf.st.statemachine;
import beaver.Parser;
import de.tudresden.inf.st.statemachine.jastadd.model.StateMachine;
import de.tudresden.inf.st.statemachine.jastadd.parser.StateMachineParser;
import de.tudresden.inf.st.statemachine.jastadd.scanner.StateMachineScanner;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
/**
* Utility methods for loading statemachine files.
*
* @author rschoene - Initial contribution
*/
public class ParserUtils {
static StateMachine load(Path path) throws IOException, Parser.Exception {
Reader reader = Files.newBufferedReader(path);
StateMachineScanner scanner = new StateMachineScanner(reader);
StateMachineParser parser = new StateMachineParser();
StateMachine result = (StateMachine) parser.parse(scanner);
reader.close();
return result;
}
}
...@@ -4,14 +4,9 @@ import beaver.Parser; ...@@ -4,14 +4,9 @@ import beaver.Parser;
import de.tudresden.inf.st.statemachine.jastadd.model.State; import de.tudresden.inf.st.statemachine.jastadd.model.State;
import de.tudresden.inf.st.statemachine.jastadd.model.StateMachine; import de.tudresden.inf.st.statemachine.jastadd.model.StateMachine;
import de.tudresden.inf.st.statemachine.jastadd.model.Transition; import de.tudresden.inf.st.statemachine.jastadd.model.Transition;
import de.tudresden.inf.st.statemachine.jastadd.parser.StateMachineParser;
import de.tudresden.inf.st.statemachine.jastadd.scanner.StateMachineScanner;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -21,7 +16,7 @@ import static org.hamcrest.collection.IsEmptyCollection.empty; ...@@ -21,7 +16,7 @@ import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**
* TODO: Add description. * Testing the statemachine parser.
* *
* @author rschoene - Initial contribution * @author rschoene - Initial contribution
*/ */
...@@ -29,7 +24,7 @@ public class ParserTest { ...@@ -29,7 +24,7 @@ public class ParserTest {
@Test @Test
public void test1() throws IOException, Parser.Exception { public void test1() throws IOException, Parser.Exception {
StateMachine stateMachine = load(Paths.get("src", "test", "resources", "machine_one.sm")); StateMachine stateMachine = ParserUtils.load(Paths.get("src", "test", "resources", "machine_one.sm"));
assertEquals(6, stateMachine.getNumElement()); assertEquals(6, stateMachine.getNumElement());
assertEquals(3, stateMachine.states().size()); assertEquals(3, stateMachine.states().size());
...@@ -87,12 +82,4 @@ public class ParserTest { ...@@ -87,12 +82,4 @@ public class ParserTest {
return s.getOutgoingList().stream().map(Transition::getTo).collect(Collectors.toList()); return s.getOutgoingList().stream().map(Transition::getTo).collect(Collectors.toList());
} }
private static StateMachine load(Path path) throws IOException, Parser.Exception {
Reader reader = Files.newBufferedReader(path);
StateMachineScanner scanner = new StateMachineScanner(reader);
StateMachineParser parser = new StateMachineParser();
StateMachine result = (StateMachine) parser.parse(scanner);
reader.close();
return result;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment