* Mono.Documentation/monodocs2html.cs: By request of Edd Dumbill, add
authorJonathan Pryor <jpryor@novell.com>
Sat, 19 Sep 2009 17:34:16 +0000 (17:34 -0000)
committerJonathan Pryor <jpryor@novell.com>
Sat, 19 Sep 2009 17:34:16 +0000 (17:34 -0000)
  --with-version=VERSION option.  This will generate HTML
  documentation for ONLY those types/members which exist within
  VERSION.  This makes it easy to generate HTML that will show e.g.
  only MonoTouch docs (and not the full class library docs).
* Makefile: Add test for 'mdoc export-html --with-version=VERSION'.
  Somewhat brain-dead, as it only checks for added types (and not
  added members), but better than nothing...

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

mcs/tools/mdoc/ChangeLog
mcs/tools/mdoc/Makefile
mcs/tools/mdoc/Mono.Documentation/monodocs2html.cs

index fa833af790d0fa67b705d2ec3ed3514d0cfdd5f9..20848a264292763395f99f1b913e1b65ed81e7fb 100644 (file)
@@ -1,3 +1,14 @@
+2009-09-19  Jonathan Pryor <jpryor@novell.com>
+
+       * Mono.Documentation/monodocs2html.cs: By request of Edd Dumbill, add
+         --with-version=VERSION option.  This will generate HTML
+         documentation for ONLY those types/members which exist within
+         VERSION.  This makes it easy to generate HTML that will show e.g.
+         only MonoTouch docs (and not the full class library docs).
+       * Makefile: Add test for 'mdoc export-html --with-version=VERSION'.
+         Somewhat brain-dead, as it only checks for added types (and not
+         added members), but better than nothing...
+
 2009-09-09  Jonathan Pryor <jpryor@novell.com>
 
        * Mono.Documentation/monodocs2html.cs: Fix behavior when multiple
index 576afc644d0479456e90d45a50c1b5e3c9cbf797..e0ebe60c11289c253e679e30a46e33b7b127ec8b 100644 (file)
@@ -155,6 +155,16 @@ check-mdoc-export-html: check-monodocer mdoc.exe
                Test/en.expected.importslashdoc
        diff --exclude=.svn -rup Test/html.expected Test/html.actual
 
+check-mdoc-export-html-with-version: mdoc.exe
+       rm -Rf Test/html.actual.v0 Test/html.actual.since-with-v0 .v0.txt .v2.txt
+       $(MONO) mdoc.exe export-html -o Test/html.actual.v0 \
+               Test/en.expected
+       $(MONO) mdoc.exe export-html -o Test/html.actual.since-with-v0 \
+               Test/en.expected.since -with-version 0.0.0.0
+       (cd Test/html.actual.v0            && find . -type f) | sort > .v0.txt
+       (cd Test/html.actual.since-with-v0 && find . -type f) | sort > .v2.txt
+       diff -rup .v0.txt .v2.txt   # assert no types added
+
 check-md-html-dir: mdoc.exe
        rm -Rf Test/html.actual
        $(MONO) mdoc.exe export-html -dest:Test/html.actual $(DIR) 
@@ -201,6 +211,7 @@ check-doc-tools: check-monodocer-since \
        check-monodocer-importslashdoc \
        check-monodocer \
        check-mdoc-export-html \
+       check-mdoc-export-html-with-version \
        check-mdoc-export-msxdoc \
        check-mdoc-validate
 
index 259b670f3e7e5da8d3109d748cf29383d96b922c..3838f80c218f18ab8a7aa77ffa909ac766941427 100644 (file)
@@ -25,6 +25,7 @@ class MDocToHtmlConverterOptions {
        public string template;
        public bool   dumptemplate;
        public bool   forceUpdate;
+       public List<string> versions = new List<string> ();
 }
 
 class MDocToHtmlConverter : MDocCommand {
@@ -53,6 +54,12 @@ class MDocToHtmlConverter : MDocCommand {
                                        "files.  If not specified, uses the template generated by " + 
                                        "--default-template.",
                                v => opts.template = v },
+                       { "with-version=",
+                               "The assembly VERSION to generate documentation for.  This allows " + 
+                                       "display of a subset of types/members that correspond to the given " +
+                                       "assembly version.  May be specified multiple times.  " + 
+                                       "If not specified, all versions are displayed.",
+                               v => opts.versions.Add (v) }
                };
                List<string> extra = Parse (p, args, "export-html", 
                                "[OPTIONS]+ DIRECTORIES",
@@ -158,6 +165,7 @@ class MDocToHtmlConverter : MDocCommand {
 
                                XmlDocument typexml = new XmlDocument();
                                typexml.Load(typefile);
+                               PreserveMembersInVersions (typexml);
                                if (extensions != null) {
                                        DocLoader loader = CreateDocLoader (overview);
                                        XmlDocUtils.AddExtensionMethods (typexml, extensions, loader);
@@ -364,13 +372,37 @@ class MDocToHtmlConverter : MDocCommand {
                                dest.AppendChild (nsd);
                        }
                        foreach (XmlNode t in ns.ChildNodes) {
+                               if (!TypeInVersions (sourceDirectory, n, t))
+                                       continue;
                                var c = dest.OwnerDocument.ImportNode (t, true);
                                AddAttribute (c, "SourceDirectory", sourceDirectory);
                                nsd.AppendChild (c);
                        }
+                       if (nsd.ChildNodes.Count == 0)
+                               dest.RemoveChild (nsd);
                }
        }
 
+       static bool TypeInVersions (string sourceDirectory, string ns, XmlNode type)
+       {
+               if (opts.versions.Count == 0)
+                       return true;
+               var file = Path.Combine (Path.Combine (sourceDirectory, ns), type.Attributes ["Name"].Value + ".xml");
+               if (!File.Exists (file))
+                       return false;
+               XPathDocument doc;
+               using (var s = File.OpenText (file))
+                       doc = new XPathDocument (s);
+               return MemberInVersions (doc.CreateNavigator ().SelectSingleNode ("/Type"));
+       }
+
+       static bool MemberInVersions (XPathNavigator nav)
+       {
+               return nav.Select ("AssemblyInfo/AssemblyVersion")
+                       .Cast<object> ()
+                       .Any (v => opts.versions.Contains (v.ToString ()));
+       }
+
        static void AddAttribute (XmlNode self, string name, string value)
        {
                var a = self.OwnerDocument.CreateAttribute (name);
@@ -383,6 +415,20 @@ class MDocToHtmlConverter : MDocCommand {
                return !opts.forceUpdate && File.Exists (dest) &&
                        File.GetLastWriteTime (source) < File.GetLastWriteTime (dest);
        }
+
+       private static void PreserveMembersInVersions (XmlDocument doc)
+       {
+               if (opts.versions.Count == 0)
+                       return;
+               var remove = new List<XmlNode>();
+               foreach (XmlNode m in doc.SelectNodes ("/Type/Members/Member")) {
+                       if (!MemberInVersions (m.CreateNavigator ()))
+                               remove.Add (m);
+               }
+               XmlNode members = doc.SelectSingleNode ("/Type/Members");
+               foreach (var m in remove)
+                       members.RemoveChild (m);
+       }
 }
 
 }