Author: spouliot
Date: 2006-09-17 20:16:42 -0400 (Sun, 17 Sep 2006)
New Revision: 65558
Added:
trunk/cecil/gendarme/console/HtmlResultWriter.cs
trunk/cecil/gendarme/console/IResultWriter.cs
trunk/cecil/gendarme/console/TextResultWriter.cs
trunk/cecil/gendarme/console/XmlResultWriter.cs
trunk/cecil/gendarme/console/gendarme.xsl
Modified:
trunk/cecil/gendarme/console/ChangeLog
trunk/cecil/gendarme/console/ConsoleRunner.cs
trunk/cecil/gendarme/console/Makefile.am
trunk/cecil/gendarme/console/console.mdp
Log:
2006-09-17 Sebastien Pouliot <[EMAIL PROTECTED]>
* console.mdp: Update MonoDevelop project file
* ConsoleRunner.cs: Add new options to the console runner.
* HtmlResultWriter.cs: New. Output HTML reports using the XML
output and the new XSL transform.
* IResultWriter.cs: New. Interface for all reporters. Original code
from Christian Birkl adapted/merged with existing code.
* Makefile.am: Add new files to the build.
* TextResultWriter.cs: New. Output text reports. Original code from
Christian Birkl adapted/merged with existing code.
* XmlResultWriter.cs: New. Output XML reports. Original code from
Christian Birkl adapted/merged with existing code.
2006-09-17 Christian Birkl <[EMAIL PROTECTED]>
* gendarme.xsl: New. XSLT file to transform XML output into HTML.
Modified: trunk/cecil/gendarme/console/ChangeLog
===================================================================
--- trunk/cecil/gendarme/console/ChangeLog 2006-09-18 00:16:01 UTC (rev
65557)
+++ trunk/cecil/gendarme/console/ChangeLog 2006-09-18 00:16:42 UTC (rev
65558)
@@ -1,3 +1,21 @@
+2006-09-17 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * console.mdp: Update MonoDevelop project file
+ * ConsoleRunner.cs: Add new options to the console runner.
+ * HtmlResultWriter.cs: New. Output HTML reports using the XML
+ output and the new XSL transform.
+ * IResultWriter.cs: New. Interface for all reporters. Original code
+ from Christian Birkl adapted/merged with existing code.
+ * Makefile.am: Add new files to the build.
+ * TextResultWriter.cs: New. Output text reports. Original code from
+ Christian Birkl adapted/merged with existing code.
+ * XmlResultWriter.cs: New. Output XML reports. Original code from
+ Christian Birkl adapted/merged with existing code.
+
+2006-09-17 Christian Birkl <[EMAIL PROTECTED]>
+
+ * gendarme.xsl: New. XSLT file to transform XML output into HTML.
+
2006-08-28 Sebastien Pouliot <[EMAIL PROTECTED]>
* ConsoleRunner.cs: Fix exception when rules.xml contains XML
Modified: trunk/cecil/gendarme/console/ConsoleRunner.cs
===================================================================
--- trunk/cecil/gendarme/console/ConsoleRunner.cs 2006-09-18 00:16:01 UTC
(rev 65557)
+++ trunk/cecil/gendarme/console/ConsoleRunner.cs 2006-09-18 00:16:42 UTC
(rev 65558)
@@ -44,8 +44,11 @@
private string config;
private string set;
private ArrayList assemblies;
+ private string format;
+ private string output;
private static Assembly assembly;
+ private static bool quiet;
static Assembly Assembly {
get {
@@ -68,6 +71,32 @@
return defaultValue;
return args [index];
}
+
+ // name can be
+ // - a filename (a single assembly)
+ // - a mask (*, ?) for multiple assemblies
+ // - a special file (@) containing a list of assemblies
+ void AddFiles (string name)
+ {
+ if ((name == null) || (name.Length == 0))
+ return;
+
+ if (name.StartsWith ("@")) {
+ // note: recursive (can contains @, masks and filenames)
+ using (StreamReader sr = File.OpenText (name.Substring
(1))) {
+ while (sr.Peek () >= 0) {
+ AddFiles (sr.ReadLine ());
+ }
+ }
+ } else if (name.IndexOfAny (new char[] { '*', '?' }) >= 0) {
+ string[] files = Directory.GetFiles
(Path.GetDirectoryName (name), Path.GetFileName (name));
+ foreach (string file in files) {
+ assemblies.Add (file);
+ }
+ } else {
+ assemblies.Add (Path.GetFullPath (name));
+ }
+ }
bool ParseOptions (string[] args)
{
@@ -89,19 +118,25 @@
case "--debug":
debug = true;
break;
+ case "--quiet":
+ quiet = true;
+ break;
case "--help":
return false;
+ case "--log":
+ format = "text";
+ output = GetNext (args, ++i, String.Empty);
+ break;
+ case "--xml":
+ format = "xml";
+ output = GetNext (args, ++i, String.Empty);
+ break;
+ case "--html":
+ format = "html";
+ output = GetNext (args, ++i, String.Empty);
+ break;
default:
- string filename = args[i];
- if (filename.IndexOfAny (new char[] { '*', '?'
}) >= 0) {
- string[] files = Directory.GetFiles
(Path.GetDirectoryName (filename),
- Path.GetFileName (filename));
- foreach (string file in files) {
- assemblies.Add (file);
- }
- } else {
- assemblies.Add (Path.GetFullPath
(filename));
- }
+ AddFiles (args[i]);
break;
}
}
@@ -146,6 +181,9 @@
static void Header ()
{
+ if (quiet)
+ return;
+
Assembly a = Assembly.GetExecutingAssembly();
Version v = a.GetName ().Version;
if (v.ToString () != "0.0.0.0") {
@@ -161,26 +199,50 @@
static void Help ()
{
- Console.WriteLine ("Usage: gendarme [--config configfile]
[--set ruleset] assembly");
+ Console.WriteLine ("Usage: gendarme [--config file] [--set
ruleset] [--{log|xml|html} file] assembly");
Console.WriteLine ("Where");
- Console.WriteLine (" --config configfile\tSpecify the
configuration file. Default is 'rules.xml'.");
+ Console.WriteLine (" --config file\tSpecify the configuration
file. Default is 'rules.xml'.");
Console.WriteLine (" --set ruleset\t\tSpecify the set of rules
to verify. Default is '*'.");
+ Console.WriteLine (" --log file\t\tSave the text output to the
specified file.");
+ Console.WriteLine (" --xml file\t\tSave the output, as XML, to
the specified file.");
+ Console.WriteLine (" --html file\t\tSave the output, as HTML,
to the specified file.");
+ Console.WriteLine (" --quiet\t\tDisplay minimal output
(results) from the runner.");
Console.WriteLine (" --debug\t\tEnable debugging output.");
Console.WriteLine (" assembly\t\tSpecify the assembly to
verify.");
Console.WriteLine ();
}
+ static void Write (string text)
+ {
+ if (!quiet)
+ Console.Write (text);
+ }
+
+ static void WriteLine (string text)
+ {
+ if (!quiet)
+ Console.WriteLine (text);
+ }
+
+ static void WriteLine (string text, params object[] args)
+ {
+ if (!quiet)
+ Console.WriteLine (text, args);
+ }
+
static int Main (string[] args)
{
- Header ();
ConsoleRunner runner = new ConsoleRunner ();
+ // runner options and configuration
+
try {
if (!runner.ParseOptions (args)) {
Help ();
return 1;
}
if (!runner.LoadConfiguration ()) {
+ Console.WriteLine ("No assembly file were
specified.");
return 1;
}
}
@@ -189,50 +251,56 @@
return 1;
}
+ // processing
+
+ Header ();
+ DateTime total = DateTime.UtcNow;
foreach (string assembly in runner.assemblies) {
+ DateTime start = DateTime.UtcNow;
AssemblyDefinition ad = null;
+ Write (assembly);
try {
ad = AssemblyFactory.GetAssembly (assembly);
+ try {
+ runner.Process (ad);
+ WriteLine (" - completed ({0}
seconds).", (DateTime.UtcNow - start).TotalSeconds);
+ }
+ catch (Exception e) {
+ WriteLine (" - error executing
rules{0}Details: {1}", Environment.NewLine, e);
+ }
}
catch (Exception e) {
- Console.WriteLine ("Error processing assembly
'{0}'{1}Details: {2}",
- assembly, Environment.NewLine, e);
+ WriteLine (" - error processing{0}\tDetails:
{1}", Environment.NewLine, e);
}
- try {
- runner.Process (ad);
- }
- catch (Exception e) {
- Console.WriteLine ("Error executing rules on
assembly '{0}'{1}Details: {2}",
- assembly, Environment.NewLine, e);
- }
}
+ WriteLine ("{0}{1} assemblies processed in {2} seconds).{0}",
Environment.NewLine, runner.assemblies.Count,
+ (DateTime.UtcNow - total).TotalSeconds);
- int i = 0;
- foreach (Violation v in runner.Violations.List) {
- RuleInformation ri =
RuleInformationManager.GetRuleInformation (v.Rule);
- Console.WriteLine ("{0}. {1}", ++i, ri.Name);
- Console.WriteLine ();
- Console.WriteLine ("Problem: {0}", String.Format
(ri.Problem, v.Violator));
- Console.WriteLine ();
- if(v.Messages != null && v.Messages.Count > 0) {
- Console.WriteLine ("Details:");
- foreach(object message in v.Messages) {
- Console.WriteLine(" {0}", message);
- }
- Console.WriteLine ();
- }
- Console.WriteLine ("Solution: {0}", String.Format
(ri.Solution, v.Violator));
- Console.WriteLine ();
- string url = ri.Uri;
- if (url.Length > 0) {
- Console.WriteLine ("More info available at:
{0}", url);
- Console.WriteLine ();
- }
- Console.WriteLine ();
+ // reporting
+
+ IResultWriter writer;
+ switch (runner.format) {
+ case "xml":
+ writer = new XmlResultWriter (runner.output);
+ break;
+ case "html":
+ writer = new HtmlResultWriter (runner.output);
+ break;
+ default:
+ writer = new TextResultWriter (runner.output);
+ break;
}
- if (i == 0) {
- Console.WriteLine ("No rule's violation were found.");
+ writer.Start ();
+ writer.Write (runner.assemblies);
+ writer.Write (runner.Rules);
+ foreach (Violation v in runner.Violations) {
+ writer.Write (v);
+ }
+ writer.End ();
+
+ if (runner.Violations.Count == 0) {
+ WriteLine ("No rule's violation were found.");
return 0;
}
return 1;
Added: trunk/cecil/gendarme/console/HtmlResultWriter.cs
===================================================================
--- trunk/cecil/gendarme/console/HtmlResultWriter.cs 2006-09-18 00:16:01 UTC
(rev 65557)
+++ trunk/cecil/gendarme/console/HtmlResultWriter.cs 2006-09-18 00:16:42 UTC
(rev 65558)
@@ -0,0 +1,87 @@
+//
+// HtmlResultWriter.cs
+//
+// Authors:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Reflection;
+using System.Xml;
+using System.Xml.Xsl;
+
+using Gendarme.Framework;
+
+public class HtmlResultWriter : IResultWriter {
+
+ private XmlResultWriter writer;
+ private string temp_filename;
+ private string final_filename;
+
+ public HtmlResultWriter (string output)
+ {
+ final_filename = output;
+ temp_filename = Path.GetTempFileName ();
+ writer = new XmlResultWriter (temp_filename);
+ }
+
+ public void Start ()
+ {
+ writer.Start ();
+ }
+
+ public void End ()
+ {
+ try {
+ writer.End ();
+ // load XSL file from embedded resource
+ using (Stream s = Assembly.GetExecutingAssembly
().GetManifestResourceStream ("gendarme.xsl")) {
+ // process the XML result with the XSL file
+ XslTransform xslt = new XslTransform ();
+ xslt.Load (new XmlTextReader (s), null, null);
+ xslt.Transform (temp_filename, final_filename,
null);
+ }
+ }
+ finally {
+ File.Delete (temp_filename);
+ }
+ }
+
+ public void Write (ICollection assemblies)
+ {
+ writer.Write (assemblies);
+ }
+
+ public void Write (Rules rules)
+ {
+ writer.Write (rules);
+ }
+
+ public void Write (Violation v)
+ {
+ writer.Write (v);
+ }
+}
Added: trunk/cecil/gendarme/console/IResultWriter.cs
===================================================================
--- trunk/cecil/gendarme/console/IResultWriter.cs 2006-09-18 00:16:01 UTC
(rev 65557)
+++ trunk/cecil/gendarme/console/IResultWriter.cs 2006-09-18 00:16:42 UTC
(rev 65558)
@@ -0,0 +1,44 @@
+//
+// ResultWriter
+//
+// Authors:
+// Christian Birkl <[EMAIL PROTECTED]>
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2006 Christian Birkl
+// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+
+using Gendarme.Framework;
+
+public interface IResultWriter {
+
+ void Start ();
+ void End ();
+
+ void Write (ICollection assemblies);
+ void Write (Rules rules);
+ void Write (Violation v);
+}
Modified: trunk/cecil/gendarme/console/Makefile.am
===================================================================
--- trunk/cecil/gendarme/console/Makefile.am 2006-09-18 00:16:01 UTC (rev
65557)
+++ trunk/cecil/gendarme/console/Makefile.am 2006-09-18 00:16:42 UTC (rev
65558)
@@ -1,18 +1,20 @@
gendarmedir=$(pkglibdir)
gendarme_SCRIPTS = gendarme.exe
-EXTRA_DIST = $(gendarme_sources) $(gendarme_sources_in)
+EXTRA_DIST = $(gendarme_sources) $(gendarme_sources_in) console.mdp
CLEANFILES = gendarme.exe
DISTCLEANFILES = Makefile.in
gendarme_sources_in = ../AssemblyInfo.cs.in
gendarme_generated_sources = $(gendarme_sources_in:.in=)
-gendarme_sources = ConsoleRunner.cs
+gendarme_sources = ConsoleRunner.cs IResultWriter.cs TextResultWriter.cs
XmlResultWriter.cs HtmlResultWriter.cs
+gendarme_resources = gendarme.xsl
gendarme_build_sources = $(addprefix $(srcdir)/, $(gendarme_sources))
gendarme_build_sources += $(gendarme_generated_sources)
gendarme.exe: $(gendarme_build_sources)
- $(MCS) -pkg:mono-cecil -r:../framework/Gendarme.Framework.dll
-r:System.Xml.dll -out:$@ $(gendarme_build_sources)
+ $(MCS) -pkg:mono-cecil -r:../framework/Gendarme.Framework.dll
-r:System.Xml.dll -out:$@ $(gendarme_build_sources) \
+ -resource:gendarme.xsl
self-test: gendarme.exe
gendarme gendarme.exe
Added: trunk/cecil/gendarme/console/TextResultWriter.cs
===================================================================
--- trunk/cecil/gendarme/console/TextResultWriter.cs 2006-09-18 00:16:01 UTC
(rev 65557)
+++ trunk/cecil/gendarme/console/TextResultWriter.cs 2006-09-18 00:16:42 UTC
(rev 65558)
@@ -0,0 +1,95 @@
+//
+// ResultWriter
+//
+// Authors:
+// Christian Birkl <[EMAIL PROTECTED]>
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2006 Christian Birkl
+// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+using System.IO;
+
+using Gendarme.Framework;
+
+public class TextResultWriter : IResultWriter {
+
+ private TextWriter writer;
+ private bool need_closing;
+ private int index;
+
+ public TextResultWriter (string output)
+ {
+ if ((output == null) || (output.Length == 0))
+ writer = Console.Out;
+ else {
+ writer = new StreamWriter (output);
+ need_closing = true;
+ }
+ }
+
+ public void Start ()
+ {
+ index = 0;
+ }
+
+ public void End ()
+ {
+ if (need_closing)
+ writer.Close ();
+ }
+
+ public void Write (ICollection assemblies)
+ {
+ }
+
+ public void Write (Rules rules)
+ {
+ }
+
+ public void Write (Violation v)
+ {
+ RuleInformation ri = RuleInformationManager.GetRuleInformation
(v.Rule);
+ writer.WriteLine ("{0}. {1}", ++index, ri.Name);
+ writer.WriteLine ();
+ writer.WriteLine ("Problem: {0}", String.Format (ri.Problem,
v.Violator));
+ writer.WriteLine ();
+ if(v.Messages != null && v.Messages.Count > 0) {
+ writer.WriteLine ("Details:");
+ foreach (object message in v.Messages) {
+ writer.WriteLine(" {0}", message);
+ }
+ writer.WriteLine ();
+ }
+ writer.WriteLine ("Solution: {0}", String.Format (ri.Solution,
v.Violator));
+ writer.WriteLine ();
+ string url = ri.Uri;
+ if (url.Length > 0) {
+ writer.WriteLine ("More info available at: {0}", url);
+ writer.WriteLine ();
+ }
+ writer.WriteLine ();
+ }
+}
Added: trunk/cecil/gendarme/console/XmlResultWriter.cs
===================================================================
--- trunk/cecil/gendarme/console/XmlResultWriter.cs 2006-09-18 00:16:01 UTC
(rev 65557)
+++ trunk/cecil/gendarme/console/XmlResultWriter.cs 2006-09-18 00:16:42 UTC
(rev 65558)
@@ -0,0 +1,126 @@
+//
+// ResultWriter
+//
+// Authors:
+// Christian Birkl <[EMAIL PROTECTED]>
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2006 Christian Birkl
+// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections;
+using System.Text;
+using System.Xml;
+using System.Xml.Serialization;
+
+using Gendarme.Framework;
+
+public class XmlResultWriter : IResultWriter {
+
+ private XmlTextWriter writer;
+
+ public XmlResultWriter (string output)
+ {
+ if ((output == null) || (output.Length == 0))
+ writer = new XmlTextWriter (Console.Out);
+ else
+ writer = new XmlTextWriter (output, Encoding.UTF8);
+ }
+
+ public void Start ()
+ {
+ writer.Formatting = Formatting.Indented;
+ writer.WriteProcessingInstruction ("xml", "version='1.0'");
+ writer.WriteStartElement ("gendarme-output");
+ writer.WriteAttributeString ("date", DateTime.UtcNow.ToString
());
+ }
+
+ public void End ()
+ {
+ writer.WriteEndElement ();
+ writer.Flush ();
+ writer.Close ();
+ writer = null;
+ }
+
+ public void Write (ICollection assemblies)
+ {
+ foreach (string assembly in assemblies) {
+ writer.WriteElementString("input", assembly);
+ }
+ }
+
+ public void Write (Rules rules)
+ {
+ writer.WriteStartElement ("rules");
+ Rules("Assembly", rules.Assembly);
+ Rules("Module", rules.Module);
+ Rules("Type", rules.Type);
+ Rules("Method", rules.Method);
+ writer.WriteEndElement ();
+ }
+
+ private void Rules (string type, RuleCollection rules)
+ {
+ foreach (IRule rule in rules) {
+ writer.WriteStartElement ("rule");
+ writer.WriteAttributeString ("Type", type);
+ writer.WriteString (rule.GetType ().FullName);
+ writer.WriteEndElement ();
+ }
+ }
+
+ public void Write (Violation v)
+ {
+ RuleInformation ri = RuleInformationManager.GetRuleInformation
(v.Rule);
+
+ writer.WriteStartElement ("violation");
+ writer.WriteAttributeString ("Assembly", v.Assembly.ToString
());
+ writer.WriteAttributeString ("Name", ri.Name);
+ writer.WriteAttributeString ("Uri", ri.Uri);
+ writer.WriteElementString ("problem", String.Format
(ri.Problem, v.Violator));
+ writer.WriteElementString ("solution", String.Format
(ri.Solution, v.Violator));
+
+ if ((v.Messages != null) && (v.Messages.Count > 0)) {
+ writer.WriteStartElement ("messages");
+ foreach (object o in v.Messages) {
+ writer.WriteStartElement ("message");
+ // FIXME: review existing rules
+ Message message = (o as Message);
+ if (message != null) {
+ if (message.Location != null)
+ writer.WriteAttributeString
("Location", message.Location.ToString());
+ writer.WriteAttributeString ("Type",
message.Type.ToString());
+ writer.WriteString (message.Text);
+ } else {
+ writer.WriteString (o.ToString ());
+ }
+ writer.WriteEndElement ();
+ }
+ writer.WriteEndElement ();
+ }
+
+ writer.WriteEndElement ();
+ }
+}
Modified: trunk/cecil/gendarme/console/console.mdp
===================================================================
--- trunk/cecil/gendarme/console/console.mdp 2006-09-18 00:16:01 UTC (rev
65557)
+++ trunk/cecil/gendarme/console/console.mdp 2006-09-18 00:16:42 UTC (rev
65558)
@@ -16,6 +16,11 @@
<DeployTargets />
<Contents>
<File name="./ConsoleRunner.cs" subtype="Code" buildaction="Compile" />
+ <File name="./IResultWriter.cs" subtype="Code" buildaction="Compile" />
+ <File name="./TextResultWriter.cs" subtype="Code" buildaction="Compile" />
+ <File name="./XmlResultWriter.cs" subtype="Code" buildaction="Compile" />
+ <File name="./gendarme.xsl" subtype="Code" buildaction="EmbedAsResource" />
+ <File name="./HtmlResultWriter.cs" subtype="Code" buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
Added: trunk/cecil/gendarme/console/gendarme.xsl
===================================================================
--- trunk/cecil/gendarme/console/gendarme.xsl 2006-09-18 00:16:01 UTC (rev
65557)
+++ trunk/cecil/gendarme/console/gendarme.xsl 2006-09-18 00:16:42 UTC (rev
65558)
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="iso-8859-1" ?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ <xsl:output method="html" encoding="iso-8859-1" />
+ <xsl:template name="print-rules">
+ <xsl:param name="type" />
+ <p>
+ <b><xsl:value-of select="$type" /></b>:
+ <xsl:choose>
+ <xsl:when test="count(rules/[EMAIL
PROTECTED] = $type]) = 0">
+ <ul>
+ <li>None</li>
+ </ul>
+ </xsl:when>
+ <xsl:otherwise>
+ <ul>
+ <xsl:for-each
select="rules/[EMAIL PROTECTED] = $type]">
+
<li><xsl:value-of select="text()" /></li>
+ </xsl:for-each>
+ </ul>
+ </xsl:otherwise>
+ </xsl:choose>
+ </p>
+ </xsl:template>
+ <xsl:template match="/">
+ <xsl:for-each select="gendarme-output">
+ <html>
+ <head>
+ <title>Gendarme Report</title>
+ </head>
+ <style type="text/css">
+ h1, h2, h3 {
+ font-family: Verdana;
+ color: #68892F;
+ }
+ h2 {
+ font-size: 14pt;
+ }
+
+ p, li, b {
+ font-family: Verdana;
+ font-size: 11pt;
+ }
+ p.problem, p.solution {
+ background-color: #F6F6F6;
+ border: 1px solid #DDDDDD;
+ padding: 10px;
+ }
+ div.toc {
+ background-color: #F6F6F6;
+ border: 1px solid #DDDDDD;
+ padding: 10px;
+ float: right;
+ width: 300px;
+ }
+ a:link, a:active, a:hover, a:visited {
+ color: #9F75AD;
+ font-weight: bold;
+ text-decoration: none;
+ }
+ </style>
+ <body>
+
+ <h1>Gendarme Report</h1>
+
+ <div class="toc">
+ <div align="center">
+ <b style="font-size:
10pt;">Table of contents</b>
+ </div>
+ <p style="font-size: 10pt;">
+ <a
href="#s1">1  Summary</a><br />
+ <a
href="#s1_1">  1.1  List of assemblies searched</a><br />
+ <a
href="#s1_2">  1.2  List of rules used</a><br />
+ <a
href="#s2">2  Reported defects</a><br />
+ </p>
+ </div>
+ <h1><a name="s1">Summary</a></h1>
+
+ <p>
+ <h2>List of assemblies
searched</h2>
+ <ul>
+ <xsl:for-each
select="input">
+ <xsl:variable
name="assembly"><xsl:value-of select="text()" /></xsl:variable>
+
+
<li><xsl:value-of select="text()" />: <xsl:value-of select="count(//[EMAIL
PROTECTED] = $assembly]/messages/message)" /> defects</li>
+ </xsl:for-each>
+ </ul>
+ </p>
+
+ <p>
+ <h2>List of rules used</h2>
+
+ <xsl:call-template
name="print-rules">
+ <xsl:with-param
name="type">Assembly</xsl:with-param>
+ </xsl:call-template>
+
+ <xsl:call-template
name="print-rules">
+ <xsl:with-param
name="type">Module</xsl:with-param>
+ </xsl:call-template>
+
+ <xsl:call-template
name="print-rules">
+ <xsl:with-param
name="type">Type</xsl:with-param>
+ </xsl:call-template>
+
+ <xsl:call-template
name="print-rules">
+ <xsl:with-param
name="type">Method</xsl:with-param>
+ </xsl:call-template>
+
+ </p>
+
+ <h1><a name="s2">Reported
Defects</a></h1>
+
+ <p>
+
+ <xsl:for-each
select="violation/messages/message">
+ <h3><xsl:value-of
select="position()" /> <xsl:value-of select="../../@Name" /> hit in
<xsl:value-of select="@Location" /></h3>
+
+ <b>Problem:</b>
+ <p class="problem">
+ <xsl:value-of
select="../../problem" />
+ </p>
+
+ <b>Solution:</b>
+ <p class="solution">
+ <xsl:value-of
select="../../solution" />
+ </p>
+ </xsl:for-each>
+
+ </p>
+ </body>
+ </html>
+ </xsl:for-each>
+ </xsl:template>
+</xsl:stylesheet>
\ No newline at end of file
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches