* Mono.Documentation/validate.cs: Remove warnings
authorJonathan Pryor <jpryor@novell.com>
Mon, 27 Oct 2008 14:10:01 +0000 (14:10 -0000)
committerJonathan Pryor <jpryor@novell.com>
Mon, 27 Oct 2008 14:10:01 +0000 (14:10 -0000)
* Test/validate.check.monodocer, Test/validate.check.monodocer.since:
  Don't generate output if no errors are found.
* Test/validate.check.monodocer.importslashdoc: Prefix error messages
  with "mdoc:", as per Unix convention.

svn path=/trunk/mcs/; revision=117158

mcs/tools/mdoc/ChangeLog
mcs/tools/mdoc/Mono.Documentation/validate.cs
mcs/tools/mdoc/Test/validate.check.monodocer
mcs/tools/mdoc/Test/validate.check.monodocer.importslashdoc
mcs/tools/mdoc/Test/validate.check.monodocer.since

index 0bd72cbf33ed1033087e7af5213733c78675f803..ce1803e8bb6bd34dd9cab135c8ad653aab810032 100644 (file)
@@ -1,3 +1,11 @@
+2008-10-27  Jonathan Pryor <jpryor@novell.com>
+
+       * Mono.Documentation/validate.cs: Remove warnings
+       * Test/validate.check.monodocer, Test/validate.check.monodocer.since:
+         Don't generate output if no errors are found.
+       * Test/validate.check.monodocer.importslashdoc: Prefix error messages
+         with "mdoc:", as per Unix convention.
+
 2008-10-24  Jonathan Pryor <jpryor@novell.com>
 
        * Makefile: Fixup mdoc.exe dependencies so that it's rebuilt if the
index b2ec6b3cd624395cdd5c2705875877cd4352ca7b..afaba40ff2226f1fb09b407bc35d2730d336b96a 100644 (file)
@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.IO;
 using System.Reflection;
 using System.Xml;
@@ -11,10 +12,8 @@ namespace Mono.Documentation
 {
        public class MDocValidator : MDocCommand
        {
-               static XmlValidatingReader reader;
-               static XmlSchema schema;
-               static long errors = 0;
-               static bool IsValid = true;
+               XmlReaderSettings settings;
+               long errors = 0;
 
                public override void Run (IEnumerable<string> args)
                {
@@ -22,7 +21,6 @@ namespace Mono.Documentation
                                "ecma",
                        };
                        string format = "ecma";
-                       bool showHelp = false;
                        var p = new OptionSet () {
                                { "f|format=",
                                        "The documentation {0:FORMAT} used within PATHS.  " + 
@@ -41,7 +39,7 @@ namespace Mono.Documentation
                        Run (format, files);
                }
        
-               public static void Run (string format, IEnumerable<string> files)
+               public void Run (string format, IEnumerable<string> files)
                {
                        Stream s = null;
 
@@ -57,8 +55,11 @@ namespace Mono.Documentation
                        if (s == null)
                                throw new NotSupportedException (string.Format ("The schema for `{0}' was not found.", format));
 
-                       schema = XmlSchema.Read (s, null);
-                       schema.Compile (null);
+                       settings = new XmlReaderSettings ();
+                       settings.Schemas.Add (XmlSchema.Read (s, null));
+                       settings.Schemas.Compile ();
+                       settings.ValidationType = ValidationType.Schema;
+                       settings.ValidationEventHandler += OnValidationEvent;
 
                        // skip args[0] because it is the provider name
                        foreach (string arg in files) {
@@ -71,28 +72,25 @@ namespace Mono.Documentation
                                }
                        }
 
-                       Console.WriteLine ("Total validation errors: {0}", errors);
+                       Message (errors == 0 ? TraceLevel.Info : TraceLevel.Error, 
+                                       "Total validation errors: {0}", errors);
                }
 
-               static void ValidateFile (string file)
+               void ValidateFile (string file)
                {
-                       IsValid = true;
                        try {
-                               reader = new XmlValidatingReader (new XmlTextReader (file));
-                               reader.ValidationType = ValidationType.Schema;
-                               reader.Schemas.Add (schema);
-                               reader.ValidationEventHandler += new ValidationEventHandler (OnValidationEvent);
-                               while (reader.Read ()) {
-                                       // do nothing
+                               using (var reader = XmlReader.Create (new XmlTextReader (file), settings)) {
+                                       while (reader.Read ()) {
+                                               // do nothing
+                                       }
                                }
-                               reader.Close ();
                        }
                        catch (Exception e) {
-                               Console.WriteLine ("mdvalidator: error: " + e.ToString ());
+                               Message (TraceLevel.Error, "mdoc: {0}", e.ToString ());
                        }
                }
 
-               static void RecurseDirectory (string dir)
+               void RecurseDirectory (string dir)
                {
                        string[] files = Directory.GetFiles (dir, "*.xml");
                        foreach (string f in files)
@@ -106,12 +104,10 @@ namespace Mono.Documentation
                                RecurseDirectory (d);
                }
 
-               static void OnValidationEvent (object sender, ValidationEventArgs a)
+               void OnValidationEvent (object sender, ValidationEventArgs a)
                {
-                       if (IsValid)
-                               IsValid = false;
                        errors ++;
-                       Console.WriteLine (a.Message);
+                       Message (TraceLevel.Error, "mdoc: {0}", a.Message);
                }
 
                static bool IsMonodocFile (string file)
index 2f36683dcfc32b50e72d06276a4a5d4e0e854093..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1 +0,0 @@
-Total validation errors: 0
index 7396fde6c53b4c23c88036f01b11b2907c2e7498..6b360994ed8d538bfb38692bb0808f7f462ca1ae 100644 (file)
@@ -1,4 +1,4 @@
-XmlSchema error: Invalid start element: :extra XML URI: Test/en.expected.importslashdoc/Mono.DocTest/Widget.xml . Line 20, Position 6.
-XmlSchema error: Element declaration for extra is missing. XML URI: Test/en.expected.importslashdoc/Mono.DocTest/Widget.xml . Line 20, Position 6.
-XmlSchema error: Invalid end element: Docs XML URI: Test/en.expected.importslashdoc/Mono.DocTest/Widget.xml . Line 21, Position 5.
+mdoc: XmlSchema error: Invalid start element: :extra XML URI: Test/en.expected.importslashdoc/Mono.DocTest/Widget.xml . Line 20, Position 6.
+mdoc: XmlSchema error: Element declaration for extra is missing. XML URI: Test/en.expected.importslashdoc/Mono.DocTest/Widget.xml . Line 20, Position 6.
+mdoc: XmlSchema error: Invalid end element. There are still required content items. XML URI: Test/en.expected.importslashdoc/Mono.DocTest/Widget.xml . Line 21, Position 5.
 Total validation errors: 3
index 2f36683dcfc32b50e72d06276a4a5d4e0e854093..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1 +0,0 @@
-Total validation errors: 0