Skip to content

Commit de74774

Browse files
committed
test
1 parent 85db0a3 commit de74774

File tree

3 files changed

+116
-103
lines changed

3 files changed

+116
-103
lines changed

haxe-checkstyle-intellij-plugin.jar

15.6 KB
Binary file not shown.

src/haxe/checkstyle/Install.java

+22-15
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import com.intellij.openapi.project.Project;
77
import com.intellij.openapi.ui.Messages;
88

9+
import java.io.BufferedReader;
910
import java.io.IOException;
11+
import java.io.InputStreamReader;
1012

1113
public class Install extends AnAction {
1214

@@ -15,26 +17,31 @@ public Install() {
1517
}
1618

1719
public void actionPerformed(AnActionEvent event) {
20+
Project project = event.getData(PlatformDataKeys.PROJECT);
21+
1822
try {
19-
Runtime rt = Runtime.getRuntime();
20-
Process pr = rt.exec("haxelib install checkstyle");
21-
try {
22-
pr.waitFor();
23-
} catch (InterruptedException e) {
24-
System.out.print(e);
23+
Process pr = Runtime.getRuntime().exec("haxelib install checkstyle");
24+
pr.waitFor();
25+
26+
StringBuffer output = new StringBuffer();
27+
BufferedReader reader = new BufferedReader(new InputStreamReader(pr.getInputStream()));
28+
29+
String line = "";
30+
String l = "";
31+
int i = 0;
32+
while ((line = reader.readLine()) != null) {
33+
if (i == 0) output.append(line + "\n");
34+
i++;
35+
l = line;
2536
}
37+
if (i > 1 && l != null) output.append(l);
2638

27-
Project project = event.getData(PlatformDataKeys.PROJECT);
28-
29-
Integer exitValue = pr.exitValue();
39+
Messages.showMessageDialog(project, output.toString(), "Haxe Checkstyle (haxelib)", Messages.getInformationIcon());
3040

31-
if (exitValue == 0) {
32-
Messages.showMessageDialog(project, "Library successfully installed.", "Haxe Checkstyle", Messages.getInformationIcon());
33-
} else {
34-
Messages.showMessageDialog(project, "Library installation failed.", "Haxe Checkstyle", Messages.getErrorIcon());
35-
}
3641
} catch (IOException e) {
37-
System.out.print(e);
42+
Messages.showMessageDialog(project, e.getMessage(), "Haxe Checkstyle (haxelib)", Messages.getErrorIcon());
43+
} catch (InterruptedException e) {
44+
Messages.showMessageDialog(project, e.getMessage(), "Haxe Checkstyle (haxelib)", Messages.getErrorIcon());
3845
}
3946
}
4047
}

src/haxe/checkstyle/Run.java

+94-88
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
import javax.swing.table.DefaultTableModel;
2626
import javax.xml.parsers.DocumentBuilder;
2727
import javax.xml.parsers.DocumentBuilderFactory;
28-
import java.awt.Font;
29-
import java.awt.Color;
28+
import java.awt.*;
3029
import java.io.File;
3130
import java.io.IOException;
3231

3332
public class Run extends AnAction {
3433

3534
String id;
35+
String projectPath;
3636
StatusBar statusBar;
3737
Balloon statusBaloon;
3838

@@ -55,102 +55,108 @@ private void hideBaloon() {
5555
}
5656

5757
private void runCheckstyle(Project project, ToolWindow window) {
58-
Runnable r = new Runnable() {
58+
/*Runnable r = new Runnable() {
5959
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-
}
13460
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++;
142136
}
143137
}
144-
hideBaloon();
138+
}
139+
} catch (Exception e) {
140+
e.printStackTrace();
141+
}
145142

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+
}
147150
}
148-
};
149-
new Thread(r).start();
151+
hideBaloon();
152+
153+
} catch (IOException e) {
154+
}
150155
}
151156

152157
public void actionPerformed(AnActionEvent event) {
153158
Project project = event.getData(PlatformDataKeys.PROJECT);
159+
projectPath = project.getBasePath();
154160
createStatusBaloon(project);
155161
showBaloon();
156162

0 commit comments

Comments
 (0)