using System; using System.IO; using System.Xml; using FlashDevelop; using PluginCore; using PluginCore.Managers; using ProjectManager.Projects; using System.Windows.Forms; public class PMDResults { public static void Execute() { Project project = (Project)PluginBase.CurrentProject; XmlDocument xml = new XmlDocument(); string projectPath; string PMDFilePath = ""; if (project != null) { projectPath = project.Directory; PMDFilePath = projectPath + "/pmd.xml"; } else { projectPath = ""; } if (System.IO.File.Exists(PMDFilePath)) { xml.Load(PMDFilePath); } else { PMDFilePath = OpenFile(projectPath); if (PMDFilePath != "") xml.Load(PMDFilePath); else return; } if (xml.DocumentElement.Name != "pmd") { ErrorManager.ShowWarning("This file is not FlexPMD file.", null); return; } Globals.MainForm.CallCommand("PluginCommand", "ResultsPanel.ClearResults"); TraceManager.Add("\nFlexPMD:\n" + PMDFilePath, -2); string characterStr; string[] priorityName = new string[] {"Null", "Info", "Warning", "Error"}; bool isMinusNumber = false; int countError = 0; int countWarning = 0; int countInfo = 0; foreach (XmlNode file in xml.DocumentElement.SelectNodes("file")) { string filePath = file.Attributes["name"].Value; foreach (XmlNode violation in file.SelectNodes("violation")) { // minus line check string beginline = violation.Attributes["beginline"].Value; if (beginline == "-1") { beginline = "0"; isMinusNumber = true; } // col string begincolumn = violation.Attributes["begincolumn"].Value; if (begincolumn == "-1") { begincolumn = "0"; isMinusNumber = true; } string endcolumn = violation.Attributes["endcolumn"].Value; if (endcolumn == "-1") { endcolumn = "0"; isMinusNumber = true; } if (begincolumn == endcolumn) characterStr = begincolumn; else characterStr = begincolumn + "-" + endcolumn; // priority int priority = Int32.Parse(violation.Attributes["priority"].Value); int traceTypeNum = 0; // Null if (priority == 1) { traceTypeNum = 3; countError++; } // Error if (priority == 3) { traceTypeNum = 2; countWarning++; } // Warning if (priority == 5) { traceTypeNum = 1; countInfo++; } // Info TraceManager.Add(priorityName[traceTypeNum] + ":", traceTypeNum); TraceManager.Add(filePath.Replace("/","\\") + "(" + beginline + "): col: " + characterStr + " " + priorityName[traceTypeNum] + ": " + violation.InnerText.Replace("\n",""), traceTypeNum); } } //if (isMinusNumber) { TraceManager.Add("Attention:\n出力結果で本来「-1」と表示される箇所をResultsパネルの仕様の影響で「0」に置き換えて表示しています。", 0); } TraceManager.Add("Results:\n[Errors:" + countError + "] [Warnings:" + countWarning + "] [Informations:" + countInfo + "]", 0); Globals.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults"); } private static string OpenFile(string projectPath) { OpenFileDialog Dialog = new OpenFileDialog(); Dialog.InitialDirectory = projectPath; Dialog.Title = "Open File"; Dialog.Filter = "XML File (*.xml)|*.xml"; if (Dialog.ShowDialog() == DialogResult.OK) { return Dialog.FileName; } else { return ""; } } }