-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPluginCallGraph.java
More file actions
109 lines (95 loc) · 4.6 KB
/
PluginCallGraph.java
File metadata and controls
109 lines (95 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package actions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import modules.ProjectModule;
import org.apache.commons.lang3.SystemUtils;
import services.FlServiceImpl;
import services.Resources;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.DumbAwareAction;
import org.jetbrains.annotations.NotNull;
import modules.PluginModule;
import services.runnables.RunCallGraphRunnable;
import ui.*;
import javax.swing.*;
import java.io.*;
import java.lang.Thread;
import static services.ProcessService.executeCommand;
public class PluginCallGraph extends DumbAwareAction {
/**
* When you click the Start Call Graph menu item, then this method will generate a call graph.
*
* @param e An event
*/
@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(), ""));
FlServiceImpl flService = new FlServiceImpl();
if (flService.isTestDataCollected()) {
/*
File file = new File(ProjectModule.getProjectPath() + File.separator +
"static_call_graph.html");
Writer fileWriter;
try {
if (!file.exists()) {
file.createNewFile();
}
fileWriter = new FileWriter(ProjectModule.getProjectPath() + File.separator +
"static_call_graph.html", false);
String command = "";
if (SystemUtils.IS_OS_WINDOWS) {
command = "\"" + PluginModule.getPythonBinPath() + "\""
+ " -m pyan " + "\"" + ProjectModule.getProjectPath() + File.separator + "*.py " + "\"" + " --uses --no-defines --colored --grouped --annotated --html ";
} else if (SystemUtils.IS_OS_LINUX) {
command = PluginModule.getPythonBinPath().replaceAll(" ", "\\ ")
+ " -m pyan " + ProjectModule.getProjectPath() + File.separator + "*.py --uses --no-defines --colored --grouped --annotated --html";
}
var proc = executeCommand(command);
var outputHtml = proc.getOutput();
outputHtml.forEach(m -> {
try {
fileWriter.write(m + System.lineSeparator());
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
fileWriter.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
} catch (NullPointerException exception) {
FileWriter fstream = null;
try {
fstream = new FileWriter("exception.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write(PluginModule.getPythonBinPath().replaceAll(" ", "\\ ")
+ " -m pyan " + ProjectModule.getProjectPath() + File.separator + "*.py --uses --no-defines --colored --grouped --annotated --html");
out.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
try {
Thread.sleep(3000);
} catch (InterruptedException z) {
Thread.currentThread().interrupt();
}
JOptionPane.showMessageDialog(null, "Creating call graph was successful.\nYou may open the generated html file in any browser." +
"\nThe file is located at " + ProjectModule.getProjectPath() + File.separator + "static_call_graph.html", "Call Graph is ready", JOptionPane.PLAIN_MESSAGE);
*/
//new PopUpView("static_call_graph.html").show();
String path = "/html/";
String filename = "callchains.html";
new CallGraphView(path + filename, e.getProject()).show();
} else {
Messages.showMessageDialog(
e.getProject(),
Resources.get("errors", "run_tests_error"),
Resources.get("titles", "data_not_collected_title"),
Messages.getErrorIcon());
}
}
}