25
25
import javax .swing .table .DefaultTableModel ;
26
26
import javax .xml .parsers .DocumentBuilder ;
27
27
import javax .xml .parsers .DocumentBuilderFactory ;
28
- import java .awt .Font ;
29
- import java .awt .Color ;
28
+ import java .awt .*;
30
29
import java .io .File ;
31
30
import java .io .IOException ;
32
31
33
32
public class Run extends AnAction {
34
33
35
34
String id ;
35
+ String projectPath ;
36
36
StatusBar statusBar ;
37
37
Balloon statusBaloon ;
38
38
@@ -55,102 +55,108 @@ private void hideBaloon() {
55
55
}
56
56
57
57
private void runCheckstyle (Project project , ToolWindow window ) {
58
- Runnable r = new Runnable () {
58
+ /* Runnable r = new Runnable() {
59
59
public void run() {
60
- try {
61
- Runtime rt = Runtime .getRuntime ();
62
- Process pr = rt .exec ("haxelib run checkstyle -s " + project .getBasePath () + "/src -r xml -p " + project .getBasePath () + "/.idea/checkstyle-report.xml -c " + project .getBasePath () + "/checkstyle.json" );
63
-
64
- try {
65
- pr .waitFor ();
66
- } catch (InterruptedException e ) {}
67
-
68
- Font font = new Font ("Arial" , Font .PLAIN , 12 );
69
- DefaultTableModel tm = new DefaultTableModel ();
70
- tm .addColumn ("File" );
71
- tm .addColumn ("Message" );
72
- tm .addColumn ("Line" );
73
- tm .addColumn ("Column" );
74
- tm .addColumn ("Severity" );
75
- JBTable issues = new JBTable (tm );
76
- issues .setFont (font );
77
- issues .setForeground (Color .BLUE );
78
- issues .getColumn ("File" ).setPreferredWidth (100 );
79
- issues .getColumn ("Message" ).setPreferredWidth (600 );
80
- issues .getColumn ("Line" ).setPreferredWidth (20 );
81
- issues .getColumn ("Column" ).setPreferredWidth (20 );
82
- issues .getColumn ("Severity" ).setPreferredWidth (30 );
83
- issues .getSelectionModel ().addListSelectionListener (new ListSelectionListener () {
84
- @ Override
85
- public void valueChanged (ListSelectionEvent e ) {
86
- if (issues .getSelectedRow () > -1 ) {
87
- String fileName = issues .getValueAt (issues .getSelectedRow (), 0 ).toString ();
88
- int row = Integer .parseInt (issues .getValueAt (issues .getSelectedRow (), 2 ).toString ()) - 1 ;
89
- int col = Integer .parseInt (issues .getValueAt (issues .getSelectedRow (), 3 ).toString ());
90
- File f = new File (fileName );
91
- VirtualFile vf = LocalFileSystem .getInstance ().findFileByIoFile (f );
92
- new OpenFileDescriptor (project , vf , row , col ).navigateInEditor (project , false );
93
- }
94
- }
95
- });
96
-
97
- JBScrollPane content = new JBScrollPane (issues );
98
- int issueCount = 0 ;
99
-
100
- try {
101
- File issuesXml = new File (project .getBasePath () + "/.idea/checkstyle-report.xml" );
102
- DocumentBuilderFactory dbFactory = DocumentBuilderFactory .newInstance ();
103
- DocumentBuilder dBuilder = dbFactory .newDocumentBuilder ();
104
- Document doc = dBuilder .parse (issuesXml );
105
- doc .getDocumentElement ().normalize ();
106
- NodeList nList = doc .getElementsByTagName ("file" );
107
-
108
- for (int temp = 0 ; temp < nList .getLength (); temp ++) {
109
- Node nNode = nList .item (temp );
110
- Element fileElement = (Element ) nNode ;
111
- NodeList messageList = nNode .getChildNodes ();
112
- for (int msg = 0 ; msg < messageList .getLength (); msg ++) {
113
- Node m = messageList .item (msg );
114
- if (m .getNodeType () == Node .ELEMENT_NODE ) {
115
-
116
- Element eElement = (Element ) m ;
117
-
118
- Object [] data = {
119
- fileElement .getAttribute ("name" ),
120
- eElement .getAttribute ("message" ),
121
- eElement .getAttribute ("line" ),
122
- eElement .getAttribute ("column" ),
123
- eElement .getAttribute ("severity" )
124
- };
125
-
126
- tm .addRow (data );
127
- issueCount ++;
128
- }
129
- }
130
- }
131
- } catch (Exception e ) {
132
- e .printStackTrace ();
133
- }
134
60
135
- if (issueCount == 0 ) {
136
- Messages .showMessageDialog (project , "No issues found." , id , Messages .getInformationIcon ());
137
- } else {
138
- window .getComponent ().getParent ().add (content );
139
- window .show (null );
140
- if (window != null ) {
141
- window .activate (null , false );
61
+ }
62
+ };
63
+ new Thread(r).start();*/
64
+
65
+ try {
66
+ Runtime rt = Runtime .getRuntime ();
67
+ Process pr = rt .exec ("haxelib run checkstyle -s " + projectPath + "/src -r xml -p " + projectPath + "/.idea/checkstyle-report.xml -c " + projectPath + "/checkstyle.json" );
68
+
69
+ try {
70
+ pr .waitFor ();
71
+ } catch (InterruptedException e ) {
72
+ }
73
+
74
+ Font font = new Font ("Arial" , Font .PLAIN , 12 );
75
+ DefaultTableModel tm = new DefaultTableModel ();
76
+ tm .addColumn ("File" );
77
+ tm .addColumn ("Message" );
78
+ tm .addColumn ("Line" );
79
+ tm .addColumn ("Column" );
80
+ tm .addColumn ("Severity" );
81
+ JBTable issues = new JBTable (tm );
82
+ issues .setFont (font );
83
+ issues .setForeground (Color .BLUE );
84
+ issues .getColumn ("File" ).setPreferredWidth (100 );
85
+ issues .getColumn ("Message" ).setPreferredWidth (600 );
86
+ issues .getColumn ("Line" ).setPreferredWidth (20 );
87
+ issues .getColumn ("Column" ).setPreferredWidth (20 );
88
+ issues .getColumn ("Severity" ).setPreferredWidth (30 );
89
+ issues .getSelectionModel ().addListSelectionListener (new ListSelectionListener () {
90
+ @ Override
91
+ public void valueChanged (ListSelectionEvent e ) {
92
+ if (issues .getSelectedRow () > -1 ) {
93
+ String fileName = projectPath + "/" + issues .getValueAt (issues .getSelectedRow (), 0 ).toString ();
94
+ int row = Integer .parseInt (issues .getValueAt (issues .getSelectedRow (), 2 ).toString ()) - 1 ;
95
+ int col = Integer .parseInt (issues .getValueAt (issues .getSelectedRow (), 3 ).toString ());
96
+ File f = new File (fileName );
97
+ VirtualFile vf = LocalFileSystem .getInstance ().findFileByIoFile (f );
98
+ new OpenFileDescriptor (project , vf , row , col ).navigateInEditor (project , false );
99
+ }
100
+ }
101
+ });
102
+
103
+ JBScrollPane content = new JBScrollPane (issues );
104
+ int issueCount = 0 ;
105
+
106
+ try {
107
+ File issuesXml = new File (project .getBasePath () + "/.idea/checkstyle-report.xml" );
108
+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory .newInstance ();
109
+ DocumentBuilder dBuilder = dbFactory .newDocumentBuilder ();
110
+ Document doc = dBuilder .parse (issuesXml );
111
+ doc .getDocumentElement ().normalize ();
112
+ NodeList nList = doc .getElementsByTagName ("file" );
113
+
114
+ for (int temp = 0 ; temp < nList .getLength (); temp ++) {
115
+ Node nNode = nList .item (temp );
116
+ Element fileElement = (Element ) nNode ;
117
+ NodeList messageList = nNode .getChildNodes ();
118
+ for (int msg = 0 ; msg < messageList .getLength (); msg ++) {
119
+ Node m = messageList .item (msg );
120
+ if (m .getNodeType () == Node .ELEMENT_NODE ) {
121
+
122
+ Element eElement = (Element ) m ;
123
+ String path = fileElement .getAttribute ("name" );
124
+ path = path .substring (projectPath .length () + 1 , path .length ());
125
+
126
+ Object [] data = {
127
+ path ,
128
+ eElement .getAttribute ("message" ),
129
+ eElement .getAttribute ("line" ),
130
+ eElement .getAttribute ("column" ),
131
+ eElement .getAttribute ("severity" )
132
+ };
133
+
134
+ tm .addRow (data );
135
+ issueCount ++;
142
136
}
143
137
}
144
- hideBaloon ();
138
+ }
139
+ } catch (Exception e ) {
140
+ e .printStackTrace ();
141
+ }
145
142
146
- } catch (IOException e ) {}
143
+ if (issueCount == 0 ) {
144
+ Messages .showMessageDialog (project , "No issues found." , id , Messages .getInformationIcon ());
145
+ } else {
146
+ window .getComponent ().getParent ().add (content );
147
+ if (window != null ) {
148
+ window .activate (null , false );
149
+ }
147
150
}
148
- };
149
- new Thread (r ).start ();
151
+ hideBaloon ();
152
+
153
+ } catch (IOException e ) {
154
+ }
150
155
}
151
156
152
157
public void actionPerformed (AnActionEvent event ) {
153
158
Project project = event .getData (PlatformDataKeys .PROJECT );
159
+ projectPath = project .getBasePath ();
154
160
createStatusBaloon (project );
155
161
showBaloon ();
156
162
0 commit comments