| 1 |
using System; |
|---|
| 2 |
using System.IO; |
|---|
| 3 |
using System.Xml; |
|---|
| 4 |
using FlashDevelop; |
|---|
| 5 |
using PluginCore; |
|---|
| 6 |
using PluginCore.Managers; |
|---|
| 7 |
using ProjectManager.Projects; |
|---|
| 8 |
using System.Windows.Forms; |
|---|
| 9 |
|
|---|
| 10 |
public class PMDResults |
|---|
| 11 |
{ |
|---|
| 12 |
public static void Execute() |
|---|
| 13 |
{ |
|---|
| 14 |
Project project = (Project)PluginBase.CurrentProject; |
|---|
| 15 |
|
|---|
| 16 |
XmlDocument xml = new XmlDocument(); |
|---|
| 17 |
|
|---|
| 18 |
string projectPath; |
|---|
| 19 |
string PMDFilePath = ""; |
|---|
| 20 |
|
|---|
| 21 |
if (project != null) { |
|---|
| 22 |
projectPath = project.Directory; |
|---|
| 23 |
PMDFilePath = projectPath + "/pmd.xml"; |
|---|
| 24 |
} |
|---|
| 25 |
else { |
|---|
| 26 |
projectPath = ""; |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
if (System.IO.File.Exists(PMDFilePath)) { |
|---|
| 30 |
xml.Load(PMDFilePath); |
|---|
| 31 |
} |
|---|
| 32 |
else { |
|---|
| 33 |
PMDFilePath = OpenFile(projectPath); |
|---|
| 34 |
if (PMDFilePath != "") xml.Load(PMDFilePath); |
|---|
| 35 |
else return; |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
if (xml.DocumentElement.Name != "pmd") |
|---|
| 40 |
{ |
|---|
| 41 |
ErrorManager.ShowWarning("This file is not FlexPMD file.", null); |
|---|
| 42 |
return; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
Globals.MainForm.CallCommand("PluginCommand", "ResultsPanel.ClearResults"); |
|---|
| 46 |
|
|---|
| 47 |
TraceManager.Add("\nFlexPMD:\n" + PMDFilePath, -2); |
|---|
| 48 |
string characterStr; |
|---|
| 49 |
string[] priorityName = new string[] {"Null", "Info", "Warning", "Error"}; |
|---|
| 50 |
bool isMinusNumber = false; |
|---|
| 51 |
int countError = 0; |
|---|
| 52 |
int countWarning = 0; |
|---|
| 53 |
int countInfo = 0; |
|---|
| 54 |
|
|---|
| 55 |
foreach (XmlNode file in xml.DocumentElement.SelectNodes("file")) { |
|---|
| 56 |
string filePath = file.Attributes["name"].Value; |
|---|
| 57 |
|
|---|
| 58 |
foreach (XmlNode violation in file.SelectNodes("violation")) { |
|---|
| 59 |
|
|---|
| 60 |
// minus line check |
|---|
| 61 |
string beginline = violation.Attributes["beginline"].Value; |
|---|
| 62 |
if (beginline == "-1") { beginline = "0"; isMinusNumber = true; } |
|---|
| 63 |
|
|---|
| 64 |
// col |
|---|
| 65 |
string begincolumn = violation.Attributes["begincolumn"].Value; |
|---|
| 66 |
if (begincolumn == "-1") { begincolumn = "0"; isMinusNumber = true; } |
|---|
| 67 |
string endcolumn = violation.Attributes["endcolumn"].Value; |
|---|
| 68 |
if (endcolumn == "-1") { endcolumn = "0"; isMinusNumber = true; } |
|---|
| 69 |
if (begincolumn == endcolumn) characterStr = begincolumn; |
|---|
| 70 |
else characterStr = begincolumn + "-" + endcolumn; |
|---|
| 71 |
|
|---|
| 72 |
// priority |
|---|
| 73 |
int priority = Int32.Parse(violation.Attributes["priority"].Value); |
|---|
| 74 |
int traceTypeNum = 0; // Null |
|---|
| 75 |
if (priority == 1) { traceTypeNum = 3; countError++; } // Error |
|---|
| 76 |
if (priority == 3) { traceTypeNum = 2; countWarning++; } // Warning |
|---|
| 77 |
if (priority == 5) { traceTypeNum = 1; countInfo++; } // Info |
|---|
| 78 |
|
|---|
| 79 |
TraceManager.Add(priorityName[traceTypeNum] + ":", traceTypeNum); |
|---|
| 80 |
TraceManager.Add(filePath.Replace("/","\\") + "(" + beginline + "): col: " + characterStr + " " + priorityName[traceTypeNum] + ": " + violation.InnerText.Replace("\n",""), traceTypeNum); |
|---|
| 81 |
|
|---|
| 82 |
} |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
//if (isMinusNumber) { TraceManager.Add("Attention:\n出力結果で本来「-1」と表示される箇所をResultsパネルの仕様の影響で「0」に置き換えて表示しています。", 0); } |
|---|
| 86 |
TraceManager.Add("Results:\n[Errors:" + countError + "] [Warnings:" + countWarning + "] [Informations:" + countInfo + "]", 0); |
|---|
| 87 |
|
|---|
| 88 |
Globals.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
private static string OpenFile(string projectPath) |
|---|
| 92 |
{ |
|---|
| 93 |
OpenFileDialog Dialog = new OpenFileDialog(); |
|---|
| 94 |
|
|---|
| 95 |
Dialog.InitialDirectory = projectPath; |
|---|
| 96 |
Dialog.Title = "Open File"; |
|---|
| 97 |
Dialog.Filter = "XML File (*.xml)|*.xml"; |
|---|
| 98 |
|
|---|
| 99 |
if (Dialog.ShowDialog() == DialogResult.OK) |
|---|
| 100 |
{ |
|---|
| 101 |
return Dialog.FileName; |
|---|
| 102 |
} |
|---|
| 103 |
else { |
|---|
| 104 |
return ""; |
|---|
| 105 |
} |
|---|
| 106 |
} |
|---|
| 107 |
} |
|---|