From ad2eaf270717a6d4314cff35b4d337492060f0f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9ka?= Date: Fri, 21 Oct 2022 12:18:25 +0200 Subject: [PATCH 1/3] #15 run call-graph --- src/main/java/actions/PluginCallGraph.java | 3 +- src/main/java/modules/PluginModule.java | 27 ++++++++++------ src/main/java/services/CallGraphEdgeData.java | 1 - src/main/java/services/FlServiceImpl.java | 14 +++++---- .../runnables/RunCallGraphRunnable.java | 11 +++---- .../python/call_graphs/call_graph_edges.py | 26 +++------------- .../python/call_graphs/call_graph_maker.py | 31 ------------------- .../python/call_graphs/statical_call_graph.py | 27 +++++++++++++--- src/main/python/main.py | 8 ++--- 9 files changed, 61 insertions(+), 87 deletions(-) delete mode 100644 src/main/python/call_graphs/call_graph_maker.py diff --git a/src/main/java/actions/PluginCallGraph.java b/src/main/java/actions/PluginCallGraph.java index 8e6eb08..276208e 100644 --- a/src/main/java/actions/PluginCallGraph.java +++ b/src/main/java/actions/PluginCallGraph.java @@ -22,9 +22,8 @@ public class PluginCallGraph extends DumbAwareAction { */ @Override public void actionPerformed(@NotNull AnActionEvent e) { - String mainFileName = JOptionPane.showInputDialog(Resources.get("errors", "enter_main_file_message")); ProgressManager.getInstance().run(new RunCallGraphRunnable(e.getProject(), PluginModule.getPluginName(), - FileEditorManager.getInstance(e.getProject()).getSelectedTextEditor(), mainFileName)); + FileEditorManager.getInstance(e.getProject()).getSelectedTextEditor())); try { Thread.sleep(3000); } catch (InterruptedException z) { diff --git a/src/main/java/modules/PluginModule.java b/src/main/java/modules/PluginModule.java index 0c87547..03e0005 100644 --- a/src/main/java/modules/PluginModule.java +++ b/src/main/java/modules/PluginModule.java @@ -19,8 +19,7 @@ public class PluginModule { private static String checkPipBinPath = ""; private static final String PYTHON_SCRIPTS_FOLDER_NAME = "Scripts"; - private static final String CALL_GRAPH_SCRIPT_NAME = "call_graph_maker.py"; - private static final String CALL_ADD_HIGHLIGHT_TO_GRAPH_SCRIPT_NAME = "call_graph_highlight.py"; + private static final String CALL_ADD_HIGHLIGHT_TO_GRAPH_SCRIPT_NAME = "call_graphs/call_graph_highlight.py"; private static final String CALL_GRAPH_EDGES = "call_graphs/call_graph_edges.py"; private static String pythonBinPath; @@ -59,6 +58,7 @@ public static void refreshPluginPythonBinPath() { /** * Gets the installed charmfl's plugin name + * * @return the plugin name */ public static String getPluginName() { @@ -67,22 +67,16 @@ public static String getPluginName() { /** * Gets the installed charmfl's plugin id + * * @return the plugin id */ public static String getPluginId() { return PLUGIN_ID; } - /** - * Gets the call graph generator scripts path - * @return pathToInstalledCharmFL/call_graphs/call_graph_maker.py - */ - public static String getCallGraphScriptName() { - return pluginPath + File.separator + CALL_GRAPH_SCRIPT_NAME; - } - /** * Gets the call graph edge retriever scripts path + * * @return pathToInstalledCharmFL/call_graphs/call_graph_edges.py */ public static String getCallGraphEdges() { @@ -91,6 +85,7 @@ public static String getCallGraphEdges() { /** * Gets the call graph highlighter scripts path + * * @return pathToInstalledCharmFL/call_graphs/call_graph_highlight.py */ public static String callAddHighlightToGraphScriptName() { @@ -99,6 +94,7 @@ public static String callAddHighlightToGraphScriptName() { /** * Gets the path of the installed charmfl's plugin main.py (backend) + * * @return the path to main.py */ public static String getPyflBinPath() { @@ -107,6 +103,7 @@ public static String getPyflBinPath() { /** * Gets the path of the installed charmfl's plugin check_pip.py (checking requirements) + * * @return the path to main.py */ public static String getCheckPipBinPath() { @@ -120,6 +117,7 @@ public static String getPythonBinPath() { /** * Returns the path of pip script + * * @return path */ public static String getPipBinPath() { @@ -128,6 +126,7 @@ public static String getPipBinPath() { /** * Returns the requirements.txt + * * @return path and filename */ public static String getRequirementsFilePath() { @@ -136,6 +135,7 @@ public static String getRequirementsFilePath() { /** * Returns the results json's name + * * @return name */ public static final String getResultsJsonFileName() { @@ -148,6 +148,7 @@ public static void setPythonBinPath(String pythonBinPath) { /** * Returns whether Tarantula score calculation is the selected approach + * * @return true if tarantula is selected */ public static boolean isTarantulaSelected() { @@ -160,6 +161,7 @@ public static void setTarantulaSelected(boolean tarantulaSelected) { /** * Returns whether Ochiai score calculation is the selected approach + * * @return true if ochiai is selected */ public static boolean isOchiaiSelected() { @@ -172,6 +174,7 @@ public static void setOchiaiSelected(boolean ochiaiSelected) { /** * Returns whether Dstar score calculation is the selected approach + * * @return true if dstar is selected */ public static boolean isDStarSelected() { @@ -184,6 +187,7 @@ public static void setDStarSelected(boolean dStarSelected) { /** * Returns whether Wong2 score calculation is the selected approach + * * @return true if tarantula is selected */ public static boolean isWongIISelected() { @@ -196,6 +200,7 @@ public static void setWongIISelected(boolean wongIISelected) { /** * Ranking approach + * * @return true if maximum ranking is selected */ public static boolean isMaximumSelected() { @@ -208,6 +213,7 @@ public static void setMaximumSelected(boolean maximumSelected) { /** * Ranking approach + * * @return true if minimum ranking is selected */ public static boolean isMinimumSelected() { @@ -220,6 +226,7 @@ public static void setMinimumSelected(boolean minimumSelected) { /** * Ranking approach + * * @return true if average ranking is selected */ public static boolean isAverageSelected() { diff --git a/src/main/java/services/CallGraphEdgeData.java b/src/main/java/services/CallGraphEdgeData.java index ecf30e9..46064ff 100644 --- a/src/main/java/services/CallGraphEdgeData.java +++ b/src/main/java/services/CallGraphEdgeData.java @@ -18,7 +18,6 @@ public static void createHighlightedCallGraph(String relativePath, String method String pythonBinPath = ProjectRootManager.getInstance(ProjectModule.getProject()).getProjectSdk().getHomePath(); PluginModule.setPythonBinPath(pythonBinPath); String command = PluginModule.getPythonBinPath() + " " + PluginModule.getCallGraphEdges() + - " " + ProjectModule.getProjectPath() + File.separator + "**/*.py" + " " + ProjectModule.getProjectPath() + " " + nodeName; ProcessService.executeCommand(command); } diff --git a/src/main/java/services/FlServiceImpl.java b/src/main/java/services/FlServiceImpl.java index 237162b..d780c66 100644 --- a/src/main/java/services/FlServiceImpl.java +++ b/src/main/java/services/FlServiceImpl.java @@ -9,6 +9,7 @@ import com.intellij.openapi.project.Project; import com.intellij.util.messages.MessageBus; import models.bean.*; +import modules.PluginModule; import org.jetbrains.annotations.NotNull; import org.apache.commons.lang3.SystemUtils; @@ -28,18 +29,19 @@ public class FlServiceImpl { /** * This calls the subprocess of executing the call graph - * @param callGraphScriptName - * @param projectPath - * @param mainFileName * @param pythonBinPath + * @param pyflPath + * @param projectPath * @return */ - public ProcessResultData executeCallGraph(String callGraphScriptName, String projectPath, Object mainFileName, String pythonBinPath) { + public ProcessResultData executeCallGraph(String pythonBinPath, String pyflPath, String projectPath) { String command = ""; if (SystemUtils.IS_OS_WINDOWS) { - command = "\"" + pythonBinPath + "\" " + "\"" + callGraphScriptName + "\" " + "\"" + projectPath + "\" " + "\"" + mainFileName + "\" " + " -cg"; + command = "\"" + pythonBinPath + "\" " + + "\"" + pyflPath + "\" -d " + + "\"" + projectPath + "\"" + " -cg"; } - + System.out.println(command); return executeCommand(command); } diff --git a/src/main/java/services/runnables/RunCallGraphRunnable.java b/src/main/java/services/runnables/RunCallGraphRunnable.java index 14b71ab..4f7da21 100644 --- a/src/main/java/services/runnables/RunCallGraphRunnable.java +++ b/src/main/java/services/runnables/RunCallGraphRunnable.java @@ -18,14 +18,12 @@ public class RunCallGraphRunnable extends Task.Backgroundable implements Progress { private Editor editor; private Project project; - private Object mainFileName; static final int OK_CODE = 0; - public RunCallGraphRunnable(Project project, String title, Editor editor, Object mainFileName) { + public RunCallGraphRunnable(Project project, String title, Editor editor) { super(project, title, false); this.project = project; this.editor = editor; - this.mainFileName = mainFileName; } @Override @@ -184,10 +182,9 @@ public void execute(FlServiceImpl flService, ProgressIndicator progressIndicator progressIndicator.setText(Resources.get("states", "running_call_graph")); flService.executeCallGraph( - PluginModule.getCallGraphScriptName(), - ProjectModule.getProjectPath(), - mainFileName, - PluginModule.getPythonBinPath()); + PluginModule.getPythonBinPath(), + PluginModule.getPyflBinPath(), + ProjectModule.getProjectPath()); } @Override diff --git a/src/main/python/call_graphs/call_graph_edges.py b/src/main/python/call_graphs/call_graph_edges.py index a5c5fd6..083240a 100644 --- a/src/main/python/call_graphs/call_graph_edges.py +++ b/src/main/python/call_graphs/call_graph_edges.py @@ -1,30 +1,14 @@ -from IPython.display import HTML import os import sys from glob import glob -import pyan from call_graph_highlight import Highlighted_Callgraph +from statical_call_graph import StaticalCallGraph -files = [fn for fn in glob(sys.argv[1], recursive=True) - if 'venv' not in os.path.normpath(fn)] +project_path = sys.argv[1] +node = sys.argv[2] -project_path = sys.argv[2] -node = sys.argv[3] - -files_without_tests = [] -for file in files: - file_name = file[file.find(project_path)+len(project_path):] - if "test" not in file_name: - files_without_tests.append(file) - -call_graph = HTML(pyan.create_callgraph(filenames=files_without_tests, format='html')) - -destination = project_path + "/static_call_graph.html" - -call_graph_file = open(destination, 'w') -message = call_graph.data -call_graph_file.write(message) -call_graph_file.close() +call_graph = StaticalCallGraph(project_path) +call_graph.make_call_graph() highlight_maker = Highlighted_Callgraph(project_path, node) highlight_maker.add_highlighted_callgraph() \ No newline at end of file diff --git a/src/main/python/call_graphs/call_graph_maker.py b/src/main/python/call_graphs/call_graph_maker.py deleted file mode 100644 index 18f2d1c..0000000 --- a/src/main/python/call_graphs/call_graph_maker.py +++ /dev/null @@ -1,31 +0,0 @@ -import sys -from pathlib import Path - -import pyan -from IPython.display import HTML - - -def make_call_graph(project_path, main_name): - main_name_use = '/' + main_name - source_file = project_path + main_name_use - call_graph = HTML(pyan.create_callgraph(filenames=source_file, format='html')) - - destination = project_path + '/static_call_graph.html' - - call_graph_file = open(destination, 'w') - message = call_graph.data - call_graph_file.write(message) - call_graph_file.close() - - -"""project_path_arg = sys.argv[1] -main_name_arg = sys.argv[2] -try_main = project_path_arg + '/' + main_name_arg -call_graph_file_path = Path(try_main) -if call_graph_file_path.is_file(): - make_call_graph(project_path_arg, main_name_arg) -else: - problem_with_the_file = open(project_path_arg + '/static_call_graph.html', 'w') - problem_with_the_file.write('

Invalid ' - 'Main File

') - problem_with_the_file.close()""" \ No newline at end of file diff --git a/src/main/python/call_graphs/statical_call_graph.py b/src/main/python/call_graphs/statical_call_graph.py index e711f12..7b85191 100644 --- a/src/main/python/call_graphs/statical_call_graph.py +++ b/src/main/python/call_graphs/statical_call_graph.py @@ -1,9 +1,28 @@ +import os +from glob import glob import pyan from IPython.display import HTML class StaticalCallGraph: - def createHTML(self): - with open("call_graph.html", "w") as out_html: - html = HTML(pyan.create_callgraph(filenames="*.py", format="html")) - out_html.write(html.data) \ No newline at end of file + def __init__(self, project_path): + self.project_path = project_path + + def make_call_graph(self): + files = [fn for fn in glob(self.project_path + "/**/*.py", recursive=True) + if 'venv' not in os.path.normpath(fn)] + + files_without_tests = [] + for file in files: + file_name = file[file.find(self.project_path) + len(self.project_path):] + if "test" not in file_name: + files_without_tests.append(file) + + call_graph = HTML(pyan.create_callgraph(filenames=files_without_tests, format='html')) + + destination = self.project_path + "/static_call_graph.html" + + call_graph_file = open(destination, 'w') + message = call_graph.data + call_graph_file.write(message) + call_graph_file.close() \ No newline at end of file diff --git a/src/main/python/main.py b/src/main/python/main.py index 7bd41de..85636cd 100644 --- a/src/main/python/main.py +++ b/src/main/python/main.py @@ -8,6 +8,7 @@ from faultloc.Spectra import Spectra from faultloc.Metrics import Metrics from utils.Result_Builder import Result_Builder +from call_graphs.statical_call_graph import StaticalCallGraph # import call_graphs.statical_call_graph as cg @@ -15,9 +16,6 @@ from constans import COVERAGE_RC_FILE_NAME from error_codes import FAILED_COPY_COVERAGE_RC_FILE, FAILED_WRITE_PROJECT_COVERAGE_RC_FILE - -# from call_graph_maker import make_call_graph - # logging.basicConfig(filename='charmfl.log', level=logging.INFO, format='%(levelname)s:%(filename)s:%(lineno)d:%(message)s') @@ -74,8 +72,8 @@ def main(): output.write(result_builder.toJSON()) if (args["CallGraph"] == True): - call_graph = cg.StaticalCallGraph() - call_graph.createHTML() + call_graph = StaticalCallGraph(project_path) + call_graph.make_call_graph() if __name__ == "__main__": From 273ee753f9d7fa11d55ef92d9727f5d83a56369d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9ka?= Date: Fri, 21 Oct 2022 15:54:23 +0200 Subject: [PATCH 2/3] #15 remove sysout --- src/main/java/services/FlServiceImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/services/FlServiceImpl.java b/src/main/java/services/FlServiceImpl.java index d780c66..f41e5f5 100644 --- a/src/main/java/services/FlServiceImpl.java +++ b/src/main/java/services/FlServiceImpl.java @@ -41,7 +41,6 @@ public ProcessResultData executeCallGraph(String pythonBinPath, String pyflPath, "\"" + pyflPath + "\" -d " + "\"" + projectPath + "\"" + " -cg"; } - System.out.println(command); return executeCommand(command); } From 3b55496be46c611d3f9528f87d8763a34b61e2a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9ka?= Date: Fri, 21 Oct 2022 17:46:56 +0200 Subject: [PATCH 3/3] use hightlight on static call-graph --- src/main/java/ui/StatementOptions.java | 2 +- src/main/python/call_graphs/call_graph_highlight.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/ui/StatementOptions.java b/src/main/java/ui/StatementOptions.java index e66b8b7..115eb9b 100644 --- a/src/main/java/ui/StatementOptions.java +++ b/src/main/java/ui/StatementOptions.java @@ -113,7 +113,7 @@ public StatementOptions(ArrayList nameList, ArrayList lineList, } } } - new CallGraphHighlightedView().show(); + new CallGraphView().show(); }); diff --git a/src/main/python/call_graphs/call_graph_highlight.py b/src/main/python/call_graphs/call_graph_highlight.py index dd0f625..242c7e3 100644 --- a/src/main/python/call_graphs/call_graph_highlight.py +++ b/src/main/python/call_graphs/call_graph_highlight.py @@ -46,14 +46,13 @@ def __lighter(self, node: str): def __add_highlight_to_data(self, project_path, solution_node): graph_file_path = project_path + "/static_call_graph.html" - highlighted_graph = project_path + "/static_call_graph_highlighted.html" call_graph_start_file = open(graph_file_path, 'r') read_file = call_graph_start_file.read() new_data = read_file[:-66] new_data = new_data + solution_node new_data = new_data + read_file[-66:] call_graph_start_file.close() - call_graph_end_file = open(highlighted_graph, 'w') + call_graph_end_file = open(graph_file_path, 'w') call_graph_end_file.write(new_data) call_graph_end_file.close() @@ -70,6 +69,6 @@ def add_highlighted_callgraph(self): if call_graph_file_path.is_file(): self.__call_functions(self.project_path, self.node) else: - problem_with_the_file = open(self.project_path + "/static_call_graph_highlighted.html", 'w') + problem_with_the_file = open(self.project_path + "/static_call_graph.html", 'w') problem_with_the_file.write("

First run the Start Call Graph

") problem_with_the_file.close() \ No newline at end of file