...
 
Commits (157)
......@@ -25,6 +25,7 @@
<root url="jar://$PROJECT_DIR$/libs/batik-util.jar!/" />
<root url="jar://$PROJECT_DIR$/libs/batik-xml.jar!/" />
<root url="jar://$PROJECT_DIR$/libs/jautomata-core.jar!/" />
<root url="jar://$PROJECT_DIR$/libs/com.microsoft.z3.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$PROJECT_DIR$/libs/commons-io-2.5-javadoc.jar!/" />
......
......@@ -7,6 +7,7 @@ TAR = tar
GZIP = gzip
GRADLE_NO_TEST = -x test
GRADLE_OPTIONS = --parallel
#GRADLE_OPTIONS =
GRADLE = $(shell which gradle)
GRADLE_VERSION_NEEDED = 3.3
ERROR_MSG = printf "$(COLOR)\nBuild with gradle failed. Falling back to regular javac command...\n$(RESET)"
......@@ -53,7 +54,8 @@ make ultraclean Clean the repository from binaries and compilation artif
make ttooljavac Build TTool only with javac
make ttoolnotest Build TTool with gradle, but do not execute test. Performs the install
make allnotest Builld all apps, but do not execute tests. Performs the install
make allnotest Builld all apps, but do not execute tests. Performs the install
make ttoolhelp Generate the help of TTool in HTML format
Other targets:
......@@ -126,6 +128,10 @@ export WEBCRAWLER_SERVER_BINARY = $(TTOOL_BUILD)/webcrawler-server.jar
export JTTOOL_DIR = $(TTOOL_PATH)/jttool
export JTTOOL_BINARY = $(TTOOL_BUILD)/jttool.jar
export TTOOL_HELP_DIR = $(TTOOL_PATH)/src/main/resources/help
MD_FILES=$(wildcard src/main/resources/help/*.md)
MD2HTML=$(MD_FILES:.md=.html)
all: ttool launcher ttool-cli graphminimize graphshow tiftranslator tmltranslator rundse remotesimulator webcrawler install
allnotest: GRADLE_OPTIONS += $(GRADLE_NO_TEST)
......@@ -140,7 +146,7 @@ ttoolnotest:
$(TTOOL_BINARY): FORCE
@($(GRADLE) :ttool:build $(GRADLE_OPTIONS)) || ($(ERROR_MSG) $(GRADLE_VERSION) $(GRADLE_VERSION_NEEDED)&& $(MAKE) -C $(TTOOL_DIR) -e $@)
ttooljavac:
ttooljavac:
$(MAKE) -C $(TTOOL_DIR)
$(MAKE) -C $(TTOOLCLI_DIR)
......@@ -195,6 +201,13 @@ $(WEBCRAWLER_SERVER_BINARY): FORCE
$(JTTOOL_BINARY): FORCE
@$(MAKE) -C $(JTTOOL_DIR) -e $@
ttoolhelp: html
html: $(MD2HTML)
%.html: %.md
pandoc $< -f markdown -t html -s -o $@ --lua-filter=doc/ttoolfilter.lua
# ========================================
# ========== DOCUMENTATION ==========
# ========================================
......
12929
\ No newline at end of file
12971
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -24,6 +24,7 @@ dependencies {
compileOnly name:'batik-dom'
compileOnly name:'batik-util'
compile name:'jautomata-core'
compile name:'com.microsoft.z3'
}
jar {
......
Main-Class: RunDSE
Class-Path: com.microsoft.z3.jar
......@@ -76,13 +76,21 @@ TMLCommand* TMLExeciCommand::prepareNextTransaction(){
std::string TMLExeciCommand::toString() const{
std::ostringstream outp;
outp << "Execi in " << TMLCommand::toString();
if (_execType == 0) {
outp << "Execi in " << TMLCommand::toString();
} else {
outp << "Execc in " << TMLCommand::toString();
}
return outp.str();
}
std::string TMLExeciCommand::toShortString() const{
std::ostringstream outp;
outp << _task->toString() << ": Execi " << _length;
if (_execType == 0) {
outp << _task->toString() << ": Execi " << _length;
} else {
outp << _task->toString() << ": Execc " << _length;
}
return outp.str();
}
This diff is collapsed.
......@@ -88,7 +88,7 @@ public class Command implements CommandInterface {
// Analyzing next command
for(Command c: subcommands) {
if ((c.getCommand().compareTo(nextCommand) == 0) || (c.getCommand().compareTo(nextCommand) == 0)) {
if ((c.getCommand().compareTo(nextCommand) == 0) || (c.getShortCommand().compareTo(nextCommand) == 0)) {
return c.executeCommand(args, interpreter);
}
}
......
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package cli;
import common.ConfigurationTTool;
import launcher.RTLLauncher;
import myutil.PluginManager;
import myutil.TraceManager;
import ui.MainGUI;
import ui.util.IconManager;
import java.io.File;
import java.util.BitSet;
import java.util.*;
/**
* Class Set
* Creation: 25/10/2018
* Version 2.0 25/10/2018
*
* @author Ludovic APVRILLE
*/
public class Help extends Command {
public Help() {
}
public List<Command> getListOfSubCommands() {
return subcommands;
}
public String getCommand() {
return "help";
}
public String getShortCommand() {
return "h";
}
public String getUsage() {
return "help or help <command>";
}
public String getDescription() {
return "Displays the general help of the help of a given command";
}
public String getExample() {
return "help action";
}
public String executeCommand(String command, Interpreter interpreter) {
if (command.trim().length() == 0) {
String s = "";
for(Command c: Interpreter.commands) {
s += c.getShortCommand() + "\t" + c.getCommand() + "\t" + c.getDescription() + "\n";
}
interpreter.print(s);
return null;
}
Command c = interpreter.getCommandByName(command);
if (c == null) {
return Interpreter.BAD_COMMAND_NAME;
}
interpreter.print(c.getHelp(1));
return null;
}
public void fillSubCommands() {
}
}
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package cli;
import common.ConfigurationTTool;
import launcher.RTLLauncher;
import myutil.PluginManager;
import myutil.TraceManager;
import ui.MainGUI;
import ui.TURTLEPanel;
import ui.util.IconManager;
import java.io.File;
import java.util.BitSet;
import java.util.*;
/**
* Class History
* Creation: 23/02/2019
* Version 2.0 23/02/2019
*
* @author Ludovic APVRILLE
*/
public class History extends Command {
public History() {
}
public List<Command> getListOfSubCommands() {
return subcommands;
}
public String getCommand() {
return "history";
}
public String getShortCommand() {
return "hi";
}
public String getUsage() { return "history"; }
public String getDescription() {
return "Prints all the non empty commands previously executed";
}
public String executeCommand(String command, Interpreter interpreter) {
TraceManager.addDev("History command");
return interpreter.printAllFormerCommands();
}
public void fillSubCommands() {
}
}
......@@ -48,6 +48,7 @@ import myutil.TraceManager;
import ui.*;
import ui.util.IconManager;
import java.io.*;
import myutil.*;
import java.util.*;
......@@ -58,8 +59,9 @@ import java.util.*;
*
* @author Ludovic APVRILLE
*/
public class Interpreter {
private final static Command[] commands = {new Action(), new Set(), new Wait(), new Print()};
public class Interpreter implements Runnable {
public final static Command[] commands = {new Help(), new Quit(), new Action(),
new Set(), new Wait(), new Print(), new History()};
// Errors
public final static String UNKNOWN = "Unknown command";
......@@ -70,6 +72,7 @@ public class Interpreter {
public final static String UNKNOWN_NEXT_COMMAND ="Invalid action: ";
public final static String TTOOL_NOT_STARTED ="TTool is not yet started. Cannot execute command.";
public final static String TTOOL_ALREADY_STARTED ="TTool is already started. Cannot execute command.";
public final static String BAD_COMMAND_NAME ="The provided command is invalid";
private String script;
......@@ -81,6 +84,7 @@ public class Interpreter {
private String error;
private boolean ttoolStarted = false;
public MainGUI mgui;
private Vector<String> formerCommands;
public Interpreter(String script, InterpreterOutputInterface printInterface, boolean show) {
......@@ -88,6 +92,36 @@ public class Interpreter {
this.printInterface = printInterface;
variables = new HashMap<>();
this.show = show;
formerCommands = new Vector<>();
}
@Override
public void run() {
interact();
}
public void interact() {
/*if (RawConsoleInput.isWindows) {
print("In Windows");
} else {
print("In Unix");
}*/
Scanner scanner = new Scanner(System.in);
int cptLine = 0;
printPrompt(cptLine);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
executeLine(line, cptLine, false);
cptLine ++;
printPrompt(cptLine);
}
}
private void printPrompt(int lineNb) {
System.out.print("" + lineNb + " -> ");
System.out.flush();
}
public void interpret() {
......@@ -96,63 +130,67 @@ public class Interpreter {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
cptLine ++;
executeLine(line, cptLine, true);
// Comment
if (line.startsWith("#")) {
}
scanner.close();
printInterface.print("All done. See you soon.");
printInterface.exit(1);
} else {
}
// Replace all double space by one unique space
line = Conversion.replaceAllString(line, " ", " ").trim();
//TraceManager.addDev("Handling line: " + line);
// Replace variable value in the current line
String lineWithNoVariable = removeVariablesIn(line);
TraceManager.addDev("Handling line: " + lineWithNoVariable);
// Analyze current line
error = "";
for(Command c: commands) {
if (lineWithNoVariable.startsWith(c.getCommand() + " ")) {
error = c.executeCommand( lineWithNoVariable.substring(c.getCommand().length() + 1,
lineWithNoVariable.length()).trim(), this);
break;
}
if (lineWithNoVariable.startsWith(c.getShortCommand() + " ")) {
error = c.executeCommand( lineWithNoVariable.substring(c.getShortCommand().length() + 1,
lineWithNoVariable.length()).trim(), this);
break;
}
}
private void executeLine(String line, int cptLine, boolean exitOnError) {
// Comment
line = line.trim();
if (line.length() == 0) {
return;
}
/*if (lineWithNoVariable.startsWith(SET + " ")) {
success = setVariable(lineWithNoVariable.substring(SET.length() + 1, lineWithNoVariable.length()).trim());
} else if (lineWithNoVariable.startsWith(ACTION + " ")) {
success = performAction(lineWithNoVariable.substring(ACTION.length() + 1, lineWithNoVariable.length()).trim());
} else if (lineWithNoVariable.startsWith(WAIT + " ")) {
success = waitFor(lineWithNoVariable.substring(WAIT.length() + 1, lineWithNoVariable.length()).trim());
} else if (lineWithNoVariable.startsWith(PRINT + " ")) {
success = performPrint(lineWithNoVariable.substring(PRINT.length() + 1, lineWithNoVariable.length()).trim());
} else {
success = false;
error = UNKNOWN;
if (line.startsWith("#")) {
}*/
} else {
formerCommands.add(line);
// Replace all double space by one unique space
line = Conversion.replaceAllString(line, " ", " ").trim();
//TraceManager.addDev("Handling line: " + line);
// Replace variable value in the current line
String lineWithNoVariable = removeVariablesIn(line).trim();
String begOfLine = lineWithNoVariable;
int index = lineWithNoVariable.indexOf(' ');
if (index > -1) {
begOfLine = begOfLine.substring(0, index).trim();
}
TraceManager.addDev("Handling line: " + lineWithNoVariable);
// Analyze current line
error = "";
for(Command c: commands) {
if (lineWithNoVariable.compareTo(c.getCommand()) == 0) {
error = c.executeCommand( lineWithNoVariable.substring(c.getCommand().length(),
lineWithNoVariable.length()).trim(), this);
break;
}
if (lineWithNoVariable.compareTo(c.getShortCommand()) == 0) {
error = c.executeCommand( lineWithNoVariable.substring(c.getShortCommand().length(),
lineWithNoVariable.length()).trim(), this);
break;
if (error != null) {
System.out.println("Error in line " + cptLine + " : " + error);
System.exit(-1);
}
}
if (error != null) {
System.out.println("Error in line " + cptLine + " : " + error);
if (exitOnError) {
System.exit(-1);
}
}
}
scanner.close();
printInterface.print("All done. See you soon.");
printInterface.exit(1);
}
......@@ -206,11 +244,22 @@ public class Interpreter {
ttoolStarted = b;
}
public void setMGUI(MainGUI mgui) {
this.mgui = mgui;
}
public boolean showWindow() {
return show;
}
public Command getCommandByName(String cmd) {
for (Command c: commands) {
if ((c.getShortCommand().compareTo(cmd) == 0) || (c.getCommand().compareTo(cmd) == 0)) {
return c;
}
}
return null;
}
public String getHelp() {
StringBuffer buf = new StringBuffer("");
......@@ -220,4 +269,18 @@ public class Interpreter {
return buf.toString();
}
public void print(String s) {
printInterface.print(s);
}
public String printAllFormerCommands() {
StringBuffer sb = new StringBuffer("");
for(int i=0; i<formerCommands.size(); i++) {
sb.append("" + i + "\t" + formerCommands.get(i) + "\n");
}
print(sb.toString());
return null;
}
}
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package cli;
import common.ConfigurationTTool;
import launcher.RTLLauncher;
import myutil.PluginManager;
import myutil.TraceManager;
import ui.MainGUI;
import ui.util.IconManager;
import java.io.File;
import java.util.BitSet;
import java.util.*;
/**
* Class Set
* Creation: 22/02/2019
* Version 2.0 22/02/2019
*
* @author Ludovic APVRILLE
*/
public class Quit extends Command {
public Quit() {
}
public String getCommand() {
return "quit";
}
public String getShortCommand() {
return "q";
}
public String getUsage() {
return "quit";
}
public String getDescription() {
return "Quits the interaction and closes all opened windows";
}
public String getExample() {
return "quit";
}
public String executeCommand(String command, Interpreter interpreter) {
System.exit(-1);
return null;
}
public void fillSubCommands() {
}
}
......@@ -48,6 +48,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Field;
/**
......@@ -141,6 +142,9 @@ public class ConfigurationTTool {
public static String AVATARExecutableSoclibCodeTraceCommand = "";
public static String AVATARExecutableSoclibTraceFile = "";
// Z3
public static String Z3LIBS = "";
// Ontology
//public static String RequirementOntologyWebsite = "";
......@@ -432,6 +436,9 @@ public class ConfigurationTTool {
sb.append("AVATARExecutableSocLibCodeTraceCommand: " + AVATARExecutableSoclibCodeTraceCommand + "\n");
sb.append("AVATARExecutableSocLibCodeTraceFile: " + AVATARExecutableSoclibTraceFile + "\n");
sb.append("\nZ3 Libs:\n");
sb.append("Z3LIBS: " + Z3LIBS + "\n");
sb.append("\nProVerif:\n");
sb.append("ProVerifCodeDirectory: " + ProVerifCodeDirectory + "\n");
sb.append("ProVerifVerifierPATH: " + ProVerifVerifierPath + "\n");
......@@ -707,6 +714,10 @@ public class ConfigurationTTool {
if (nl.getLength() > 0)
AVATARExecutableSoclibTraceFile(nl);
nl = doc.getElementsByTagName("Z3LIBS");
if (nl.getLength() > 0)
Z3LIBS(nl);
if (systemcOn) {
nl = doc.getElementsByTagName("SystemCHost");
if (nl.getLength() > 0)
......@@ -1441,6 +1452,15 @@ public class ConfigurationTTool {
}
}
private static void Z3LIBS(NodeList nl) throws MalformedConfigurationException {
try {
Element elt = (Element) (nl.item(0));
Z3LIBS = elt.getAttribute("data");
} catch (Exception e) {
throw new MalformedConfigurationException(e.getMessage());
}
}
private static void ProVerifCodeDirectory(NodeList nl) throws MalformedConfigurationException {
try {
Element elt = (Element) (nl.item(0));
......@@ -1663,4 +1683,80 @@ public class ConfigurationTTool {
}
}
// Returns an error string in case of failure
public static String loadZ3Libs() {
if ((ConfigurationTTool.Z3LIBS == null) || (ConfigurationTTool.Z3LIBS.length() == 0)) {
return "Z3 libraries not configured.\n Set them in configuration file (e.g. config.xml)\n" +
"For instance:\n<Z3LIBS data=\"/opt/z3/bin/libz3.so:/opt/z3/bin/libz3java.so\" />\n";
}
try {
String [] libs = ConfigurationTTool.Z3LIBS.split(":");
boolean setLibPath = false;
for (int i=0; i<libs.length; i++) {
// get the path and set it as a property of java lib path
String tmp = libs[i].trim();
if (tmp.length() > 0) {
if (setLibPath == false) {
File f = new File(tmp);
String dir = f.getParent();
//TraceManager.addDev("Old library path: " + System.getProperty("java.library.path"));
//TraceManager.addDev("Setting java library path to " + dir);
//System.setProperty("java.library.path", ".:" + dir);
addToJavaLibraryPath(new File(dir));
//TraceManager.addDev("New library path: " + System.getProperty("java.library.path"));
setLibPath = true;
}
TraceManager.addDev("Loading Z3 lib: " + tmp);
System.load(tmp);
}
}
} catch (UnsatisfiedLinkError e) {
return ("Z3 libs + " + ConfigurationTTool.Z3LIBS + " could not be loaded\n");
}
return null;
}
/**
* Adding a new dir to java.library.path.
* @param dir The new directory
*/
public static void addToJavaLibraryPath(File dir) {
final String LIBRARY_PATH = "java.library.path";
if (!dir.isDirectory()) {
throw new IllegalArgumentException(dir + " is not a directory.");
}
String javaLibraryPath = System.getProperty(LIBRARY_PATH);
System.setProperty(LIBRARY_PATH, javaLibraryPath + File.pathSeparatorChar + dir.getAbsolutePath());
resetJavaLibraryPath();
}
/**
* Deletes "java.library.path" cache
*/
public static void resetJavaLibraryPath() {
synchronized(Runtime.getRuntime()) {
try {
Field field = ClassLoader.class.getDeclaredField("usr_paths");
field.setAccessible(true);
field.set(null, null);
field = ClassLoader.class.getDeclaredField("sys_paths");
field.setAccessible(true);
field.set(null, null);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
} //
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package help;
import myutil.GenericTree;
import myutil.TraceManager;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.Vector;
import java.util.stream.Collectors;
/**
* Class HelpEntry
* Creation: 28/02/2019
* Version 2.0 28/02/2019
*
* @author Ludovic APVRILLE
*/
public class HelpEntry implements GenericTree {
public HelpEntry linkToParent;
Vector<HelpEntry> entries;
public String masterKeyword;
public String[] keywords;
public String pathToHTMLFile;
public String htmlContent;
public HelpEntry() {
}
public String getMasterKeyword() {
if (masterKeyword == null) {
return "Help not loaded";
}
return masterKeyword;
}
// Infos are: file of name, master key, list of keywords
public boolean fillInfos(String infos) {
infos = infos.trim();
infos = myutil.Conversion.replaceAllString(infos, " ", " ");
String[] splitted = infos.split(" ");
if (splitted.length < 3) {
TraceManager.addDev("Split too small");
return false;
}
pathToHTMLFile = splitted[0] + ".html";
masterKeyword = splitted[1];
keywords = new String[splitted.length - 1];
for (int i = 0; i < splitted.length - 1; i++) {
keywords[i] = splitted[i + 1];
}
//TraceManager.addDev("Infos ok");
return true;
}
public String getToolTip() {
if (keywords == null) {
return "";
}
if (keywords.length == 0) {
return "";
}
String ret = "";
for (int i=1; i<keywords.length; i++) {
ret += keywords[i] + " ";
}
return ret;
}
public int getNbInHierarchy() {
if (linkToParent == null) { return 0;
}
return 1 + linkToParent.getNbInHierarchy();
}
public void addKid(HelpEntry he) {
if (entries == null) {
entries = new Vector<>();
}
entries.add(he);
}
public boolean hasKids() {
if (entries == null) {
return false;
}
return entries.size() > 0;
}
public int getNbOfKids() {
if (entries == null) {
return 0;
}
return entries.size();
}
public HelpEntry getKid(int index) {
if (entries == null) {
return null;
}
return entries.get(index);
}
public int getIndexOfKid(HelpEntry he) {
if (entries == null) {
return 0;
}
return entries.indexOf(he);
}
public String getHTMLContent() {
if (htmlContent == null) {
try {
URL url = HelpManager.getURL(pathToHTMLFile);
URLConnection conn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
htmlContent = reader.lines().collect(Collectors.joining("\n"));
//TraceManager.addDev("htmlcontent=" + getHTMLContent());
htmlContent = filterHTMLContent(htmlContent);
} catch (Exception e) {
TraceManager.addDev("Exception when retreiving HTML of " + pathToHTMLFile);
return "";
}
}
return htmlContent;
}
private String filterHTMLContent(String input) {
int index = input.indexOf("<meta http-equiv=");
if (index == -1) {
return input;
}
String ret1 = input.substring(0, index);
String ret2 = input.substring(index+17, input.length());
index = ret2.indexOf("/>");
if (index == -1) {
return input;
}
ret2 = ret2.substring(index+2, ret2.length());
return ret1 + ret2;
}
public HelpEntry getFather() {
return linkToParent;
}
public String toString() {
if ((masterKeyword == null) || (keywords == null)) {
return "Help";
}
/*String ret = masterKeyword + " (";
for(int i=1; i<keywords.length; i++) {
ret += keywords[i] + " ";
}
ret += ")";*/
return masterKeyword.substring(0,1).toUpperCase() + masterKeyword.substring(1, masterKeyword.length());
}
public String printHierarchy(int n) {
String s = getHTMLContent();
String ret = "";
for (int i = 0; i < n; i++) {
ret += " ";
}
ret += toString() + "\n";
if (entries != null) {
for (HelpEntry he : entries) {
ret += he.printHierarchy(n + 1);
}
}
return ret;
}
public int getChildCount() {
//TraceManager.addDev("GetChild count in " + toString() + " = " + getNbOfKids());
return getNbOfKids();
}
public Object getChild(int index) {
return getKid(index);
}
public int getIndexOfChild(Object child) {
return getIndexOfKid((HelpEntry)child);
}
public HelpEntry getFromMasterKeyword(String search) {
if (masterKeyword != null) {
if (masterKeyword.compareTo(search) == 0) {
return this;
}
}
if (entries != null) {
HelpEntry ret;
for(HelpEntry he: entries) {
ret = he.getFromMasterKeyword(search);
if (ret != null) {
return ret;
}
}
}
return null;
}
public void addEntries(Vector<HelpEntry> list) {
list.add(this);
if (entries != null) {
for (HelpEntry he : entries) {
he.addEntries(list);
}
}
}
public int hasSimilarWords(String[] words) {
int result = 0;
for(String s:words) {
if (hasKeyword(s)) {
result ++;
}
}
return result;
}
public boolean hasKeyword(String word) {
for(String s: keywords) {
if (s.compareTo(word) == 0) {
return true;
}
}
return false;
}
}
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
*
* ludovic.apvrille AT enst.fr
*
* This software is a computer program whose purpose is to allow the
* edition of TURTLE analysis, design and deployment diagrams, to
* allow the generation of RT-LOTOS or Java code from this diagram,
* and at last to allow the analysis of formal validation traces
* obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
* from INRIA Rhone-Alpes.
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
package help;
import myutil.TraceManager;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Vector;
/**
* Class HelpManager
* Creation: 28/02/2019
* Version 2.0 28/02/2019
*
* @author Ludovic APVRILLE
*/
public class HelpManager extends HelpEntry {
private static String PATH_TO_INDEX = "helpTable.txt";
private static String INIT_CHAR = "-";
private boolean helpLoaded = false;
private Vector<HelpEntry> allEntries;
public HelpManager() {
linkToParent = null;
}
// Returns false in case of failure
public boolean loadEntries() {
if (helpLoaded) {
return true;
}
// Setup the root entry
fillInfos("none Help TTool help");
//File file = getContent(PATH_TO_INDEX);
URL url = getURL(PATH_TO_INDEX);
int lineNb = 0;
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
//TraceManager.addDev("File=" + file);
HelpEntry currentHelpEntry = this;
//try (BufferedReader br = new BufferedReader(new FileReader(file))) {
//try {
String line;
lineNb++;
while ((line = in.readLine()) != null) {
// while ((line = br.readLine()) != null) {
//TraceManager.addDev("Reading index line: " + line);
line = line.trim();
if (line.length() > 0) {
//TraceManager.addDev("Getting number of inits");
int nb = getNumberOfInit(line);
//TraceManager.addDev("Testing number of inits=" + nb);
if (nb > 0) {
//TraceManager.addDev("Before adding Entry");
currentHelpEntry = addEntry(currentHelpEntry, nb, removeInitChars(line));
//TraceManager.addDev("After adding Entry");
if (currentHelpEntry == null) {
TraceManager.addDev("\nHelp: error when loading help index file at line: " + lineNb + "\n");
//System.exit(-1);
return false;
}
}
}
lineNb ++;
}
} catch (Exception e) {
TraceManager.addDev("Help: exception when loading help index file at line: " + lineNb + "\n");
//System.exit(-1);
return false;
}
computeAllEntries();
helpLoaded = true;
return true;
}
public HelpEntry addEntry(HelpEntry entry, int inHierarchy, String infos) {
if (entry == null) {
return null;
}
if (inHierarchy < 1) {
return null;
}
// We must locate the corresponding father
int currentN = entry.getNbInHierarchy();
HelpEntry father = null;
// Missing an intermediate section?
if (inHierarchy > (currentN + 1)) {
return null;
}
//TraceManager.addDev("New node");
HelpEntry newNode = new HelpEntry();
boolean ok = newNode.fillInfos(infos);
if (!ok) {
TraceManager.addDev("HELP: Not ok");
return null;
}
//TraceManager.addDev("Before child");
// Child?
if (inHierarchy == (currentN + 1)) {
entry.addKid(newNode);
newNode.linkToParent = entry;
return newNode;
}
//TraceManager.addDev("Before brother");
// Brother?
if (inHierarchy == (currentN)) {
if (entry.getFather() == null) {
return null;
}
entry.getFather().addKid(newNode);
newNode.linkToParent = entry.getFather();
return newNode;
}
// Next section!
// We must locate the correct father
//TraceManager.addDev("Next section");
father = entry;
int nbOfAncestors = currentN - inHierarchy + 1;
//TraceManager.addDev("Next section ancestors:" + nbOfAncestors);
while (nbOfAncestors > 0) {
father = father.getFather();
if (father == null) {
return null;
}
nbOfAncestors--;
}
father.addKid(newNode);
newNode.linkToParent = father;
return newNode;
}
private String removeInitChars(String s) {
while (s.startsWith(INIT_CHAR)) {
s = s.substring(1, s.length());
}
return s;
}
private int getNumberOfInit(String s) {
int cpt = 0;
while (s.startsWith(INIT_CHAR)) {
cpt++;
s = s.substring(1, s.length());
}
return cpt;
}
public static URL getURL(String resource) {
return HelpManager.class.getResource(resource);
}
public static File getContent(String resource) {
try {
TraceManager.addDev("Getting help resource:" + resource);
URL url = HelpManager.class.getResource(resource);
if (url != null) {
TraceManager.addDev("help url = " + url);
File myFile = new File(url.toURI());
return myFile;
}
//TraceManager.addDev("NULL URL");
} catch (Exception e) {
}
return null;
}
public String printHierarchy() {
String top = "Help tree\n root has " + getNbOfKids() + " nodes.\n";
for (HelpEntry he : entries) {
top += he.printHierarchy(1);
}
return top;
}
private void computeAllEntries() {
allEntries = new Vector<>();
addEntries(allEntries);
}
public Vector<HelpEntry> getEntriesWithKeyword(String[] words) {
Vector<HelpEntry> result = new Vector<>();
for(HelpEntry he: allEntries) {