diff options
Diffstat (limited to 'src/cppcheckplus/control/Main.java')
-rw-r--r-- | src/cppcheckplus/control/Main.java | 300 |
1 files changed, 153 insertions, 147 deletions
diff --git a/src/cppcheckplus/control/Main.java b/src/cppcheckplus/control/Main.java index 2759e2f..19d33cc 100644 --- a/src/cppcheckplus/control/Main.java +++ b/src/cppcheckplus/control/Main.java | |||
@@ -65,7 +65,7 @@ public class Main extends JFrame { | |||
65 | private final JFileChooser jfc = new JFileChooser();// 文件选择器 | 65 | private final JFileChooser jfc = new JFileChooser();// 文件选择器 |
66 | private final JFileChooser jfsettings = new JFileChooser();// 配置设定 | 66 | private final JFileChooser jfsettings = new JFileChooser();// 配置设定 |
67 | private final String projectPath; | 67 | private final String projectPath; |
68 | public MyTabPanel tabPanel; | 68 | public MyTabPanel centerTabPanel; |
69 | // 编辑代码的面板 | 69 | // 编辑代码的面板 |
70 | public MyTextPanel testCode; | 70 | public MyTextPanel testCode; |
71 | public String src = ""; // 目标源文件或目录的路径 | 71 | public String src = ""; // 目标源文件或目录的路径 |
@@ -73,9 +73,11 @@ public class Main extends JFrame { | |||
73 | public String flawfinderPath = null; | 73 | public String flawfinderPath = null; |
74 | public String paracppcheck = null; | 74 | public String paracppcheck = null; |
75 | public String paraflawfinder = null; | 75 | public String paraflawfinder = null; |
76 | public creatTable ct = new creatTable(); | 76 | public String clangtidyPath = null; |
77 | public String paraclangtidy = null; | ||
78 | public creatTable ct = new creatTable(); // 生成表格 | ||
77 | private MyOutlookPanel outlookPanel; | 79 | private MyOutlookPanel outlookPanel; |
78 | private MyTabPanel1 tabPanel2; | 80 | private MyTabPanel1 footTabPanel; |
79 | private MyShortcutPanel shortcutPanel; | 81 | private MyShortcutPanel shortcutPanel; |
80 | private MyTree tree; | 82 | private MyTree tree; |
81 | // 标记是否修改了工具路径 | 83 | // 标记是否修改了工具路径 |
@@ -136,9 +138,9 @@ public class Main extends JFrame { | |||
136 | // 读取文件内容并显示到代码区 | 138 | // 读取文件内容并显示到代码区 |
137 | textCode.setText(FileTools.readFile(result)); | 139 | textCode.setText(FileTools.readFile(result)); |
138 | // 如果代码标签页不存在,则创建一个 | 140 | // 如果代码标签页不存在,则创建一个 |
139 | if (!tabPanel.isSelectTabComponents("代码")) { | 141 | if (!centerTabPanel.isSelectTabComponents("代码")) { |
140 | tabPanel.addTab("代码", testCode); | 142 | centerTabPanel.addTab("代码", testCode); |
141 | tabPanel.isSelectTabComponents("代码"); | 143 | centerTabPanel.isSelectTabComponents("代码"); |
142 | } | 144 | } |
143 | break; | 145 | break; |
144 | case "onMenuLoad": | 146 | case "onMenuLoad": |
@@ -243,10 +245,10 @@ public class Main extends JFrame { | |||
243 | // 按类型排序:生成表格并按类型排序 | 245 | // 按类型排序:生成表格并按类型排序 |
244 | ct.makeTable(); | 246 | ct.makeTable(); |
245 | ct.ord(2); | 247 | ct.ord(2); |
246 | if (!tabPanel.isSelectTabComponents("结果")) { | 248 | if (!centerTabPanel.isSelectTabComponents("结果")) { |
247 | viewPanel = new ViewPanel(ct.results); | 249 | viewPanel = new ViewPanel(ct.results); |
248 | tabPanel.addTab("结果", createPage(viewPanel)); | 250 | centerTabPanel.addTab("结果", createPage(viewPanel)); |
249 | tabPanel.isSelectTabComponents("结果"); | 251 | centerTabPanel.isSelectTabComponents("结果"); |
250 | } else { | 252 | } else { |
251 | viewPanel.update(ct.results); | 253 | viewPanel.update(ct.results); |
252 | } | 254 | } |
@@ -255,10 +257,10 @@ public class Main extends JFrame { | |||
255 | // 按级别排序 | 257 | // 按级别排序 |
256 | ct.makeTable(); | 258 | ct.makeTable(); |
257 | ct.ord(3); | 259 | ct.ord(3); |
258 | if (!tabPanel.isSelectTabComponents("结果")) { | 260 | if (!centerTabPanel.isSelectTabComponents("结果")) { |
259 | viewPanel = new ViewPanel(ct.results); | 261 | viewPanel = new ViewPanel(ct.results); |
260 | tabPanel.addTab("结果", createPage(viewPanel)); | 262 | centerTabPanel.addTab("结果", createPage(viewPanel)); |
261 | tabPanel.isSelectTabComponents("结果"); | 263 | centerTabPanel.isSelectTabComponents("结果"); |
262 | } else { | 264 | } else { |
263 | viewPanel.update(ct.results); | 265 | viewPanel.update(ct.results); |
264 | } | 266 | } |
@@ -267,20 +269,19 @@ public class Main extends JFrame { | |||
267 | // 按文件排序 | 269 | // 按文件排序 |
268 | ct.makeTable(); | 270 | ct.makeTable(); |
269 | ct.ord(1); | 271 | ct.ord(1); |
270 | if (!tabPanel.isSelectTabComponents("结果")) { | 272 | if (!centerTabPanel.isSelectTabComponents("结果")) { |
271 | viewPanel = new ViewPanel(ct.results); | 273 | viewPanel = new ViewPanel(ct.results); |
272 | tabPanel.addTab("结果", createPage(viewPanel)); | 274 | centerTabPanel.addTab("结果", createPage(viewPanel)); |
273 | tabPanel.isSelectTabComponents("结果"); | 275 | centerTabPanel.isSelectTabComponents("结果"); |
274 | } else { | 276 | } else { |
275 | viewPanel.update(ct.results); | 277 | viewPanel.update(ct.results); |
276 | } | 278 | } |
277 | break; | 279 | break; |
278 | case "onSetCppcheckRoad": | 280 | case "onSetCppcheckRoad": |
279 | // cppcheck路径 | 281 | // cppcheck路径 |
280 | jfsettings.setFileSelectionMode(0);// 设定只能选择到文件 | 282 | jfsettings.setFileSelectionMode(JFileChooser.FILES_ONLY); |
281 | // int state = jfsettings.showOpenDialog(null); | 283 | if (jfsettings.showOpenDialog(null) == JFileChooser.CANCEL_OPTION) { |
282 | if (jfsettings.showOpenDialog(null) == 1) { | 284 | return; |
283 | return; // 撤销则返回 | ||
284 | } else { | 285 | } else { |
285 | File cppcheckFile = jfsettings.getSelectedFile(); | 286 | File cppcheckFile = jfsettings.getSelectedFile(); |
286 | String cppcheckPathTemp = | 287 | String cppcheckPathTemp = |
@@ -293,8 +294,7 @@ public class Main extends JFrame { | |||
293 | case "onSetFlawfinderRoad": | 294 | case "onSetFlawfinderRoad": |
294 | // flawfinder路径 | 295 | // flawfinder路径 |
295 | jfsettings.setFileSelectionMode( | 296 | jfsettings.setFileSelectionMode( |
296 | JFileChooser.FILES_ONLY);// 设定只能选择到文件 | 297 | JFileChooser.FILES_ONLY); |
297 | // int state = jfsettings.showOpenDialog(null); | ||
298 | if (jfsettings.showOpenDialog(null) == | 298 | if (jfsettings.showOpenDialog(null) == |
299 | JFileChooser.CANCEL_OPTION) { | 299 | JFileChooser.CANCEL_OPTION) { |
300 | return;// 撤销则返回 | 300 | return;// 撤销则返回 |
@@ -320,7 +320,6 @@ public class Main extends JFrame { | |||
320 | } | 320 | } |
321 | 321 | ||
322 | public static void main(String[] args) throws ParserConfigurationException { | 322 | public static void main(String[] args) throws ParserConfigurationException { |
323 | |||
324 | SwingUtilities.invokeLater(new Runnable() { | 323 | SwingUtilities.invokeLater(new Runnable() { |
325 | public void run() { | 324 | public void run() { |
326 | MyContorlUtil.setupLookAndFeel(); | 325 | MyContorlUtil.setupLookAndFeel(); |
@@ -331,7 +330,7 @@ public class Main extends JFrame { | |||
331 | } | 330 | } |
332 | 331 | ||
333 | private void execute(String src, String para) { | 332 | private void execute(String src, String para) { |
334 | System.out.println("cppcheckPath:" + cppcheckPath); | 333 | // FIXME:这段代码原因不详,十分令人疑惑 |
335 | if (changedpathcpp) { | 334 | if (changedpathcpp) { |
336 | MyContorlUtil.loadToolsRoad(settingsXML, this); | 335 | MyContorlUtil.loadToolsRoad(settingsXML, this); |
337 | changedpathcpp = false; | 336 | changedpathcpp = false; |
@@ -342,49 +341,44 @@ public class Main extends JFrame { | |||
342 | return; | 341 | return; |
343 | } | 342 | } |
344 | 343 | ||
345 | Runtime runtime = Runtime.getRuntime(); | 344 | Runtime[] runtime = {Runtime.getRuntime(), Runtime.getRuntime()}; |
346 | Process p = null; | 345 | Process[] p = new Process[2]; |
347 | Runtime runtime1 = Runtime.getRuntime(); | ||
348 | Process p1 = null; | ||
349 | try { | 346 | try { |
350 | // 指定模板执行cppcheck,格式化输出信息 | 347 | System.out.printf(cppcheckPath + " %s %s%n", para, src); |
351 | p = runtime.exec(String.format(cppcheckPath + | 348 | // 指定模板执行cppcheck,用于生成“结果”表格 |
349 | p[0] = runtime[0].exec(String.format(cppcheckPath + | ||
352 | " --template=\"cppcheck${file}${line}${severity}${id}${message}${cwe}\" %s %s", | 350 | " --template=\"cppcheck${file}${line}${severity}${id}${message}${cwe}\" %s %s", |
353 | para, src)); | 351 | para, src)); |
354 | final InputStream is1 = p.getInputStream(); | 352 | // 不使用模板,在底部标签页显示纯文本结果 |
355 | final InputStream is2 = p.getErrorStream(); | 353 | p[1] = runtime[1].exec( |
354 | String.format(cppcheckPath + " %s %s", para, src)); | ||
356 | 355 | ||
357 | // 不使用模板,捕获错误信息 | 356 | final InputStream[] stdout = |
358 | p1 = | 357 | {p[0].getInputStream(), p[1].getInputStream()}; |
359 | runtime.exec(String.format(cppcheckPath + " %s %s", para, src)); | 358 | final InputStream[] stderr = |
360 | System.out.printf(cppcheckPath + " %s %s%n", para, src); | 359 | {p[0].getErrorStream(), p[1].getErrorStream()}; |
361 | final InputStream is11 = p1.getInputStream(); | ||
362 | final InputStream is21 = p1.getErrorStream(); | ||
363 | 360 | ||
364 | // 处理标准输出 | 361 | // 板准输出 |
365 | new Thread() { | 362 | new Thread() { |
366 | @SuppressWarnings("resource") | 363 | @SuppressWarnings("resource") |
367 | public void run() { | 364 | public void run() { |
368 | |||
369 | BufferedReader br1 = | 365 | BufferedReader br1 = |
370 | new BufferedReader(new InputStreamReader(is1)); | 366 | new BufferedReader(new InputStreamReader(stdout[0])); |
371 | //StringBuilder l1 = new StringBuilder(); | 367 | StringBuilder l1 = new StringBuilder(); |
372 | try { | 368 | try { |
373 | |||
374 | String line1 = null; | 369 | String line1 = null; |
375 | int i = 0; | 370 | int i = 0; |
376 | textCheck.setText(""); | 371 | textCheck.setText(""); |
377 | while ((line1 = br1.readLine()) != null) { | 372 | while ((line1 = br1.readLine()) != null) { |
378 | i++; | ||
379 | textCheck.append(i + " " + line1 + ENTERWindows); | 373 | textCheck.append(i + " " + line1 + ENTERWindows); |
374 | i++; | ||
380 | } | 375 | } |
381 | } catch (Exception e) { | 376 | } catch (Exception e) { |
382 | e.printStackTrace(); | 377 | e.printStackTrace(); |
383 | System.out.println("inputError"); | 378 | System.out.println("inputError"); |
384 | } finally { | 379 | } finally { |
385 | try { | 380 | try { |
386 | //textCheck.setText(new String(l1.toString().getBytes(), "utf-8")); | 381 | stdout[0].close(); |
387 | is1.close(); | ||
388 | } catch (IOException e) { | 382 | } catch (IOException e) { |
389 | e.printStackTrace(); | 383 | e.printStackTrace(); |
390 | } | 384 | } |
@@ -392,22 +386,28 @@ public class Main extends JFrame { | |||
392 | } | 386 | } |
393 | }.start(); | 387 | }.start(); |
394 | 388 | ||
395 | // 处理错误流 | 389 | // 模板错误流,用于生成结果表格 |
396 | new Thread() { | 390 | new Thread() { |
397 | public void run() { | 391 | public void run() { |
398 | BufferedReader br2 = | 392 | BufferedReader br2 = |
399 | new BufferedReader(new InputStreamReader(is2)); | 393 | new BufferedReader(new InputStreamReader(stderr[0])); |
400 | StringBuilder l2 = new StringBuilder(); | 394 | StringBuilder l2 = new StringBuilder(); |
401 | try { | 395 | try { |
402 | String line2 = null; | 396 | String line2 = null; |
397 | int i = 0; | ||
403 | while ((line2 = br2.readLine()) != null) { | 398 | while ((line2 = br2.readLine()) != null) { |
404 | ct.toRowsOfCppcheckResult(line2); | 399 | ct.toRowsOfCppcheckResult(line2); |
400 | l2.append(i + " " + line2 + ENTERWindows); | ||
401 | i++; | ||
405 | } | 402 | } |
406 | } catch (Exception e) { | 403 | } catch (Exception e) { |
407 | e.printStackTrace(); | 404 | e.printStackTrace(); |
408 | } finally { | 405 | } finally { |
409 | try { | 406 | try { |
410 | is2.close(); | 407 | cppcheckResult.setText( |
408 | new String(l2.toString().getBytes(), | ||
409 | StandardCharsets.UTF_8)); | ||
410 | stderr[0].close(); | ||
411 | } catch (IOException e) { | 411 | } catch (IOException e) { |
412 | e.printStackTrace(); | 412 | e.printStackTrace(); |
413 | } | 413 | } |
@@ -415,11 +415,11 @@ public class Main extends JFrame { | |||
415 | } | 415 | } |
416 | }.start(); | 416 | }.start(); |
417 | 417 | ||
418 | // 的错误流 | 418 | // 的错误流,用于在底部标签页显示 |
419 | new Thread() { | 419 | new Thread() { |
420 | public void run() { | 420 | public void run() { |
421 | BufferedReader br2 = | 421 | BufferedReader br2 = |
422 | new BufferedReader(new InputStreamReader(is21)); | 422 | new BufferedReader(new InputStreamReader(stderr[1])); |
423 | StringBuilder l2 = new StringBuilder(); | 423 | StringBuilder l2 = new StringBuilder(); |
424 | cppcheckResult.setText(""); | 424 | cppcheckResult.setText(""); |
425 | try { | 425 | try { |
@@ -436,7 +436,7 @@ public class Main extends JFrame { | |||
436 | cppcheckResult.setText( | 436 | cppcheckResult.setText( |
437 | new String(l2.toString().getBytes(), | 437 | new String(l2.toString().getBytes(), |
438 | StandardCharsets.UTF_8)); | 438 | StandardCharsets.UTF_8)); |
439 | is21.close(); | 439 | stderr[1].close(); |
440 | } catch (IOException e) { | 440 | } catch (IOException e) { |
441 | e.printStackTrace(); | 441 | e.printStackTrace(); |
442 | } | 442 | } |
@@ -445,29 +445,29 @@ public class Main extends JFrame { | |||
445 | }.start(); | 445 | }.start(); |
446 | 446 | ||
447 | // 等待两个进程结束 | 447 | // 等待两个进程结束 |
448 | int exitCode = p.waitFor(); | 448 | int exitCode = p[0].waitFor(); |
449 | int exitCode1 = p1.waitFor(); | 449 | int exitCode1 = p[1].waitFor(); |
450 | if (exitCode == SUCCESS) { | 450 | if (exitCode == SUCCESS) { |
451 | System.out.println(SUCCESS_MESSAGE); | 451 | System.out.println(SUCCESS_MESSAGE); |
452 | |||
453 | } else { | 452 | } else { |
454 | System.err.println(ERROR_MESSAGE + exitCode); | 453 | System.err.println(ERROR_MESSAGE + exitCode); |
455 | } | 454 | } |
456 | p.destroy(); | 455 | p[0].destroy(); |
457 | p1.destroy(); | 456 | p[1].destroy(); |
458 | } catch (Exception e) { | 457 | } catch (Exception e) { |
459 | try { | 458 | try { |
460 | // 出现异常则关闭相关流 | 459 | // 出现异常则关闭相关流 |
461 | p.getErrorStream().close(); | 460 | p[0].getErrorStream().close(); |
462 | p.getInputStream().close(); | 461 | p[0].getInputStream().close(); |
463 | p.getOutputStream().close(); | 462 | p[0].getOutputStream().close(); |
464 | p1.getErrorStream().close(); | 463 | p[1].getErrorStream().close(); |
465 | p1.getInputStream().close(); | 464 | p[1].getInputStream().close(); |
466 | p1.getOutputStream().close(); | 465 | p[1].getOutputStream().close(); |
467 | } catch (Exception ee) { | 466 | } catch (Exception ee) { |
468 | } | 467 | } |
469 | } | 468 | } |
470 | if (!tabPanel.isSelectTabComponents("结果")) { | 469 | |
470 | if (!centerTabPanel.isSelectTabComponents("结果")) { | ||
471 | try { | 471 | try { |
472 | ct.makeTable(); | 472 | ct.makeTable(); |
473 | viewPanel = new ViewPanel(ct.results); | 473 | viewPanel = new ViewPanel(ct.results); |
@@ -475,8 +475,8 @@ public class Main extends JFrame { | |||
475 | e1.printStackTrace(); | 475 | e1.printStackTrace(); |
476 | System.out.println("图表生成错误"); | 476 | System.out.println("图表生成错误"); |
477 | } | 477 | } |
478 | tabPanel.addTab("结果", createPage(viewPanel)); | 478 | centerTabPanel.addTab("结果", createPage(viewPanel)); |
479 | tabPanel.isSelectTabComponents("结果"); | 479 | centerTabPanel.isSelectTabComponents("结果"); |
480 | } else { | 480 | } else { |
481 | try { | 481 | try { |
482 | ct.makeTable(); | 482 | ct.makeTable(); |
@@ -486,59 +486,65 @@ public class Main extends JFrame { | |||
486 | System.out.println("图表生成错误"); | 486 | System.out.println("图表生成错误"); |
487 | } | 487 | } |
488 | } | 488 | } |
489 | |||
490 | // 底部标签页切换到cppcheck | ||
491 | if (!footTabPanel.isSelectTabComponents("cppcheck")) { | ||
492 | footTabPanel.selectTabByOId("cppcheck"); | ||
493 | } | ||
489 | } | 494 | } |
490 | 495 | ||
491 | private void execute2(String src) { | 496 | private void execute2(String src) { |
492 | // clamh-tidy 检查 | 497 | // clang-tidy 检查 |
493 | Runtime runtime = Runtime.getRuntime(); | 498 | Runtime runtime = Runtime.getRuntime(); |
494 | Process p = null; | 499 | Process p = null; |
495 | try { | 500 | try { |
496 | // 修改为执行 clang-tidy | 501 | // 修改为执行 clang-tidy |
497 | String path = "C:\\MinGW\\include"; // FIXME: 需要修改为自己的路径 | ||
498 | Path srcPath = Paths.get(src); | 502 | Path srcPath = Paths.get(src); |
499 | String execable; | 503 | String execable; |
504 | // FIXME: | ||
505 | // 1.这里没能实现递归检查 | ||
506 | // 2.如何指定特定的检查规则? | ||
507 | // 3.如何指定特定的头文件路径? | ||
508 | // 4.是否需要指定代码标准 | ||
500 | if (Files.isDirectory(srcPath)) { | 509 | if (Files.isDirectory(srcPath)) { |
501 | // 是目录,则检查这个目录下所有cpp文件 | 510 | // 是目录,则检查这个目录下所有cpp文件 |
502 | execable = String.format( | 511 | execable = String.format( |
503 | "clang-tidy %s\\*.cpp --checks=* --header-filter=%s -- -std=c++17 -I %s", | 512 | "%s %s\\*.cpp --checks=* --header-filter=%s -- %s", |
504 | src, src, path); | 513 | clangtidyPath, src, src, paraclangtidy); |
505 | } else { | 514 | } else { |
506 | // 是文件,直接执行 | 515 | // 是文件,直接执行 |
507 | execable = String.format( | 516 | execable = |
508 | "clang-tidy %s --checks=* --header-filter=%s -- -std=c++17 -I %s", | 517 | String.format("%s %s --checks=* --header-filter=%s -- %s", |
509 | src, src, path); | 518 | clangtidyPath, src, src, paraclangtidy); |
510 | } | 519 | } |
511 | //String execable1 = String.format("clang-tidy %s --checks=* --header-filter=%s -- -std=c++17 -I %s", src, src, path); | ||
512 | //String execable2 = String.format("clang-tidy %s\\*.cpp --checks=* --header-filter=%s -- -std=c++17 -I %s", src,src, path); | ||
513 | //String execable = String.format("clang-tidy %s\\*.cpp --checks='*,misc-no-delete-this,-llvmlibc-restrict-system-libc-headers,-modernize-use-trailing-return-type' -- -std=c++17 -I %s", src, path); | 520 | //String execable = String.format("clang-tidy %s\\*.cpp --checks='*,misc-no-delete-this,-llvmlibc-restrict-system-libc-headers,-modernize-use-trailing-return-type' -- -std=c++17 -I %s", src, path); |
514 | System.out.println(execable); | 521 | System.out.println(execable); |
515 | 522 | ||
516 | // 执行 | 523 | // 执行 |
517 | p = runtime.exec(execable); // -- 表示之后是源文件 | 524 | p = runtime.exec(execable); |
518 | final InputStream is1 = p.getInputStream(); // 标准输出流 | 525 | final InputStream stdout = p.getInputStream(); |
519 | final InputStream is2 = p.getErrorStream(); // clang-tidy 的错误流 | 526 | final InputStream stderr = p.getErrorStream(); |
527 | |||
528 | clangResult.setText(""); | ||
520 | 529 | ||
521 | // 处理标准输出 | 530 | // 处理标准输出 |
522 | new Thread() { | 531 | new Thread() { |
523 | public void run() { | 532 | public void run() { |
524 | BufferedReader br1 = | 533 | BufferedReader br1 = |
525 | new BufferedReader(new InputStreamReader(is1)); | 534 | new BufferedReader(new InputStreamReader(stdout)); |
526 | StringBuilder l1 = new StringBuilder(); | 535 | StringBuilder l1 = new StringBuilder(); |
527 | try { | 536 | try { |
528 | String line1 = null; | 537 | String line1 = null; |
529 | while ((line1 = br1.readLine()) != null) { | 538 | while ((line1 = br1.readLine()) != null) { |
530 | // 只处理包含源文件路径的行 | 539 | l1.append(line1 + ENTERWindows); |
531 | if (line1.contains(src)) { | 540 | ct.toRowsOfClang(line1); |
532 | l1.append(line1).append(ENTERWindows); | ||
533 | // 如果有需要,可以将标准输出进行处理 | ||
534 | ct.toRowsOfClang(line1); | ||
535 | } | ||
536 | } | 541 | } |
537 | } catch (Exception e) { | 542 | } catch (Exception e) { |
538 | e.printStackTrace(); | 543 | e.printStackTrace(); |
539 | } finally { | 544 | } finally { |
540 | try { | 545 | try { |
541 | is1.close(); | 546 | clangResult.append(l1.toString()); |
547 | stdout.close(); | ||
542 | } catch (IOException e) { | 548 | } catch (IOException e) { |
543 | e.printStackTrace(); | 549 | e.printStackTrace(); |
544 | } | 550 | } |
@@ -546,46 +552,40 @@ public class Main extends JFrame { | |||
546 | } | 552 | } |
547 | }.start(); | 553 | }.start(); |
548 | 554 | ||
549 | // FIXME: 这一部分是否必要? | 555 | new Thread() { |
550 | //new Thread() { | 556 | public void run() { |
551 | // | 557 | BufferedReader br2 = |
552 | // | 558 | new BufferedReader(new InputStreamReader(stderr)); |
553 | // public void run() { | 559 | StringBuilder l2 = new StringBuilder(); |
554 | // BufferedReader br2 = new BufferedReader(new InputStreamReader(is2)); | 560 | try { |
555 | // StringBuilder l2 = new StringBuilder(); | 561 | String line2 = null; |
556 | // try { | 562 | int i = 0; |
557 | // String line2 = null; | 563 | l2.append(ENTERWindows + ENTERWindows); |
558 | // int i = 0; | 564 | while ((line2 = br2.readLine()) != null) { |
559 | // clangResult.setText(""); | 565 | l2.append(line2 + ENTERWindows); |
560 | // while ((line2 = br2.readLine()) != null) { | 566 | ct.toRowsOfClang(line2); |
561 | // l2.append(i + " " + line2 + ENTERWindows); | 567 | i++; |
562 | // ct.toRowsOfClang(line2); // 可能需要根据 clang-tidy 的输出格式进行调整 | 568 | } |
563 | // i++; | 569 | } catch (Exception e) { |
564 | // } | 570 | e.printStackTrace(); |
565 | // } catch (Exception e) { | 571 | System.out.println("inputError"); |
566 | // e.printStackTrace(); | 572 | } finally { |
567 | // System.out.println("inputError"); | 573 | try { |
568 | // } finally { | 574 | clangResult.append(l2.toString()); |
569 | // try { | 575 | stderr.close(); |
570 | // clangResult.setText(l2.substring(0, l2.length())); | 576 | } catch (IOException e) { |
571 | // is2.close(); | 577 | e.printStackTrace(); |
572 | // } catch (IOException e) { | 578 | } |
573 | // e.printStackTrace(); | 579 | } |
574 | // } | 580 | } |
575 | // } | 581 | }.start(); |
576 | // } | ||
577 | //}.start(); | ||
578 | 582 | ||
579 | int exitCode = p.waitFor(); | 583 | int exitCode = p.waitFor(); |
580 | if (exitCode == SUCCESS) { | 584 | if (exitCode == SUCCESS) { |
581 | System.out.println(SUCCESS_MESSAGE); | 585 | System.out.println(SUCCESS_MESSAGE); |
582 | |||
583 | } else { | 586 | } else { |
584 | System.err.println(ERROR_MESSAGE + exitCode); | 587 | System.err.println(ERROR_MESSAGE + exitCode); |
585 | } | 588 | } |
586 | |||
587 | // 为什么需要关闭两次? | ||
588 | p.destroy(); | ||
589 | p.destroy(); | 589 | p.destroy(); |
590 | } catch (Exception e) { | 590 | } catch (Exception e) { |
591 | try { | 591 | try { |
@@ -597,7 +597,7 @@ public class Main extends JFrame { | |||
597 | } | 597 | } |
598 | 598 | ||
599 | // 更新或者创建结果标签页,显示结果 | 599 | // 更新或者创建结果标签页,显示结果 |
600 | if (!tabPanel.isSelectTabComponents("结果")) { | 600 | if (!centerTabPanel.isSelectTabComponents("结果")) { |
601 | try { | 601 | try { |
602 | ct.makeTable(); | 602 | ct.makeTable(); |
603 | viewPanel = new ViewPanel(ct.results); | 603 | viewPanel = new ViewPanel(ct.results); |
@@ -605,8 +605,8 @@ public class Main extends JFrame { | |||
605 | e1.printStackTrace(); | 605 | e1.printStackTrace(); |
606 | System.out.println("图表生成错误"); | 606 | System.out.println("图表生成错误"); |
607 | } | 607 | } |
608 | tabPanel.addTab("结果", createPage(viewPanel)); | 608 | centerTabPanel.addTab("结果", createPage(viewPanel)); |
609 | tabPanel.isSelectTabComponents("结果"); | 609 | centerTabPanel.isSelectTabComponents("结果"); |
610 | } else { | 610 | } else { |
611 | try { | 611 | try { |
612 | ct.makeTable(); | 612 | ct.makeTable(); |
@@ -616,10 +616,13 @@ public class Main extends JFrame { | |||
616 | System.out.println("图表生成错误"); | 616 | System.out.println("图表生成错误"); |
617 | } | 617 | } |
618 | } | 618 | } |
619 | |||
620 | if (!footTabPanel.isSelectTabComponents("Clang")) { | ||
621 | footTabPanel.selectTabByOId("Clang"); | ||
622 | } | ||
619 | } | 623 | } |
620 | 624 | ||
621 | private void execute3(String src, String para, String tmpFileName) { | 625 | private void execute3(String src, String para, String tmpFileName) { |
622 | System.out.println("flawfinderPath:" + flawfinderPath); | ||
623 | // flawfinder | 626 | // flawfinder |
624 | if (changedpathflaw) { | 627 | if (changedpathflaw) { |
625 | MyContorlUtil.loadToolsRoad(settingsXML, this); | 628 | MyContorlUtil.loadToolsRoad(settingsXML, this); |
@@ -716,7 +719,7 @@ public class Main extends JFrame { | |||
716 | } catch (Exception ee) { | 719 | } catch (Exception ee) { |
717 | } | 720 | } |
718 | } | 721 | } |
719 | if (!tabPanel.isSelectTabComponents("结果")) { | 722 | if (!centerTabPanel.isSelectTabComponents("结果")) { |
720 | try { | 723 | try { |
721 | ct.makeTable(); | 724 | ct.makeTable(); |
722 | viewPanel = new ViewPanel(ct.results); | 725 | viewPanel = new ViewPanel(ct.results); |
@@ -724,8 +727,8 @@ public class Main extends JFrame { | |||
724 | e1.printStackTrace(); | 727 | e1.printStackTrace(); |
725 | System.out.println("图表生成错误"); | 728 | System.out.println("图表生成错误"); |
726 | } | 729 | } |
727 | tabPanel.addTab("结果", createPage(viewPanel)); | 730 | centerTabPanel.addTab("结果", createPage(viewPanel)); |
728 | tabPanel.isSelectTabComponents("结果"); | 731 | centerTabPanel.isSelectTabComponents("结果"); |
729 | } else { | 732 | } else { |
730 | try { | 733 | try { |
731 | ct.makeTable(); | 734 | ct.makeTable(); |
@@ -736,6 +739,9 @@ public class Main extends JFrame { | |||
736 | } | 739 | } |
737 | } | 740 | } |
738 | 741 | ||
742 | if (!footTabPanel.isSelectTabComponents("flawfinder")) { | ||
743 | footTabPanel.selectTabByOId("flawfinder"); | ||
744 | } | ||
739 | } | 745 | } |
740 | 746 | ||
741 | private void initSwing() throws UnsupportedEncodingException { | 747 | private void initSwing() throws UnsupportedEncodingException { |
@@ -774,11 +780,11 @@ public class Main extends JFrame { | |||
774 | 780 | ||
775 | // 面板加入布局 | 781 | // 面板加入布局 |
776 | centerPane.add(outlookPanel, "West"); | 782 | centerPane.add(outlookPanel, "West"); |
777 | centerPane.add(tabPanel, "Center"); | 783 | centerPane.add(centerTabPanel, "Center"); |
778 | centerPane.add(shortcutPanel, "East"); | 784 | centerPane.add(shortcutPanel, "East"); |
779 | 785 | ||
780 | // 底部添加第二个标签页面板,用于显示检查结果 | 786 | // 底部添加第二个标签页面板,用于显示检查结果 |
781 | contentPanel.add(tabPanel2, BorderLayout.SOUTH); | 787 | contentPanel.add(footTabPanel, BorderLayout.SOUTH); |
782 | } | 788 | } |
783 | 789 | ||
784 | private void initTree() { | 790 | private void initTree() { |
@@ -806,7 +812,7 @@ public class Main extends JFrame { | |||
806 | String command = item.getActionCommand(); | 812 | String command = item.getActionCommand(); |
807 | if (command.equals("Chart2")) { | 813 | if (command.equals("Chart2")) { |
808 | // 如果TabPanel不存在就create,否则就切换 | 814 | // 如果TabPanel不存在就create,否则就切换 |
809 | if (!tabPanel.isSelectTabComponents("结果")) { | 815 | if (!centerTabPanel.isSelectTabComponents("结果")) { |
810 | try { | 816 | try { |
811 | ct.makeTable(); | 817 | ct.makeTable(); |
812 | viewPanel = new ViewPanel(ct.results); | 818 | viewPanel = new ViewPanel(ct.results); |
@@ -814,20 +820,20 @@ public class Main extends JFrame { | |||
814 | e1.printStackTrace(); | 820 | e1.printStackTrace(); |
815 | System.out.println("图表生成错误"); | 821 | System.out.println("图表生成错误"); |
816 | } | 822 | } |
817 | tabPanel.addTab("结果", createPage(viewPanel)); | 823 | centerTabPanel.addTab("结果", createPage(viewPanel)); |
818 | tabPanel.isSelectTabComponents("结果"); | 824 | centerTabPanel.isSelectTabComponents("结果"); |
819 | } | 825 | } |
820 | } else if (command.equals("Map")) { | 826 | } else if (command.equals("Map")) { |
821 | // 代码标签页 | 827 | // 代码标签页 |
822 | if (!tabPanel.isSelectTabComponents("代码")) { | 828 | if (!centerTabPanel.isSelectTabComponents("代码")) { |
823 | tabPanel.addTab("代码", testCode); | 829 | centerTabPanel.addTab("代码", testCode); |
824 | tabPanel.isSelectTabComponents("代码"); | 830 | centerTabPanel.isSelectTabComponents("代码"); |
825 | } | 831 | } |
826 | } else if (command.equals("Process")) { | 832 | } else if (command.equals("Process")) { |
827 | // 进度 | 833 | // 进度 |
828 | if (!tabPanel.isSelectTabComponents("进度")) { | 834 | if (!centerTabPanel.isSelectTabComponents("进度")) { |
829 | tabPanel.addTab("进度", textCheck); | 835 | centerTabPanel.addTab("进度", textCheck); |
830 | tabPanel.isSelectTabComponents("进度"); | 836 | centerTabPanel.isSelectTabComponents("进度"); |
831 | } | 837 | } |
832 | } | 838 | } |
833 | } | 839 | } |
@@ -839,17 +845,17 @@ public class Main extends JFrame { | |||
839 | } | 845 | } |
840 | 846 | ||
841 | private void initTab() { | 847 | private void initTab() { |
842 | tabPanel = new MyTabPanel(); | 848 | centerTabPanel = new MyTabPanel(); |
843 | tabPanel.addMouseListener(new MouseAdapter() { | 849 | centerTabPanel.addMouseListener(new MouseAdapter() { |
844 | private boolean isMaximized() { | 850 | private boolean isMaximized() { |
845 | return outlookPanel.isShrinked(); | 851 | return outlookPanel.isShrinked(); |
846 | } | 852 | } |
847 | 853 | ||
848 | public void mouseClicked(MouseEvent e) { | 854 | public void mouseClicked(MouseEvent e) { |
849 | if (e.getClickCount() > 1) { | 855 | if (e.getClickCount() > 1) { |
850 | TabbedPaneUI ui = tabPanel.getUI(); | 856 | TabbedPaneUI ui = centerTabPanel.getUI(); |
851 | int tabIndex = | 857 | int tabIndex = |
852 | ui.tabForCoordinate(tabPanel, e.getX(), e.getY()); | 858 | ui.tabForCoordinate(centerTabPanel, e.getX(), e.getY()); |
853 | if (tabIndex != -1) { | 859 | if (tabIndex != -1) { |
854 | boolean maxed = isMaximized(); | 860 | boolean maxed = isMaximized(); |
855 | outlookPanel.setShrink(!maxed); | 861 | outlookPanel.setShrink(!maxed); |
@@ -867,17 +873,17 @@ public class Main extends JFrame { | |||
867 | } | 873 | } |
868 | 874 | ||
869 | private void initTab2() { | 875 | private void initTab2() { |
870 | tabPanel2 = new MyTabPanel1(); | 876 | footTabPanel = new MyTabPanel1(); |
871 | tabPanel2.addMouseListener(new MouseAdapter() { | 877 | footTabPanel.addMouseListener(new MouseAdapter() { |
872 | private boolean isMaximized() { | 878 | private boolean isMaximized() { |
873 | return outlookPanel.isShrinked(); | 879 | return outlookPanel.isShrinked(); |
874 | } | 880 | } |
875 | 881 | ||
876 | public void mouseClicked(MouseEvent e) { | 882 | public void mouseClicked(MouseEvent e) { |
877 | if (e.getClickCount() > 1) { | 883 | if (e.getClickCount() > 1) { |
878 | TabbedPaneUI ui = tabPanel2.getUI(); | 884 | TabbedPaneUI ui = footTabPanel.getUI(); |
879 | int tabIndex = | 885 | int tabIndex = |
880 | ui.tabForCoordinate(tabPanel2, e.getX(), e.getY()); | 886 | ui.tabForCoordinate(footTabPanel, e.getX(), e.getY()); |
881 | if (tabIndex != -1) { | 887 | if (tabIndex != -1) { |
882 | boolean maxed = isMaximized(); | 888 | boolean maxed = isMaximized(); |
883 | outlookPanel.setShrink(!maxed); | 889 | outlookPanel.setShrink(!maxed); |
@@ -894,9 +900,9 @@ public class Main extends JFrame { | |||
894 | cppcheckResult = cppcheckPanel.getTextArea(); | 900 | cppcheckResult = cppcheckPanel.getTextArea(); |
895 | clangResult = clangPanel.getTextArea(); | 901 | clangResult = clangPanel.getTextArea(); |
896 | 902 | ||
897 | tabPanel2.addTab("cppcheck", createPage1(cppcheckPanel)); | 903 | footTabPanel.addTab("cppcheck", createPage1(cppcheckPanel)); |
898 | tabPanel2.addTab("Clang", createPage1(clangPanel)); | 904 | footTabPanel.addTab("Clang", createPage1(clangPanel)); |
899 | tabPanel2.addTab("flawfinder", createPage1(flawfinderPanel)); | 905 | footTabPanel.addTab("flawfinder", createPage1(flawfinderPanel)); |
900 | } | 906 | } |
901 | 907 | ||
902 | private MyTabPage1 createPage1(JComponent pageContent) { | 908 | private MyTabPage1 createPage1(JComponent pageContent) { |