diff --git a/BuildFiles/Building/XBuildLog2Xml/App.config b/BuildFiles/Building/XBuildLog2Xml/App.config new file mode 100644 index 00000000..8e156463 --- /dev/null +++ b/BuildFiles/Building/XBuildLog2Xml/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/BuildFiles/Building/XBuildLog2Xml/Program.cs b/BuildFiles/Building/XBuildLog2Xml/Program.cs new file mode 100644 index 00000000..75414a08 --- /dev/null +++ b/BuildFiles/Building/XBuildLog2Xml/Program.cs @@ -0,0 +1,242 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Security; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Xml; + +namespace XBuildLog2Xml +{ + class Program + { + static void Main(string[] args) + { + string logFileName = "msbuild.log"; + + if (Debugger.IsAttached) + { + logFileName = "E:\\Temp\\" + logFileName; + } + + List projectResults = new List(); + int sumWarningsCode = 0; + int sumWarningsEnvironment = 0; + int sumErrors = 0; + + ProjectResult currentProject = new ProjectResult + { + ProjectName = "Solution" + }; + + const string projectStartRegex = "Building target \"Compile\" in project \"[a-zA-Z/]+/(?[A-Za-z0-9\\-]+)\\.csproj\""; + const string messageRegex = "(?[A-Za-z\\-_0-9]+).cs\\((?[0-9]+),[0-9]+\\): (?[a-z]+) CS(?[0-9]{4}): (?.+)"; + + Regex regexProject = new Regex (projectStartRegex, RegexOptions.Compiled); + Regex regexMessage = new Regex (messageRegex, RegexOptions.Compiled); + + + // first, read original log into parsed data + + + using (TextReader reader = new StreamReader (logFileName, Encoding.UTF8, true)) + { + string line = reader.ReadLine(); + while (line != null) + { + // 'Building target "Compile" in ".../.../[A-Za-z]+.csproj"' + // 'Database-ExchangeRates.cs(59,34): warning CS0219: The variable `testDate' is assigned but its value is never used' + + line = line.Trim(); + + Match matchProject = regexProject.Match (line); + if (matchProject.Success) + { + // Store old project + + projectResults.Add (currentProject); + + currentProject = new ProjectResult + { + ProjectName = "Project " + matchProject.Groups["projectName"].Value + }; + } + + Match matchMessage = regexMessage.Match (line); + + if (matchMessage.Success) + { + BuildMessage newMessage = new BuildMessage + { + Code = matchMessage.Groups["messageCode"].Value, + File = matchMessage.Groups["fileName"].Value, + Line = Int32.Parse (matchMessage.Groups["lineNumber"].Value), + Description = matchMessage.Groups["messageText"].Value + }; + + if (matchMessage.Groups["messageType"].Value.ToLowerInvariant() == "warning") + { + sumWarningsCode++; + newMessage.Type = MessageType.CodeWarning; + currentProject.CodeWarnings.Add (newMessage); + } + else + { + sumErrors++; + newMessage.Type = MessageType.Error; + currentProject.Errors.Add (newMessage); + } + } + else if (line.Contains ("error")) + { + currentProject.Errors.Add (new BuildMessage + { + Type = MessageType.Error, + Description = line + }); + sumErrors++; + } + else if (line.Contains ("warning")) + { + currentProject.EnvironmentWarnings.Add(new BuildMessage + { + Type = MessageType.EnvironmentWarning, + Description = line + }); + sumWarningsEnvironment++; + } + + line = reader.ReadLine(); + } + + projectResults.Add (currentProject); + } + + // and once we have it in data format, write it as an xml document + + using (XmlWriter xmlWriter = new XmlTextWriter ("xbuild.xml", Encoding.UTF8)) + { + xmlWriter.WriteStartDocument(); + xmlWriter.WriteStartElement ("xbuild"); + xmlWriter.WriteAttributeString ("environment_warning_count", sumWarningsEnvironment.ToString()); + xmlWriter.WriteAttributeString ("code_warning_count", sumWarningsCode.ToString()); + xmlWriter.WriteAttributeString ("error_count", sumErrors.ToString()); + + foreach (ProjectResult result in projectResults) + { + if (result.WarningsTotal + result.ErrorsTotal > 0) + { + xmlWriter.WriteStartElement ("project"); + xmlWriter.WriteAttributeString ("name", result.ProjectName); + + if (result.ErrorsTotal > 0) + { + WriteXmlBuildMessages (xmlWriter, result.Errors); + } + else + { + WriteXmlBuildMessages (xmlWriter, result.CodeWarnings); + WriteXmlBuildMessages (xmlWriter, result.EnvironmentWarnings); + } + + xmlWriter.WriteEndElement(); + } + } + + xmlWriter.WriteEndDocument(); + } + + + + } + + private static void WriteXmlBuildMessages (XmlWriter xmlWriter, List messages) + { + foreach (BuildMessage message in messages) + { + WriteXmlBuildMessage (xmlWriter, message); + } + } + + + private static void WriteXmlBuildMessage (XmlWriter xmlWriter, BuildMessage message) + { + if (message.Type == MessageType.Error) + { + xmlWriter.WriteStartElement ("error"); + } + else + { + xmlWriter.WriteStartElement("warning"); + } + + xmlWriter.WriteAttributeString ("message", message.Description); + xmlWriter.WriteAttributeString ("code", message.Code); // may be null or empty + + if (message.Line > 0 || !string.IsNullOrEmpty (message.File)) + { + xmlWriter.WriteAttributeString ("name", message.File); + xmlWriter.WriteAttributeString ("line", message.Line.ToString()); + } + + xmlWriter.WriteEndElement(); + } + + public enum MessageType + { + Unknown = 0, + Error, + CodeWarning, + EnvironmentWarning + }; + + public class ProjectResult + { + public ProjectResult() + { + Errors = new List(); + CodeWarnings = new List(); + EnvironmentWarnings = new List(); + } + + public string ProjectName { get; set; } + + public int ErrorsTotal + { + get { return Errors.Count; } + } + + public int WarningsTotal + { + get { return CodeWarningsTotal + EnvironmentWarningsTotal; } + } + + public int CodeWarningsTotal + { + get { return CodeWarnings.Count; } + } + + public int EnvironmentWarningsTotal + { + get { return EnvironmentWarnings.Count; } + } + + public List Errors; + public List CodeWarnings; + public List EnvironmentWarnings; + } + + public class BuildMessage + { + public MessageType Type { get; set; } + public string Code { get; set; } + public string Description { get; set; } + public string Folder { get; set; } + public string File { get; set; } + public int Line { get; set; } + } + } +} diff --git a/BuildFiles/Building/XBuildLog2Xml/Properties/AssemblyInfo.cs b/BuildFiles/Building/XBuildLog2Xml/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..ffbedbcc --- /dev/null +++ b/BuildFiles/Building/XBuildLog2Xml/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("XBuildLog2Xml")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("XBuildLog2Xml")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("cafe795c-105f-4006-9056-f5fc6f317dd0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/BuildFiles/Building/XBuildLog2Xml/XBuildLog2Xml.csproj b/BuildFiles/Building/XBuildLog2Xml/XBuildLog2Xml.csproj new file mode 100644 index 00000000..ef7dbf51 --- /dev/null +++ b/BuildFiles/Building/XBuildLog2Xml/XBuildLog2Xml.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {23891870-C691-4AE2-B76D-509A864CC8C5} + Exe + Properties + XBuildLog2Xml + XBuildLog2Xml + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BuildFiles/Building/XBuildLog2Xml/XBuildLog2Xml.sln b/BuildFiles/Building/XBuildLog2Xml/XBuildLog2Xml.sln new file mode 100644 index 00000000..8f4fac20 --- /dev/null +++ b/BuildFiles/Building/XBuildLog2Xml/XBuildLog2Xml.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XBuildLog2Xml", "XBuildLog2Xml.csproj", "{23891870-C691-4AE2-B76D-509A864CC8C5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {23891870-C691-4AE2-B76D-509A864CC8C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23891870-C691-4AE2-B76D-509A864CC8C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23891870-C691-4AE2-B76D-509A864CC8C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23891870-C691-4AE2-B76D-509A864CC8C5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal