Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main/java/actions/PluginCallGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 17 additions & 10 deletions src/main/java/modules/PluginModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,6 +58,7 @@ public static void refreshPluginPythonBinPath() {

/**
* Gets the installed charmfl's plugin name
*
* @return the plugin name
*/
public static String getPluginName() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -120,6 +117,7 @@ public static String getPythonBinPath() {

/**
* Returns the path of pip script
*
* @return path
*/
public static String getPipBinPath() {
Expand All @@ -128,6 +126,7 @@ public static String getPipBinPath() {

/**
* Returns the requirements.txt
*
* @return path and filename
*/
public static String getRequirementsFilePath() {
Expand All @@ -136,6 +135,7 @@ public static String getRequirementsFilePath() {

/**
* Returns the results json's name
*
* @return name
*/
public static final String getResultsJsonFileName() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -196,6 +200,7 @@ public static void setWongIISelected(boolean wongIISelected) {

/**
* Ranking approach
*
* @return true if maximum ranking is selected
*/
public static boolean isMaximumSelected() {
Expand All @@ -208,6 +213,7 @@ public static void setMaximumSelected(boolean maximumSelected) {

/**
* Ranking approach
*
* @return true if minimum ranking is selected
*/
public static boolean isMinimumSelected() {
Expand All @@ -220,6 +226,7 @@ public static void setMinimumSelected(boolean minimumSelected) {

/**
* Ranking approach
*
* @return true if average ranking is selected
*/
public static boolean isAverageSelected() {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/services/CallGraphEdgeData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/services/FlServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,18 +29,18 @@ 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";
}

return executeCommand(command);
}

Expand Down
11 changes: 4 additions & 7 deletions src/main/java/services/runnables/RunCallGraphRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ui/StatementOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public StatementOptions(ArrayList<String> nameList, ArrayList<Integer> lineList,
}
}
}
new CallGraphHighlightedView().show();
new CallGraphView().show();
});


Expand Down
26 changes: 5 additions & 21 deletions src/main/python/call_graphs/call_graph_edges.py
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 2 additions & 3 deletions src/main/python/call_graphs/call_graph_highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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("<!DOCTYPE html><html><head><style>h1 {color: red;}</style></head><body><h1>First run the Start Call Graph</h1></body></html>")
problem_with_the_file.close()
31 changes: 0 additions & 31 deletions src/main/python/call_graphs/call_graph_maker.py

This file was deleted.

27 changes: 23 additions & 4 deletions src/main/python/call_graphs/statical_call_graph.py
Original file line number Diff line number Diff line change
@@ -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)
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()
8 changes: 3 additions & 5 deletions src/main/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
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

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')


Expand Down Expand Up @@ -76,8 +74,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__":
Expand Down