Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/api-doc-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMike Norman <mike.norman@xamarin.com>2017-07-06 21:51:41 +0300
committerJoel Martinez <joelmartinez@gmail.com>2017-07-11 18:23:38 +0300
commit42a43c6fc82a5d7d88fb667443ff1775da0ed483 (patch)
treea9754965ed5d3cfc85bb9e2b00352c71daeec3d0 /tools
parent701420f5c1521f51098fe181f7dd92fc2cb56dc9 (diff)
Refactored DocStat, plus added stub for comparereport command
Diffstat (limited to 'tools')
-rw-r--r--tools/DocStat/DocStat/ParallelXmlHelper.cs53
-rw-r--r--tools/DocStat/DocStat/comparefix.cs92
-rw-r--r--tools/DocStat/DocStat/comparereport.cs51
3 files changed, 126 insertions, 70 deletions
diff --git a/tools/DocStat/DocStat/ParallelXmlHelper.cs b/tools/DocStat/DocStat/ParallelXmlHelper.cs
index 69f05ea0..bac32386 100644
--- a/tools/DocStat/DocStat/ParallelXmlHelper.cs
+++ b/tools/DocStat/DocStat/ParallelXmlHelper.cs
@@ -99,38 +99,39 @@ namespace DocStat
};
}
- public static XElement ParallelElement(XElement sourceElement,
- string sourcePath,
- string sourceRoot,
- string refRoot,
- HashSet<string> refPaths)
+ public static string GetParallelFilePathFor(string pathToTypeToFix,
+ string rootOfReferenceFiles,
+ string rootOfFilesToFix,
+ Func<string, string> referenceRootTransform = null,
+ Func<string, string> referencePathTransform = null)
{
- string parallelPath = GetParallelFilePathFor(sourcePath, refRoot, sourceRoot);
+
+ string fullFixPath = Path.GetFullPath(pathToTypeToFix);
- // bail early if we can
+ string fullFixRoot = Path.GetFullPath(rootOfFilesToFix);
- if (!File.Exists(parallelPath) || !refPaths.Contains(parallelPath))
- return null;
+ rootOfReferenceFiles =
+ null == referenceRootTransform ? rootOfReferenceFiles : referenceRootTransform(rootOfReferenceFiles);
+ string fullRefRoot = Path.GetFullPath(rootOfReferenceFiles);
- FileAttributes attr = File.GetAttributes(parallelPath);
- if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
- return null;
+ string fullReferencePath = fullFixPath.Replace(fullFixRoot, fullRefRoot);
- XDocument refToSearch = XDocument.Load(parallelPath);
- Console.WriteLine("Found parallel document");
- var toReturn = GetSelectorFor(sourceElement).Invoke(refToSearch);
- Console.WriteLine("Got the parallel element");
- return toReturn;
+ fullReferencePath =
+ null == referencePathTransform ? fullReferencePath : referencePathTransform(fullReferencePath);
+ return fullReferencePath;
}
- public static string GetParallelFilePathFor(string pathToTypeToFix,
- string rootOfFilesToUse,
- string rootOfFilesToFix)
- {
- string fullFixPath = Path.GetFullPath(pathToTypeToFix);
- string fullFixRoot = Path.GetFullPath(rootOfFilesToFix);
- string fullRefRoot = Path.GetFullPath(rootOfFilesToUse);
- return fullFixPath.Replace(fullFixRoot, fullRefRoot);
- }
+ public static XDocument GetParallelXDocFor(string parallelFilePath,
+ HashSet<string> refPaths = null)
+ {
+
+ if (!File.Exists(parallelFilePath))
+ return null;
+
+ if ((null != refPaths) && !refPaths.Contains(parallelFilePath))
+ return null;
+
+ return XDocument.Load(parallelFilePath);
+ }
}
}
diff --git a/tools/DocStat/DocStat/comparefix.cs b/tools/DocStat/DocStat/comparefix.cs
index 5bfd8c58..3520a670 100644
--- a/tools/DocStat/DocStat/comparefix.cs
+++ b/tools/DocStat/DocStat/comparefix.cs
@@ -22,7 +22,7 @@ namespace DocStat
ref processlist,
ref pattern);
// must have
- string filesToUseDir = "";
+ string filesToUseAsRefDir = "";
// should have
bool doSummaries = true;
bool doParameters = true;
@@ -35,7 +35,7 @@ namespace DocStat
var opts = new OptionSet {
{"f|fix=", (f) => filesToFixDir = f},
- {"u|using=", (u) => filesToUseDir = u},
+ {"u|using=", (u) => filesToUseAsRefDir = u},
{"s|summaries", (s) => doSummaries = s != null},
{"a|params", (p) => doParameters = p != null },
{"r|retvals", (r) => doReturns = r != null },
@@ -47,80 +47,84 @@ namespace DocStat
extras = opts.Parse(extras);
CommandUtils.ThrowOnFiniteExtras(extras);
- if (String.IsNullOrEmpty(filesToUseDir))
+ if (String.IsNullOrEmpty(filesToUseAsRefDir))
throw new ArgumentException("You must supply a parallel directory from which to source new content with '[u|using]'=.");
- IEnumerable<string> toFix = CommandUtils.GetFileList(processlist, omitlist, filesToFixDir, pattern);
- HashSet<string> toUse = new HashSet<string>(CommandUtils.GetFileList("", "", filesToUseDir, ""));
+ IEnumerable<string> filesToFix = CommandUtils.GetFileList(processlist, omitlist, filesToFixDir, pattern);
+ HashSet<string> filesToUseAsReference = new HashSet<string>(CommandUtils.GetFileList("", "", filesToUseAsRefDir, ""));
- toFix = toFix.Where((f) => toUse.Contains(ParallelXmlHelper.GetParallelFilePathFor(f, filesToUseDir, filesToFixDir)));
+ filesToFix =
+ filesToFix.Where((f) =>
+ filesToUseAsReference.Contains(ParallelXmlHelper.GetParallelFilePathFor(f,
+ filesToUseAsRefDir,
+ filesToFixDir)));
- // closure for lexical brevity in loop below
- Action<XElement, string> Fix = (XElement e, string f) =>
- {
- Console.WriteLine(e.Name);
- ParallelXmlHelper.Fix(e, ParallelXmlHelper.ParallelElement(e,
- f,
- filesToFixDir,
- filesToUseDir,
- toUse));
- };
- foreach (var f in toFix)
+ foreach (var f in filesToFix)
{
- bool changed = false;
- XDocument fixie = XDocument.Load(f);
+ XDocument currentRefXDoc = ParallelXmlHelper.GetParallelXDocFor(
+ ParallelXmlHelper.GetParallelFilePathFor(f, filesToUseAsRefDir, filesToFixDir),
+ filesToUseAsReference
+ );
+
+ if (null == currentRefXDoc)
+ continue;
+
+ Action<XElement> fix =
+ (XElement e) => ParallelXmlHelper.Fix(e, ParallelXmlHelper.GetSelectorFor(e).Invoke(currentRefXDoc));
+
+ bool changed = false;
+ XDocument currentXDocToFix = XDocument.Load(f);
EventHandler<XObjectChangeEventArgs> SetTrueIfChanged = null;
SetTrueIfChanged =
- new EventHandler<XObjectChangeEventArgs>((sender, e) => { fixie.Changed -= SetTrueIfChanged; changed = true; });
- fixie.Changed += SetTrueIfChanged;
+ new EventHandler<XObjectChangeEventArgs>((sender, e) => { currentXDocToFix.Changed -= SetTrueIfChanged; changed = true; });
+ currentXDocToFix.Changed += SetTrueIfChanged;
// (1) Fix ype-level summary and remarks:
- XElement typeSummaryToFix = fixie.Element("Type").Element("Docs").Element("summary");
- Fix(typeSummaryToFix, f);
+ XElement typeSummaryToFix = currentXDocToFix.Element("Type").Element("Docs").Element("summary");
+ fix(typeSummaryToFix);
- XElement typeRemarksToFix = fixie.Element("Type").Element("Docs").Element("remarks");
- Fix(typeRemarksToFix, f);
+ XElement typeRemarksToFix = currentXDocToFix.Element("Type").Element("Docs").Element("remarks");
+ fix(typeRemarksToFix);
- var members = fixie.Element("Type").Element("Members");
+ var members = currentXDocToFix.Element("Type").Element("Members");
if (null != members)
{
+
foreach (XElement m in members.Elements().
- Where((XElement e) => ParallelXmlHelper.ParallelElement(e,
- f,
- filesToFixDir,
- filesToUseDir,
- toUse) != null))
+ Where((XElement e) => null != ParallelXmlHelper.GetSelectorFor(e).Invoke(currentRefXDoc)))
{
// (2) Fix summary, remarks, return values, parameters, and typeparams
- XElement summary = m.Element("Docs").Element("summary");
- Fix(summary, f);
+ XElement docsElement = m.Element("Docs");
+
+ XElement summary = docsElement.Element("summary");
+ fix(summary);
- XElement remarks = m.Element("Docs").Element("remarks");
+ XElement remarks = docsElement.Element("remarks");
if (null != remarks)
- Fix(remarks, f);
+ fix(remarks);
- XElement returns = m.Element("Docs").Element("returns");
+ XElement returns = docsElement.Element("returns");
if (null != returns)
- Fix(returns, f);
+ fix(returns);
- if (m.Element("Docs").Elements("param").Any())
+ if (docsElement.Elements("param").Any())
{
- IEnumerable<XElement> _params = m.Element("Docs").Elements("param");
+ IEnumerable<XElement> _params = docsElement.Elements("param");
foreach (XElement p in _params)
{
- Fix(p, f);
+ fix(p);
}
}
- if (m.Element("Docs").Elements("typeparam").Any())
+ if (docsElement.Elements("typeparam").Any())
{
- IEnumerable<XElement> typeparams = m.Element("Docs").Elements("typeparam");
+ IEnumerable<XElement> typeparams = docsElement.Elements("typeparam");
foreach (XElement p in typeparams)
{
- Fix(p, f);
+ fix(p);
}
}
}
@@ -128,7 +132,7 @@ namespace DocStat
if (changed)
{
- CommandUtils.WriteXDocument(fixie, f);
+ CommandUtils.WriteXDocument(currentXDocToFix, f);
}
}
diff --git a/tools/DocStat/DocStat/comparereport.cs b/tools/DocStat/DocStat/comparereport.cs
new file mode 100644
index 00000000..768a8de8
--- /dev/null
+++ b/tools/DocStat/DocStat/comparereport.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Xml.Linq;
+using Mono.Options;
+
+namespace DocStat
+{
+ public class CompareReportCommand : ApiCommand
+ {
+
+ public override void Run(IEnumerable<string> args)
+ {
+ throw new NotImplementedException();
+
+ string updatedDir = "";
+ string omitlist = "";
+ string processlist = "";
+ string pattern = "";
+
+ List<string> extras = CommandUtils.ProcessFileArgs(args,
+ ref updatedDir,
+ ref omitlist,
+ ref processlist,
+ ref pattern);
+
+ string oldFiles = "";
+ bool typeOnly = false;
+
+
+ if (String.IsNullOrEmpty(oldFiles))
+ throw new ArgumentException("You must supply a parallel directory from which to source new content with '[u|using]'=.");
+
+
+ IEnumerable<string> updated = CommandUtils.GetFileList(processlist, omitlist, updatedDir, pattern);
+ HashSet<string> filesToUseAsReference = new HashSet<string>(CommandUtils.GetFileList("", "", oldFiles, ""));
+
+ updated =
+ updated.Where((f) =>
+ filesToUseAsReference.Contains(ParallelXmlHelper.GetParallelFilePathFor(f,
+ oldFiles,
+ updatedDir)));
+
+
+
+ // For each member in the updated files, report if the old one isn't present
+
+ }
+ }
+}