From 82dc985dcd32e34463676bb1f5a74648a7ecc8f7 Mon Sep 17 00:00:00 2001 From: Mpdreamz Date: Mon, 7 Nov 2016 17:24:53 +0100 Subject: [PATCH 1/2] reimplemented --- build/scripts/InheritDoc.fsx | 103 +++++++++++++++--- build/scripts/Paths.fsx | 11 +- build/scripts/Targets.fsx | 8 ++ .../FullText/CommonTerms/CommonTermsQuery.cs | 4 +- 4 files changed, 105 insertions(+), 21 deletions(-) diff --git a/build/scripts/InheritDoc.fsx b/build/scripts/InheritDoc.fsx index 1b5cda09f3b..07f833614da 100644 --- a/build/scripts/InheritDoc.fsx +++ b/build/scripts/InheritDoc.fsx @@ -2,27 +2,94 @@ #r @"FakeLib.dll" #r "System.Xml.Linq.dll" +#load @"Paths.fsx" + +namespace XmlDocPatcher + open System.Linq open System.Text.RegularExpressions open System.Xml open System.Xml.Linq open System.Xml.XPath -let PatchXmlDoc = fun (file: string) -> - let xml = XDocument.Load file - let nodes = xml.XPathSelectElements("//inheritdoc") - |> Seq.map (fun n -> - let methodName = n.Parent.Attribute(XName.Get("name")).Value - let interfaceName = Regex.Replace(methodName, @"\.([^.]+\.[^.]+\()", ".I$1") - let interfaceNode = xml.XPathSelectElement (sprintf "//member[@name='%s']" interfaceName) - (n.Parent, interfaceNode) - ) - |> Seq.filter (fun (implementationElement, interfaceElement) -> - interfaceElement <> null && implementationElement.HasElements && interfaceElement.HasElements - ) - let nodesReplace = nodes - |> Seq.iter (fun (implementationElement, interfaceElement) -> - implementationElement.Add (interfaceElement.Descendants().ToList()) - ) - - xml.Save file \ No newline at end of file +open Paths +open Projects +open Fake + + +module InheritDoc = + + let private apiName n = Regex.Replace(n, @"^\w\:(.+?)(?:\(.+$|$)", "$1") + let private relatedInterface n = Regex.Replace(n, @"\.([^.]+\.[^.]+)$", ".I$1") + let private relatedInterfaceAsync n = (relatedInterface n).Replace("Async", "") + let private relatedInterfaceDescriptor n = Regex.Replace(n, @"\.([^.]+)Descriptor\.([^.]+)$", ".I$1.$2") + let private relatedInterfaceDescriptorRequest n = Regex.Replace(n, @"\.([^.]+)Descriptor\.([^.]+)$", ".I$1Request.$2") + let private relatedInterfaceDescriptorGeneric n = Regex.Replace(n, @"\.([^.]+)Descriptor[^.]+.([^.]+)$", ".I$1.$2") + let private manualMapping (n : string) = + //this sucks but untill roslyn gets coderewriting API's this is the best we got without making it + //a bigger thing than it already is + match n with + | n when n.Contains("PutMapping") -> n.Replace("PutMapping", "TypeMapping") + | _ -> n + let private relatedApiLookups = [ + relatedInterface; + relatedInterfaceAsync; + relatedInterfaceDescriptor; + relatedInterfaceDescriptorRequest; + relatedInterfaceDescriptorGeneric; + manualMapping + ]; + + let private documentedApis = fun (file : string) -> + use reader = XmlReader.Create file + seq { + while reader.ReadToFollowing("member") do + let name = apiName(reader.GetAttribute("name")) + let innerXml = reader.ReadInnerXml().Trim(); + if (isNotNullOrEmpty innerXml && not (innerXml.Contains("" + innerXml + "") + yield (name, xdoc) + } |> Map.ofSeq + + let private patchInheritDoc = fun file -> + traceFAKE "Rewriting xmldoc: %s" file + + let mapOfDocumentedApis = documentedApis file + + let findDocumentation (apiElement:string) = + relatedApiLookups + |> Seq.map (fun f -> f apiElement) + |> (Seq.map <| mapOfDocumentedApis.TryFind) + |> Seq.choose id + |> Seq.tryHead + + let xml = XDocument.Load file + + xml.XPathSelectElements("//inheritdoc") + |> Seq.iter (fun inheritDocElement -> + let parent =inheritDocElement.Parent + let name = apiName (parent.Attribute(XName.Get "name").Value) + let documentation = findDocumentation name + + match documentation with + | Some d -> + let elements = d.Element(XName.Get("x")).Elements().ToList(); + inheritDocElement.AddBeforeSelf(elements) + | _ -> + //unignore the following to find undocumented/badly inherited methods + //tracefn "not inherited: %s" apiElement + ignore() + ) + + use writer = new XmlTextWriter(file,null) + writer.Formatting <- Formatting.Indented; + xml.Save(writer); + + let patchInheritDocs = fun () -> + AllPublishableProjectsWithSupportedFrameworks + |> Seq.map (fun p -> + let folder = Paths.ProjectOutputFolder p.project p.framework + folder @@ p.project.Name + ".xml" + ) + |> Seq.filter fileExists + |> Seq.iter patchInheritDoc diff --git a/build/scripts/Paths.fsx b/build/scripts/Paths.fsx index 6ea5c942032..8957f39bea5 100644 --- a/build/scripts/Paths.fsx +++ b/build/scripts/Paths.fsx @@ -29,6 +29,8 @@ module Projects = type PrivateProject = | Tests + + type DotNetProject = | Project of Project @@ -58,6 +60,13 @@ module Projects = DotNetProject.All |> Seq.map(fun p -> p.Name) |> Seq.tryFind(fun p -> p.ToLowerInvariant() = name.ToLowerInvariant()) + + type DotNetFrameworkProject = { framework: DotNetFramework; project: DotNetProject } + let AllPublishableProjectsWithSupportedFrameworks = seq { + for framework in DotNetFramework.All do + for project in DotNetProject.AllPublishable do + yield { framework = framework; project= project} + } module Paths = @@ -71,7 +80,7 @@ module Paths = let ProjectOutputFolder (project:DotNetProject) (framework:DotNetFramework) = sprintf "%s/%s/%s" BuildOutput framework.Identifier.MSBuild project.Name - + let Tool tool = sprintf "packages/build/%s" tool let CheckedInToolsFolder = "build/Tools" let KeysFolder = sprintf "%s/keys" BuildFolder diff --git a/build/scripts/Targets.fsx b/build/scripts/Targets.fsx index 9f9e446e289..59c7e1c1687 100644 --- a/build/scripts/Targets.fsx +++ b/build/scripts/Targets.fsx @@ -6,6 +6,7 @@ #load @"Documentation.fsx" #load @"Releasing.fsx" #load @"Profiling.fsx" +#load @"InheritDoc.fsx" open System @@ -17,6 +18,7 @@ open Signing open Versioning open Releasing open Profiling +open XmlDocPatcher // Default target Target "Build" <| fun _ -> traceHeader "STARTING BUILD" @@ -27,6 +29,8 @@ Target "BuildApp" <| fun _ -> Build.Compile() Target "Test" <| fun _ -> Tests.RunUnitTests() +Target "InheritDoc" <| fun _ -> InheritDoc.patchInheritDocs() + Target "TestForever" <| fun _ -> Tests.RunUnitTestsForever() Target "QuickTest" <| fun _ -> Tests.RunUnitTests() @@ -65,6 +69,10 @@ Target "Canary" <| fun _ -> ==> "BuildApp" ==> "TestForever" +"Clean" + ==> "BuildApp" + ==> "InheritDoc" + "Clean" ==> "BuildApp" ==> "Profile" diff --git a/src/Nest/QueryDsl/FullText/CommonTerms/CommonTermsQuery.cs b/src/Nest/QueryDsl/FullText/CommonTerms/CommonTermsQuery.cs index cba5a8fa86b..a9c102e1fad 100644 --- a/src/Nest/QueryDsl/FullText/CommonTerms/CommonTermsQuery.cs +++ b/src/Nest/QueryDsl/FullText/CommonTerms/CommonTermsQuery.cs @@ -46,9 +46,9 @@ public class CommonTermsQuery : FieldNameQueryBase, ICommonTermsQuery internal static bool IsConditionless(ICommonTermsQuery q) => q.Field.IsConditionless() || q.Query.IsNullOrEmpty(); } - public class CommonTermsQueryDescriptor + public class CommonTermsQueryDescriptor : FieldNameQueryDescriptorBase, ICommonTermsQuery, T> - , ICommonTermsQuery + , ICommonTermsQuery where T : class { string IQuery.Name { get; set; } From 9de884f4661a547685073ac868265997b20e30e2 Mon Sep 17 00:00:00 2001 From: Mpdreamz Date: Tue, 8 Nov 2016 10:36:20 +0100 Subject: [PATCH 2/2] rename target file and make inheritdoc part of normal build --- build/scripts/Targets.fsx | 7 ++----- build/scripts/{InheritDoc.fsx => XmlDocPatcher.fsx} | 0 build/scripts/scripts.fsproj | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) rename build/scripts/{InheritDoc.fsx => XmlDocPatcher.fsx} (100%) diff --git a/build/scripts/Targets.fsx b/build/scripts/Targets.fsx index 59c7e1c1687..fd03fa49d43 100644 --- a/build/scripts/Targets.fsx +++ b/build/scripts/Targets.fsx @@ -6,7 +6,7 @@ #load @"Documentation.fsx" #load @"Releasing.fsx" #load @"Profiling.fsx" -#load @"InheritDoc.fsx" +#load @"XmlDocPatcher.fsx" open System @@ -63,16 +63,13 @@ Target "Canary" <| fun _ -> =?> ("Version", hasBuildParam "version") ==> "BuildApp" =?> ("Test", (not ((getBuildParam "skiptests") = "1"))) + ==> "InheritDoc" ==> "Build" "Clean" ==> "BuildApp" ==> "TestForever" -"Clean" - ==> "BuildApp" - ==> "InheritDoc" - "Clean" ==> "BuildApp" ==> "Profile" diff --git a/build/scripts/InheritDoc.fsx b/build/scripts/XmlDocPatcher.fsx similarity index 100% rename from build/scripts/InheritDoc.fsx rename to build/scripts/XmlDocPatcher.fsx diff --git a/build/scripts/scripts.fsproj b/build/scripts/scripts.fsproj index 82681ebb8d8..cd140fef88b 100644 --- a/build/scripts/scripts.fsproj +++ b/build/scripts/scripts.fsproj @@ -65,7 +65,7 @@ - + @@ -85,4 +85,4 @@ True - \ No newline at end of file +