diff --git a/.paket/Paket.Restore.targets b/.paket/Paket.Restore.targets index e9b3c2a5dd9..55292f317cc 100644 --- a/.paket/Paket.Restore.targets +++ b/.paket/Paket.Restore.targets @@ -75,8 +75,7 @@ - - + diff --git a/.travis.yml b/.travis.yml index b1f759ab8d4..73e24448109 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ language: csharp solution: src/Elasticsearch.sln -script: ./build.sh test +script: ./build.sh test-one skipdocs dist: trusty mono: 4.6.2 -dotnet: 2.0.3 +dotnet: 2.1.3 env: global: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 diff --git a/build/Clients.Common.targets b/build/Clients.Common.targets index 3c3ef866e50..a99a3c98c93 100644 --- a/build/Clients.Common.targets +++ b/build/Clients.Common.targets @@ -5,7 +5,7 @@ 5.0.0 5.0.0 5.0.0 - + $(CurrentVersion) $(CurrentVersion) diff --git a/build/profiling/JetBrains.Profiler.Windows.SelfApi.dll b/build/profiling/JetBrains.Profiler.Windows.SelfApi.dll deleted file mode 100644 index 17f67655c78..00000000000 Binary files a/build/profiling/JetBrains.Profiler.Windows.SelfApi.dll and /dev/null differ diff --git a/build/scripts/Benchmarking.fsx b/build/scripts/Benchmarking.fsx index 7b13b683fcb..53e6947ede8 100644 --- a/build/scripts/Benchmarking.fsx +++ b/build/scripts/Benchmarking.fsx @@ -143,12 +143,12 @@ module Benchmarker = DotNetCli.RunCommand(fun p -> { p with WorkingDir = testsProjectDirectory - }) "run -f net46 -c Release Benchmark" + }) "run -f netcoreapp2.1 -c Release Benchmark" else DotNetCli.RunCommand(fun p -> { p with WorkingDir = testsProjectDirectory - }) "run -f net46 -c Release Benchmark non-interactive" + }) "run -f netcoreapp2.1 -c Release Benchmark non-interactive" finally // running benchmarks can timeout so clean up any generated benchmark files let benchmarkOutputFiles = diff --git a/build/scripts/Building.fsx b/build/scripts/Building.fsx index 23c1af46948..29deb17b204 100644 --- a/build/scripts/Building.fsx +++ b/build/scripts/Building.fsx @@ -26,19 +26,18 @@ module Build = let private runningRelease = hasBuildParam "version" || hasBuildParam "apikey" || getBuildParam "target" = "canary" || getBuildParam "target" = "release" - type private GlobalJson = JsonProvider<"../../global.json"> + type private GlobalJson = JsonProvider<"../../global.json", InferTypesFromValues=false> let private pinnedSdkVersion = GlobalJson.GetSample().Sdk.Version if isMono then setProcessEnvironVar "TRAVIS" "true" - let private buildingOnTravis = getEnvironmentVarAsBool "TRAVIS" - let private sln = sprintf "src/Elasticsearch%s.sln" (if buildingOnTravis then ".DotNetCoreOnly" else "") + let private sln = "src/Elasticsearch.sln" let private compileCore incremental = if not (DotNetCli.isInstalled()) then failwith "You need to install the dotnet command line SDK to build for .NET Core" let runningSdkVersion = DotNetCli.getVersion() if (runningSdkVersion <> pinnedSdkVersion) then failwithf "Attempting to run with dotnet.exe with %s but global.json mandates %s" runningSdkVersion pinnedSdkVersion - let incrementalFramework = DotNetFramework.Net46 + let incrementalFramework = DotNetFramework.NetStandard1_3 let sourceLink = if not incremental && not isMono && runningRelease then "1" else "" let props = [ @@ -46,7 +45,7 @@ module Build = "CurrentAssemblyVersion", (Versioning.CurrentAssemblyVersion.ToString()); "CurrentAssemblyFileVersion", (Versioning.CurrentAssemblyFileVersion.ToString()); "DoSourceLink", sourceLink; - "DotNetCoreOnly", if buildingOnTravis then "1" else ""; + "FakeBuild", "1"; "OutputPathBaseDir", Path.GetFullPath Paths.BuildOutput; ] |> List.map (fun (p,v) -> sprintf "%s=%s" p v) @@ -153,7 +152,7 @@ module Build = trace "Finished rewriting namespaces" let private ilRepackInternal() = - let fw = if isMono then [DotNetFramework.NetStandard1_3] else DotNetFramework.All + let fw = DotNetFramework.All for f in fw do let nest = Project Project.Nest let folder = Paths.ProjectOutputFolder nest f diff --git a/build/scripts/Commandline.fsx b/build/scripts/Commandline.fsx index 484c83650a7..46e98221c8a 100644 --- a/build/scripts/Commandline.fsx +++ b/build/scripts/Commandline.fsx @@ -28,14 +28,13 @@ Targets: * canary [apikey] [feed] - create a canary nuget package based on the current version if [feed] and [apikey] are provided also pushes to upstream (myget) -* diff [format] +* diff [format] NOTE: both the `test` and `integrate` targets can be suffixed with `-all` to force the tests against all suported TFM's Execution hints can be provided anywhere on the command line - skiptests : skip running tests as part of the target chain - skipdocs : skip generating documentation -- source_serialization : force tests to use a client with custom source serialization - seed: : provide a seed to run the tests with. - random:<:B> : sets random K to bool B if if B is omitted will default to true K can be: sourceserializer, typedkeys or oldconnection (only valid on windows) @@ -58,21 +57,30 @@ module Commandline = |> List.filter (fun x -> (x.StartsWith("random:"))) |> List.map (fun x -> (x.Replace("random:", ""))) + let docsBranch = + match args |> List.tryFind (fun x -> x.StartsWith("docs:")) with + | Some t -> t.Replace("docs:", "") + | _ -> "" + let private filteredArgs = args |> List.filter ( fun x -> - x <> "skiptests" && x <> "skipdocs" && x <> "source_serialization" && not (x.StartsWith("seed:")) && not (x.StartsWith("random:")) + x <> "skiptests" && + x <> "skipdocs" && + not (x.StartsWith("seed:")) && + not (x.StartsWith("random:")) && + not (x.StartsWith("docs:")) ) let multiTarget = match (filteredArgs |> List.tryHead) with - | Some t when t.EndsWith("-all") -> MultiTarget.All - | _ -> MultiTarget.One + | Some t when t.EndsWith("-one") -> MultiTarget.One + | _ -> MultiTarget.All let target = match (filteredArgs |> List.tryHead) with - | Some t -> t.Replace("-all", "") + | Some t -> t.Replace("-one", "") | _ -> "build" let validMonoTarget = @@ -206,6 +214,7 @@ module Commandline = setBuildParam "first" firstVersionOrPath setBuildParam "second" secondVersionOrPath + | ["touch"; ] -> ignore() | ["temp"; ] -> ignore() | ["canary"; ] -> ignore() | ["canary"; apiKey ] -> diff --git a/build/scripts/Differ.fsx b/build/scripts/Differ.fsx index 8f2fa052750..b34bd7803b5 100644 --- a/build/scripts/Differ.fsx +++ b/build/scripts/Differ.fsx @@ -7,9 +7,11 @@ #load @"Tooling.fsx" #load @"Projects.fsx" -open Microsoft.FSharp.Reflection open System -open System.Collections.Generic +open System.IO + +open Fake +open System open System.IO open System.Linq open System.Net @@ -17,8 +19,8 @@ open System.Text open System.Text.RegularExpressions open System.Xml open System.Xml.Linq -open Fake open Fake.Git.CommandHelper + open Paths open Projects open Tooling @@ -262,25 +264,6 @@ module Differ = | :? XmlException -> ignore() let private convertToAsciidoc path first second = - let createDiffDescription description (writer:TextWriter) = - let m = Regex.Match(description, "(.*?) changed from (.*?) to (.*).") - if m.Success then - let memberType = m.Groups.[1].Value - let o = m.Groups.[2].Value - let n = m.Groups.[3].Value - writer.WriteLine("+") - writer.WriteLine(sprintf "%s change" memberType) - writer.WriteLine("+") - writer.WriteLine("[source,csharp]") - writer.WriteLine("----") - writer.WriteLine(sprintf "// before in %s" first) - writer.WriteLine(sprintf "%s" o) - writer.WriteLine(sprintf "// now in %s" second) - writer.WriteLine(sprintf "%s" n) - writer.WriteLine("----") - else - writer.WriteLine(sprintf "%s" description) - let name = path |> Path.GetFileNameWithoutExtension try let doc = XDocument.Load path @@ -288,37 +271,35 @@ module Differ = DeleteFile output use file = File.OpenWrite <| output use writer = new StreamWriter(file) - writer.WriteLine(name |> replace "." "-" |> toLower |> sprintf "[[%s-breaking-changes]]") + writer.WriteLine(name |> replace "." "-" |> sprintf "[[%s-breaking-changes]]") writer.WriteLine(sprintf "== Breaking changes for %s between %s and %s" name first second) writer.WriteLine() for element in (doc |> descendents "Type") do let typeName = element |> attributeValue "Name" |> replace (sprintf "%s." name) "" let diffType = element |> attributeValue "DiffType" |> convertDiffType - match diffType with - | Deleted -> writer.WriteLine(sprintf "`%s`:: deleted" typeName) - | New -> writer.WriteLine(sprintf "`%s`:: added" typeName) + | Deleted -> writer.WriteLine(sprintf "[float]%s=== `%s` is deleted" Environment.NewLine typeName) + | New -> writer.WriteLine(sprintf "[float]%s=== `%s` is added" Environment.NewLine typeName) | Modified -> let members = Seq.append (element |> elements "Method") (element |> elements "Property") if Seq.isEmpty members |> not then - writer.WriteLine(sprintf "`%s`::" typeName) + writer.WriteLine(sprintf "[float]%s=== `%s`" Environment.NewLine typeName) for m in members do let memberName = m |> attributeValue "Name" if isNotNullOrEmpty memberName then let diffType = m |> attributeValue "DiffType" if isNotNullOrEmpty diffType then match convertDiffType diffType with - | Deleted -> writer.WriteLine(sprintf " * `%s` deleted" memberName) - | New -> writer.WriteLine(sprintf " * `%s` added" memberName) + | Deleted -> writer.WriteLine(sprintf "[float]%s==== `%s` is deleted" Environment.NewLine memberName) + | New -> writer.WriteLine(sprintf "[float]%s==== `%s` is added" Environment.NewLine memberName) | Modified -> match (m.Descendants(XName.op_Implicit "DiffItem") |> Seq.tryHead) with | Some diffItem -> - writer.WriteLine(sprintf " * `%s`" memberName) + writer.WriteLine(sprintf "[float]%s==== `%s`" Environment.NewLine memberName) let diffDescription = diffItem.Value - writer |> createDiffDescription diffDescription + writer.WriteLine(Regex.Replace(diffDescription, "changed from (.*?) to (.*).", "changed from `$1` to `$2`.")) | None -> () - writer.WriteLine() with | :? XmlException -> ignore() diff --git a/build/scripts/Documentation.fsx b/build/scripts/Documentation.fsx index 49f63a20d79..f9419d1ef46 100644 --- a/build/scripts/Documentation.fsx +++ b/build/scripts/Documentation.fsx @@ -3,6 +3,7 @@ #nowarn "0044" //TODO sort out FAKE 5 #load @"Paths.fsx" +#load @"Commandline.fsx" open System open System.IO @@ -11,17 +12,19 @@ open Fake open Paths open Projects +open Commandline module Documentation = let Generate() = let docGenerator = PrivateProject(DocGenerator) - let path = Paths.ProjectOutputFolder docGenerator DotNetFramework.Net46 - let generator = sprintf "%s/%s.exe" path docGenerator.Name - ExecProcess (fun p -> - p.WorkingDirectory <- Paths.Source("CodeGeneration") @@ docGenerator.Name - p.FileName <- generator - ) (TimeSpan.FromMinutes 3.) |> ignore + let path = Paths.ProjectOutputFolder docGenerator DotNetFramework.NetCoreApp2_1 + let generator = sprintf "%s.dll %s" docGenerator.Name Commandline.docsBranch + + DotNetCli.RunCommand(fun p -> + { p with + WorkingDir = path + }) generator // TODO: hook documentation validation into the process let Validate() = diff --git a/build/scripts/Projects.fsx b/build/scripts/Projects.fsx index 6b3abbc4cbd..272c7ee0de6 100644 --- a/build/scripts/Projects.fsx +++ b/build/scripts/Projects.fsx @@ -16,13 +16,13 @@ module Projects = type DotNetFramework = | Net46 | NetStandard1_3 - | NetCoreApp2_0 + | NetCoreApp2_1 static member All = [Net46; NetStandard1_3] member this.Identifier = match this with - | Net46 -> { MSBuild = "v4.6"; Nuget = "net46"; DefineConstants = if not isMono then "TRACE;NET46" else "NET46"; } - | NetStandard1_3 -> { MSBuild = "netstandard1.3"; Nuget = "netstandard1.3"; DefineConstants = if not isMono then "TRACE;DOTNETCORE" else "DOTNETCORE"; } - | NetCoreApp2_0 -> { MSBuild = "netcoreapp2.0"; Nuget = "netcoreapp2.0"; DefineConstants = if not isMono then "TRACE;DOTNETCORE" else "DOTNETCORE"; } + | Net46 -> { MSBuild = "v4.6"; Nuget = "net46"; DefineConstants = ""; } + | NetStandard1_3 -> { MSBuild = "netstandard1.3"; Nuget = "netstandard1.3"; DefineConstants = ""; } + | NetCoreApp2_1 -> { MSBuild = "netcoreapp2.1"; Nuget = "netcoreapp2.1"; DefineConstants = ""; } type Project = | Nest diff --git a/build/scripts/Targets.fsx b/build/scripts/Targets.fsx index 21aebfb1753..5c81a1cc8d6 100644 --- a/build/scripts/Targets.fsx +++ b/build/scripts/Targets.fsx @@ -34,6 +34,7 @@ open Differ.Differ Commandline.parse() +Target "Touch" <| fun _ -> traceHeader "Touching build" Target "Build" <| fun _ -> traceHeader "STARTING BUILD" Target "Start" <| fun _ -> match (isMono, Commandline.validMonoTarget) with @@ -79,7 +80,10 @@ Target "Release" <| fun _ -> Release.GenerateNotes() Target "TestNugetPackage" <| fun _ -> - Tests.RunReleaseUnitTests() + //RunReleaseUnitTests restores the canary nugetpackages in tests, since these end up being cached + //its too evasive to run on development machines or TC, Run only on AppVeyor containers. + if buildServer <> AppVeyor then Tests.RunUnitTests() + else Tests.RunReleaseUnitTests() Target "Canary" <| fun _ -> trace "Running canary build" @@ -102,7 +106,7 @@ Target "Diff" <| fun _ -> =?> ("Version", hasBuildParam "version") ==> "Restore" =?> ("FullBuild", Commandline.needsFullBuild) - =?> ("Test", (not Commandline.skipTests)) + =?> ("Test", (not Commandline.skipTests && Commandline.target <> "canary")) =?> ("InternalizeDependencies", (not isMono)) ==> "InheritDoc" =?> ("Documentation", (not Commandline.skipDocs)) @@ -120,7 +124,7 @@ Target "Diff" <| fun _ -> "Version" ==> "Release" - =?> ("TestNugetPackage", (not isMono)) + =?> ("TestNugetPackage", (not isMono && not Commandline.skipTests)) ==> "Canary" "Start" @@ -132,6 +136,7 @@ Target "Diff" <| fun _ -> "Build" ==> "Release" +"Touch" "Start" ==> "Clean" ==> "Diff" diff --git a/build/scripts/Testing.fsx b/build/scripts/Testing.fsx index 436a3bffdda..2caa2a36cd2 100644 --- a/build/scripts/Testing.fsx +++ b/build/scripts/Testing.fsx @@ -43,8 +43,9 @@ module Tests = let command = let p = ["xunit"; "-parallel"; "all"; "-xml"; "../.." @@ Paths.Output("TestResults-Desktop-Clr.xml")] match (target, buildingOnTravis) with + //make sure we don't test against net46 on mono or travis systems | (_, true) - | (Commandline.MultiTarget.One, _) -> ["-framework"; "netcoreapp2.0"] |> List.append p + | (Commandline.MultiTarget.One, _) -> ["-framework"; "netcoreapp2.1"] |> List.append p | _ -> p let dotnet = Tooling.BuildTooling("dotnet") diff --git a/build/scripts/Tooling.fsx b/build/scripts/Tooling.fsx index 215a1ee4730..8c989ac1816 100644 --- a/build/scripts/Tooling.fsx +++ b/build/scripts/Tooling.fsx @@ -109,12 +109,12 @@ module Tooling = let jetBrainsTools = [{ DotTraceTool.Name = "JetBrains DotTrace Self-Profile API"; - Download = "https://download-cf.jetbrains.com/resharper/JetBrains.Profiler.SelfSdk.2016.3.2.zip"; + Download = "https://download-cf.jetbrains.com/resharper/JetBrains.Profiler.SelfSdk.2017.3.2.zip"; TargetDir = "dottrace-selfprofile"; }; { DotTraceTool.Name = "JetBrains DotTrace Commandline Tools"; - Download = "https://download-cf.jetbrains.com/resharper/JetBrains.dotTrace.CommandLineTools.2016.3.20170126.121657.zip"; + Download = "https://download-cf.jetbrains.com/resharper/JetBrains.dotTrace.CommandLineTools.2017.3.2.zip"; TargetDir = "dottrace-commandline"; }] @@ -139,7 +139,6 @@ module Tooling = let toolPath = commandLineTool @@ path member this.Exec arguments = execAt Environment.CurrentDirectory toolPath arguments - let DotTraceProfiler = new ProfilerTooling("ConsoleProfiler.exe") let DotTraceReporter = new ProfilerTooling("Reporter.exe") let DotTraceSnapshotStats = new ProfilerTooling("SnapshotStat.exe") @@ -165,5 +164,5 @@ module Tooling = let result = execProcessWithTimeout toolPath arguments (TimeSpan.FromMinutes 5.) "." if result <> 0 then failwith (sprintf "Failed to run diff tooling for %s args: %A" exe arguments) - let JustAssembly = DiffTooling("JustAssembly.CommandLineTool.exe") + let JustAssembly = DiffTooling("JustAssembly.CommandLineTool.exe") diff --git a/contributing.md b/contributing.md index 664941cdf81..25917da9e65 100644 --- a/contributing.md +++ b/contributing.md @@ -12,7 +12,7 @@ We do ask that you sign the [Elasticsearch CLA](http://www.elasticsearch.org/con ## Coding Styleguide -Please install the [editorconfig vs extension](https://visualstudiogallery.msdn.microsoft.com/c8bccfe2-650c-4b42-bc5c-845e21f96328) +Please install the [Editorconfig vs extension](https://visualstudiogallery.msdn.microsoft.com/c8bccfe2-650c-4b42-bc5c-845e21f96328) this will automatically switch to our indentation, whitespace, newlines settings while working on our project **while leaving your default settings intact**. diff --git a/global.json b/global.json index cf8f3727151..6a1433b3ce7 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "2.0.3" + "version": "2.1.300" }, "version": "5.6.2" } \ No newline at end of file diff --git a/paket.lock b/paket.lock index e5a288f7d74..699baf125d1 100644 --- a/paket.lock +++ b/paket.lock @@ -4,8 +4,8 @@ GROUP build NUGET remote: https://www.nuget.org/api/v2 Elasticsearch.Net (5.6.2) - restriction: == net45 - FAKE (5.0.0-rc018.244) - FSharp.Core (4.3.4) - restriction: && (< net40) (< portable-net45+win8+wp8+wpa81) + FAKE (5.0) + FSharp.Core (4.5) - restriction: && (< net40) (< portable-net45+win8+wp8+wpa81) FSharp.Data (2.4.6) FSharp.Core (>= 4.0.0.1) - restriction: && (< net40) (< portable-net45+win8+wp8+wpa81) Zlib.Portable (>= 1.11) - restriction: || (&& (< net40) (>= portable-net45+win8)) (&& (< net40) (< portable-net45+win8) (>= portable-net45+win8+wp8+wpa81)) diff --git a/src/CodeGeneration/ApiGenerator/ApiGenerator.cs b/src/CodeGeneration/ApiGenerator/ApiGenerator.cs index 8ffa75ae401..8f2768ba6c2 100644 --- a/src/CodeGeneration/ApiGenerator/ApiGenerator.cs +++ b/src/CodeGeneration/ApiGenerator/ApiGenerator.cs @@ -5,15 +5,17 @@ using System.Linq; using ApiGenerator.Domain; using Newtonsoft.Json; -using Xipton.Razor; using ShellProgressBar; using Newtonsoft.Json.Linq; +using RazorLight; namespace ApiGenerator { public class ApiGenerator { - static readonly RazorMachine RazorHelper = new RazorMachine(); + private static readonly RazorLightEngine Razor = new RazorLightEngineBuilder() + .UseMemoryCachingProvider() + .Build(); public static void Generate(string downloadBranch, params string[] folders) { @@ -22,19 +24,20 @@ public static void Generate(string downloadBranch, params string[] folders) { { GenerateClientInterface, "Client interface" }, { GenerateRequestParameters, "Request parameters" }, - { GenerateRequestParametersExtensions, "Request parameters override" }, { GenerateDescriptors, "Descriptors" }, { GenerateRequests, "Requests" }, { GenerateEnums, "Enums" }, { GenerateRawClient, "Lowlevel client" }, { GenerateRawDispatch, "Dispatch" }, + { GenerateRequestParametersExtensions, "Request parameters override" }, + }; using (var pbar = new ProgressBar(actions.Count, "Generating code", new ProgressBarOptions { BackgroundColor = ConsoleColor.DarkGray })) { foreach(var kv in actions) { - pbar.UpdateMessage("Generating " + kv.Value); + pbar.Message = "Generating " + kv.Value; kv.Key(spec); pbar.Tick("Generated " + kv.Value); } @@ -139,59 +142,64 @@ private static string CreateMethodName(string apiEndpointKey) return PascalCase(apiEndpointKey); } + private static string DoRazor(string name, string template, RestApiSpec model) + { + return Razor.CompileRenderAsync(name, template, model).GetAwaiter().GetResult(); + } + private static void GenerateClientInterface(RestApiSpec model) { var targetFile = CodeConfiguration.EsNetFolder + @"IElasticLowLevelClient.Generated.cs"; - var source = RazorHelper.Execute(File.ReadAllText(CodeConfiguration.ViewFolder + @"IElasticLowLevelClient.Generated.cshtml"), model).ToString(); + var source = DoRazor(nameof(GenerateClientInterface), File.ReadAllText(CodeConfiguration.ViewFolder + @"IElasticLowLevelClient.Generated.cshtml"), model); File.WriteAllText(targetFile, source); } private static void GenerateRawDispatch(RestApiSpec model) { var targetFile = CodeConfiguration.NestFolder + @"_Generated/_LowLevelDispatch.Generated.cs"; - var source = RazorHelper.Execute(File.ReadAllText(CodeConfiguration.ViewFolder + @"_LowLevelDispatch.Generated.cshtml"), model).ToString(); + var source = DoRazor(nameof(GenerateRawDispatch), File.ReadAllText(CodeConfiguration.ViewFolder + @"_LowLevelDispatch.Generated.cshtml"), model); File.WriteAllText(targetFile, source); } private static void GenerateRawClient(RestApiSpec model) { var targetFile = CodeConfiguration.EsNetFolder + @"ElasticLowLevelClient.Generated.cs"; - var source = RazorHelper.Execute(File.ReadAllText(CodeConfiguration.ViewFolder + @"ElasticLowLevelClient.Generated.cshtml"), model).ToString(); + var source = DoRazor(nameof(GenerateRawClient), File.ReadAllText(CodeConfiguration.ViewFolder + @"ElasticLowLevelClient.Generated.cshtml"), model); File.WriteAllText(targetFile, source); } private static void GenerateDescriptors(RestApiSpec model) { var targetFile = CodeConfiguration.NestFolder + @"_Generated\_Descriptors.Generated.cs"; - var source = RazorHelper.Execute(File.ReadAllText(CodeConfiguration.ViewFolder + @"_Descriptors.Generated.cshtml"), model).ToString(); + var source = DoRazor(nameof(GenerateDescriptors), File.ReadAllText(CodeConfiguration.ViewFolder + @"_Descriptors.Generated.cshtml"), model); File.WriteAllText(targetFile, source); } private static void GenerateRequests(RestApiSpec model) { var targetFile = CodeConfiguration.NestFolder + @"_Generated\_Requests.Generated.cs"; - var source = RazorHelper.Execute(File.ReadAllText(CodeConfiguration.ViewFolder + @"_Requests.Generated.cshtml"), model).ToString(); + var source = DoRazor(nameof(GenerateRequests), File.ReadAllText(CodeConfiguration.ViewFolder + @"_Requests.Generated.cshtml"), model); File.WriteAllText(targetFile, source); } private static void GenerateRequestParameters(RestApiSpec model) { var targetFile = CodeConfiguration.EsNetFolder + @"Domain\RequestParameters\RequestParameters.Generated.cs"; - var source = RazorHelper.Execute(File.ReadAllText(CodeConfiguration.ViewFolder + @"RequestParameters.Generated.cshtml"), model).ToString(); + var source = DoRazor(nameof(GenerateRequestParameters), File.ReadAllText(CodeConfiguration.ViewFolder + @"RequestParameters.Generated.cshtml"), model); File.WriteAllText(targetFile, source); } private static void GenerateRequestParametersExtensions(RestApiSpec model) { var targetFile = CodeConfiguration.NestFolder + @"_Generated\_RequestParametersExtensions.Generated.cs"; - var source = RazorHelper.Execute(File.ReadAllText(CodeConfiguration.ViewFolder + @"_RequestParametersExtensions.Generated.cshtml"), model).ToString(); + var source = DoRazor(nameof(GenerateRequestParametersExtensions), File.ReadAllText(CodeConfiguration.ViewFolder + @"_RequestParametersExtensions.Generated.cshtml"), model); File.WriteAllText(targetFile, source); } private static void GenerateEnums(RestApiSpec model) { var targetFile = CodeConfiguration.EsNetFolder + @"Domain\Enums.Generated.cs"; - var source = RazorHelper.Execute(File.ReadAllText(CodeConfiguration.ViewFolder + @"Enums.Generated.cshtml"), model).ToString(); + var source = DoRazor(nameof(GenerateEnums), File.ReadAllText(CodeConfiguration.ViewFolder + @"Enums.Generated.cshtml"), model); File.WriteAllText(targetFile, source); } } diff --git a/src/CodeGeneration/ApiGenerator/ApiGenerator.csproj b/src/CodeGeneration/ApiGenerator/ApiGenerator.csproj index f37cc3fd72d..e8cf307dd64 100644 --- a/src/CodeGeneration/ApiGenerator/ApiGenerator.csproj +++ b/src/CodeGeneration/ApiGenerator/ApiGenerator.csproj @@ -2,16 +2,20 @@ Exe - net46 + netcoreapp2.1 6.0.0 alpha + NU1701 + true - - - - - + + + + + + + \ No newline at end of file diff --git a/src/CodeGeneration/ApiGenerator/Domain/Constructor.cs b/src/CodeGeneration/ApiGenerator/Domain/Constructor.cs index 3f7176b8af1..c061d2c17f9 100644 --- a/src/CodeGeneration/ApiGenerator/Domain/Constructor.cs +++ b/src/CodeGeneration/ApiGenerator/Domain/Constructor.cs @@ -7,7 +7,7 @@ public class Constructor public string Generated { get; set; } public string Url { get; set; } public string Description { get; set; } - public string AdditionalCode { get; set;} + public string AdditionalCode { get; set; } = string.Empty; } public class FluentRouteSetter @@ -15,4 +15,4 @@ public class FluentRouteSetter public string Code { get; set; } public string XmlDoc { get; set; } } -} \ No newline at end of file +} diff --git a/src/CodeGeneration/ApiGenerator/Domain/CsharpMethod.cs b/src/CodeGeneration/ApiGenerator/Domain/CsharpMethod.cs index d83082e7e86..44f3b5ff71a 100644 --- a/src/CodeGeneration/ApiGenerator/Domain/CsharpMethod.cs +++ b/src/CodeGeneration/ApiGenerator/Domain/CsharpMethod.cs @@ -110,10 +110,10 @@ public IEnumerable RequestConstructors() ); } - var doc = $@"/// {url}"; + var doc = $@"///{url}"; if (urlRouteParameters.Any()) { - doc += "\r\n" + string.Join("\t\t\r\n", urlRouteParameters.Select(p => $"///{(p.Value.Required ? "this parameter is required" : "Optional, accepts null")}")); + doc += "\r\n\t\t" + string.Join("\r\n\t\t", urlRouteParameters.Select(p => $"///{(p.Value.Required ? "this parameter is required" : "Optional, accepts null")}")); } var generated = $"public {m}({par}) : base({routing}){{}}"; @@ -138,7 +138,7 @@ public IEnumerable RequestConstructors() { var documentPathGeneric = Regex.Replace(this.DescriptorTypeGeneric, @"^]+).*$", "$1"); var doc = $@"/// {this.Url.Path}"; - doc += "\r\n\t\t\r\n" + $"/// describes an elasticsearch document of type from which the index, type and id can be inferred"; + doc += "\r\n\t\t" + $"/// describes an elasticsearch document of type from which the index, type and id can be inferred"; var documentRoute = "r=>r.Required(\"index\", index ?? document.Self.Index).Required(\"type\", type ?? document.Self.Type).Required(\"id\", id ?? document.Self.Id)"; var documentFromPath = $"partial void DocumentFromPath({documentPathGeneric} document);"; @@ -206,7 +206,7 @@ public IEnumerable DescriptorConstructors() var doc = $@"/// {url}"; if (requiredUrlRouteParameters.Any()) { - doc += "\r\n" + string.Join("\t\t\r\n", requiredUrlRouteParameters.Select(p => $"/// this parameter is required")); + doc += "\r\n\t\t" + string.Join("\r\n\t\t", requiredUrlRouteParameters.Select(p => $"/// this parameter is required")); } var generated = $"public {m}({par}) : base({routing}){{}}"; diff --git a/src/CodeGeneration/ApiGenerator/Program.cs b/src/CodeGeneration/ApiGenerator/Program.cs index e732051c908..4e353ece672 100644 --- a/src/CodeGeneration/ApiGenerator/Program.cs +++ b/src/CodeGeneration/ApiGenerator/Program.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; namespace ApiGenerator { diff --git a/src/CodeGeneration/ApiGenerator/RestSpecDownloader.cs b/src/CodeGeneration/ApiGenerator/RestSpecDownloader.cs index 2745dbeded2..b43bb6f99db 100644 --- a/src/CodeGeneration/ApiGenerator/RestSpecDownloader.cs +++ b/src/CodeGeneration/ApiGenerator/RestSpecDownloader.cs @@ -27,8 +27,8 @@ private class Specification private static readonly ProgressBarOptions MainProgressBarOptions = new ProgressBarOptions { BackgroundColor = ConsoleColor.DarkGray }; private static readonly ProgressBarOptions SubProgressBarOptions = new ProgressBarOptions { - ForeGroundColor = ConsoleColor.Cyan, - ForeGroundColorDone = ConsoleColor.DarkGreen, + ForegroundColor = ConsoleColor.Cyan, + ForegroundColorDone = ConsoleColor.DarkGreen, ProgressCharacter = '─', BackgroundColor = ConsoleColor.DarkGray, }; @@ -45,7 +45,7 @@ private RestSpecDownloader(string branch) { foreach (var spec in specifications) { - pbar.UpdateMessage($"Downloading rest-api-spec to {spec.FolderOnDisk} for branch {branch}"); + pbar.Message = $"Downloading rest-api-spec to {spec.FolderOnDisk} for branch {branch}"; DownloadJsonDefinitions(spec, pbar); pbar.Tick($"Downloaded rest-api-spec to {spec.FolderOnDisk} for branch {branch}"); } diff --git a/src/CodeGeneration/ApiGenerator/Views/ElasticLowLevelClient.Generated.cshtml b/src/CodeGeneration/ApiGenerator/Views/ElasticLowLevelClient.Generated.cshtml index 5dc355cbe66..65b444c44b2 100644 --- a/src/CodeGeneration/ApiGenerator/Views/ElasticLowLevelClient.Generated.cshtml +++ b/src/CodeGeneration/ApiGenerator/Views/ElasticLowLevelClient.Generated.cshtml @@ -1,3 +1,5 @@ +@using RazorLight +@inherits TemplatePage @using System @using System.Collections.Generic @using System.Globalization @@ -43,24 +45,28 @@ namespace Elasticsearch.Net ? string.Join("|", method.Url.Parts.Where(p => !partsNotToReplace.Contains(p.Key)).Select(p => p.Key)) : @"\w+"; var pattern = string.IsNullOrEmpty(partNames) ? @"\w+" : partNames; - var patchedUrl = Regex.Replace(url, "{(" + pattern + ")}", "{$1.NotNull(\"$1\")}"); + var patchedUrl = Regex.Replace(url, "{(" + pattern + ")}", "{$1.NotNull(\"$1\")}"); bool isAsync = method.ReturnType.StartsWith("Task<"); string requestMethod = isAsync ? "DoRequestAsync" : "DoRequest"; - ///Represents a @method.HttpMethod on @method.Path + + ///Represents a @method.HttpMethod on @method.Path ///Returns: @Raw(method.ReturnDescription) - ///See also: @method.Documentation - /// + ///See also: @method.Documentation + /// + foreach (var part in method.Parts) { - @Raw("///")@part.Description@Raw("") + @Raw("///")@part.Description@Raw("") + } - @Raw(@"///A func that allows you to describe the querystring parameters & request specific connection settings.") + @Raw(@"///A func that allows you to describe the querystring parameters & request specific connection settings.") + if (!string.IsNullOrEmpty(method.ObsoleteMethodVersion)) { [Obsolete("Scheduled to be removed in 6.0, @method.ObsoleteMethodVersion removed this method from the rest specification")] } - public @Raw(method.ReturnType) @(method.FullName)@(Raw(method.ReturnTypeGeneric))(@Raw(method.Arguments)) - where @method.CallTypeGeneric : class => this.@(requestMethod)@(Raw("<" + method.CallTypeGeneric +">"))(@method.HttpMethod, Url($"@(Raw(patchedUrl))"), @(method.FullName.Contains("Async") ? "cancellationToken, " : string.Empty)@(method.Parts.Any(pp=>pp.Name == "body") ? "body" : "null"), _params(requestParameters@(method.Allow404 ? ", allow404: true" :"")@(Raw(url.StartsWith("_cat") ? ", contentType: \"text/plain\", accept: \"text/plain\"" : "")))); - + public @Raw(method.ReturnType) @(method.FullName)@(Raw(method.ReturnTypeGeneric))(@Raw(method.Arguments)) + where @method.CallTypeGeneric : class => this.@(requestMethod)@(Raw("<" + method.CallTypeGeneric + ">"))(@method.HttpMethod, Url($"@(Raw(patchedUrl))"), @(method.FullName.Contains("Async") ? "cancellationToken, " : string.Empty)@(method.Parts.Any(pp => pp.Name == "body") ? "body" : "null"), _params(requestParameters@(method.Allow404 ? ", allow404: true" : "")@(Raw(url.StartsWith("_cat") ? ", contentType: \"text/plain\", accept: \"text/plain\"" : "")))); + } } diff --git a/src/CodeGeneration/ApiGenerator/Views/Enums.Generated.cshtml b/src/CodeGeneration/ApiGenerator/Views/Enums.Generated.cshtml index 67bb3ff3b42..af082e4d4ab 100644 --- a/src/CodeGeneration/ApiGenerator/Views/Enums.Generated.cshtml +++ b/src/CodeGeneration/ApiGenerator/Views/Enums.Generated.cshtml @@ -1,3 +1,5 @@ +@using RazorLight +@inherits TemplatePage @using System @using System.Collections.Generic @using System.Linq @@ -10,7 +12,7 @@ private string CreateEnum(string enumName, string value, int? i) { var enumValue = (enumName == SizeEnum && value == string.Empty) ? RawSize : value.ToPascalCase(true); - return string.Format("[EnumMember(Value = \"{0}\")]\r\n\t\t{1}{2}", value, enumValue, i.HasValue ? " = 1 << " + i.Value : null); + return string.Format("[EnumMember(Value = \"{0}\")] {1}{2}", value, enumValue, i.HasValue ? " = 1 << " + i.Value : null); } private string CreateCase(string e, string o) { @@ -55,13 +57,24 @@ namespace Elasticsearch.Net @(isFlag ? "[Flags]" : string.Empty)public enum @e.Name { - @Raw(string.Join(",\r\n\t\t", e.Options.OrderBy(s => s == "_all" ? 1 : 0).Select((s, i) => CreateEnum(e.Name, s, isFlag ? (int?)i : null)))) + @Raw(string.Join(",\r\n\t\t", e.Options.OrderBy(s => s == "_all" ? 1 : 0).Select((s, i) => CreateEnum(e.Name, s, isFlag ? (int?)i : null)))) } } public static class KnownEnums - { - private class EnumDictionary : @(Raw("Dictionary")) + { + private static readonly @(Raw("ConcurrentDictionary>")) EnumStringResolvers = new @(Raw("ConcurrentDictionary>"))(); + + static KnownEnums() + { + @foreach (EnumDescription e in Model.EnumsInTheSpec) + { + EnumStringResolvers.TryAdd(typeof(@(e.Name)), (e) => GetStringValue((@(e.Name))e)); + + } + } + + private class EnumDictionary : @(Raw("Dictionary")) { public EnumDictionary(int capacity) : base(capacity) {} public @(Raw("Func")) Resolver { get; set; } @@ -79,38 +92,30 @@ namespace Elasticsearch.Net var allOption = e.Options.FirstOrDefault(o => o == "_all"); if (allOption != null) { - if ((enumValue & @(e.Name).All) != 0) return "_all"; + if ((enumValue & @(e.Name).All) != 0) return "_all"; + } - var list = new @(Raw("List()")); + var list = new @(Raw("List()")); + foreach (var option in e.Options.Where(o => o != "_all")) { - if ((enumValue & @(e.Name).@(GetEnumValue(e.Name, option))) != 0) list.Add("@(option)"); + if ((enumValue & @(e.Name).@(GetEnumValue(e.Name, option))) != 0) list.Add("@(option)"); + } - return string.Join(",", list); + return string.Join(",", list); } } else { - switch (enumValue) + switch (enumValue) { @Raw(string.Join("\r\n\t\t\t\t", e.Options.Select(o => CreateCase(e.Name, o)))) } - throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum '@(e.Name)'"); + throw new ArgumentException($"'{enumValue.ToString()}' is not a valid value for enum '@(e.Name)'"); } } } - private static readonly @(Raw("ConcurrentDictionary>")) EnumStringResolvers = - new @(Raw("ConcurrentDictionary>"))(); - - static KnownEnums() - { - @foreach (EnumDescription e in Model.EnumsInTheSpec) - { - EnumStringResolvers.TryAdd(typeof(@(e.Name)), (e) => GetStringValue((@(e.Name))e)); - } - } - public static string GetStringValue(this Enum e) { var type = e.GetType(); diff --git a/src/CodeGeneration/ApiGenerator/Views/IElasticLowLevelClient.Generated.cshtml b/src/CodeGeneration/ApiGenerator/Views/IElasticLowLevelClient.Generated.cshtml index e4dfc1cb010..57d87c5caf2 100644 --- a/src/CodeGeneration/ApiGenerator/Views/IElasticLowLevelClient.Generated.cshtml +++ b/src/CodeGeneration/ApiGenerator/Views/IElasticLowLevelClient.Generated.cshtml @@ -1,3 +1,6 @@ +@using RazorLight +@using ApiGenerator.Domain +@inherits TemplatePage using System; using System.Collections.Generic; using System.Collections.Specialized; @@ -33,15 +36,18 @@ namespace Elasticsearch.Net var endpoint = kv.Value; foreach(var method in endpoint.GetCsharpMethods()) { - ///Represents a @method.HttpMethod on @method.Path + + ///Represents a @method.HttpMethod on @method.Path ///Returns: @Raw(method.ReturnDescription) ///See also: @method.Documentation - /// + /// + foreach (var part in method.Parts) { - @Raw("///")@part.Description@Raw("") + @Raw("///")@part.Description@Raw("") + } - @Raw(@"///A func that allows you to describe the querystring parameters & request specific connection settings.") + @Raw(@"///A func that allows you to describe the querystring parameters & request specific connection settings.") @Raw(method.ReturnType) @(method.FullName)@(Raw(method.ReturnTypeGeneric))(@Raw(method.Arguments)) where @method.CallTypeGeneric : class; } diff --git a/src/CodeGeneration/ApiGenerator/Views/RequestParameters.Generated.cshtml b/src/CodeGeneration/ApiGenerator/Views/RequestParameters.Generated.cshtml index 7febac5adc4..86ef9a8ed62 100644 --- a/src/CodeGeneration/ApiGenerator/Views/RequestParameters.Generated.cshtml +++ b/src/CodeGeneration/ApiGenerator/Views/RequestParameters.Generated.cshtml @@ -1,3 +1,5 @@ +@using RazorLight +@inherits TemplatePage @using System.Collections.Generic @using ApiGenerator.Domain @using ApiGenerator @@ -25,20 +27,20 @@ namespace Elasticsearch.Net public class @method.QueryStringParamName : FluentRequestParameters<@method.QueryStringParamName> { public override HttpMethod DefaultHttpMethod => HttpMethod.@method.HttpMethod; - @foreach (KeyValuePair kv in method.Url.Params) - { - var mm = kv.Key; - var fieldType = kv.Value.CsharpType(kv.Key).Replace("params", ""); - var setter = mm; - var isFields = (mm.Contains("fields") || mm.Contains("source_include") || mm.Contains("source_exclude")); - if (isFields && fieldType.Contains("string")) - { - fieldType = "IEnumerable"; - } - else if (mm.Contains("field") && fieldType.Contains("string")) - { - fieldType = "object"; - } + @foreach (KeyValuePair kv in method.Url.Params) + { + var mm = kv.Key; + var fieldType = kv.Value.CsharpType(kv.Key).Replace("params", ""); + var setter = mm; + var isFields = (mm.Contains("fields") || mm.Contains("source_include") || mm.Contains("source_exclude")); + if (isFields && fieldType.Contains("string")) + { + fieldType = "IEnumerable"; + } + else if (mm.Contains("field") && fieldType.Contains("string")) + { + fieldType = "object"; + } ///@kv.Value.Description @if (!string.IsNullOrWhiteSpace(kv.Value.Obsolete)) @@ -46,7 +48,7 @@ namespace Elasticsearch.Net } @Raw(kv.Value.FluentGenerator.Invoke(method.QueryStringParamName, mm, kv.Value.OriginalQueryStringParamName, setter)) - } - } + } +} } } \ No newline at end of file diff --git a/src/CodeGeneration/ApiGenerator/Views/_Descriptors.Generated.cshtml b/src/CodeGeneration/ApiGenerator/Views/_Descriptors.Generated.cshtml index b17e941dad9..81c230bf73d 100644 --- a/src/CodeGeneration/ApiGenerator/Views/_Descriptors.Generated.cshtml +++ b/src/CodeGeneration/ApiGenerator/Views/_Descriptors.Generated.cshtml @@ -1,3 +1,5 @@ +@using RazorLight +@inherits TemplatePage @using System.Collections.Generic @using System.Linq @using CsQuery.ExtensionMethods.Internal @@ -25,27 +27,28 @@ namespace Nest { @foreach (ApiUrlPart part in method.AllParts.Where(p=>!ApiUrl.BlackListRouteValues.Contains(p.Name))) { - @(Raw(part.ClrTypeName)) @(Raw(method.InterfaceType)).@(part.InterfaceName) => Self.RouteValues.Get@(Raw(string.Format("<{0}>",part.ClrTypeName)))("@(part.Name)"); + @(Raw(part.ClrTypeName)) @(Raw(method.InterfaceType)).@(part.InterfaceName) => Self.RouteValues.Get@(Raw(string.Format("<{0}>",part.ClrTypeName)))("@(part.Name)"); + } @foreach (Constructor c in method.DescriptorConstructors()) - { - @(Raw(c.Description)) + { + @(Raw(c.Description)) @(Raw(c.Generated)) @(Raw(c.AdditionalCode)) - } + } @foreach (FluentRouteSetter c in method.GetFluentRouteSetters()) - { - @(Raw(c.XmlDoc)) + { + @(Raw(c.XmlDoc)) @(Raw(c.Code)) - } + } foreach (KeyValuePair kv in method.Url.Params) { - if (method.Url.Parts != null && method.Url.Parts.ContainsKey(kv.Key)) - { + if (method.Url.Parts != null && method.Url.Parts.ContainsKey(kv.Key)) + { continue; - } + } var t = @kv.Value.HighLevelType(kv.Key); var tMethod = t == "Time" ? ".ToTimeSpan()" : ""; var tSuffix = (t == "bool") ? " = true" : ""; diff --git a/src/CodeGeneration/ApiGenerator/Views/_LowLevelDispatch.Generated.cshtml b/src/CodeGeneration/ApiGenerator/Views/_LowLevelDispatch.Generated.cshtml index 9125e24aedf..a1b61ad865a 100644 --- a/src/CodeGeneration/ApiGenerator/Views/_LowLevelDispatch.Generated.cshtml +++ b/src/CodeGeneration/ApiGenerator/Views/_LowLevelDispatch.Generated.cshtml @@ -1,3 +1,5 @@ +@using RazorLight +@inherits TemplatePage @using System.Linq @using ApiGenerator.Domain @using ApiGenerator @@ -20,7 +22,6 @@ namespace Nest ///This dispatches highlevel requests into the proper lowlevel client overload method internal partial class LowLevelDispatch { - @foreach (var kv in model.Endpoints) { var endpoint = kv.Value; @@ -38,7 +39,8 @@ namespace Nest }; foreach(var gen in generate) { - internal @Raw(gen.Returns) @(Raw(gen.Name))(IRequest<@peek.QueryStringParamName> p @if (endpoint.Body != null) {, @(Raw("PostData")) body}@(gen.Async ? ", CancellationToken cancellationToken" : string.Empty)) where T : class + + internal @Raw(gen.Returns) @(Raw(gen.Name))(IRequest<@peek.QueryStringParamName> p @if (endpoint.Body != null) {, @(Raw("PostData")) body}@(gen.Async ? ", CancellationToken cancellationToken" : string.Empty)) where T : class { switch(p.HttpMethod) { @@ -49,7 +51,7 @@ namespace Nest var totalDispatches = dispatches.Count(); var allWithIfChecks = dispatches.All(d => !string.IsNullOrEmpty(d.IfCheck)); var i = 0; - case @httpMethod.ToUpper(): + case @httpMethod.ToUpper(): @foreach (var dispatch in dispatches) { var method = dispatch.CsharpMethod; @@ -70,22 +72,26 @@ namespace Nest var hasIfCheck = !string.IsNullOrEmpty(dispatch.IfCheck); if (i == 0 && !hasIfCheck) { - return _lowLevel.@(Raw(name))(@Raw(string.Join(",", methodArguments))); + return _lowLevel.@(Raw(name))(@Raw(string.Join(",", methodArguments))); + } else { if (hasIfCheck) { - if (@Raw(dispatch.IfCheck)) return _lowLevel.@(Raw(name))(@Raw(string.Join(",", methodArguments))); + if (@Raw(dispatch.IfCheck)) return _lowLevel.@(Raw(name))(@Raw(string.Join(",", methodArguments))); + } else { - return _lowLevel.@(Raw(name))(@Raw(string.Join(",", methodArguments))); + return _lowLevel.@(Raw(name))(@Raw(string.Join(",", methodArguments))); + } } if (i == totalDispatches - 1 && allWithIfChecks) { - break; + break; + } i++; } diff --git a/src/CodeGeneration/ApiGenerator/Views/_RequestParametersExtensions.Generated.cshtml b/src/CodeGeneration/ApiGenerator/Views/_RequestParametersExtensions.Generated.cshtml index 9115f97a20d..8309aa1e095 100644 --- a/src/CodeGeneration/ApiGenerator/Views/_RequestParametersExtensions.Generated.cshtml +++ b/src/CodeGeneration/ApiGenerator/Views/_RequestParametersExtensions.Generated.cshtml @@ -1,3 +1,5 @@ +@using RazorLight +@inherits TemplatePage @using System.Collections.Generic @using System.Linq @using ApiGenerator.Domain diff --git a/src/CodeGeneration/ApiGenerator/Views/_Requests.Generated.cshtml b/src/CodeGeneration/ApiGenerator/Views/_Requests.Generated.cshtml index cfcfc5f5cae..5516e06b29e 100644 --- a/src/CodeGeneration/ApiGenerator/Views/_Requests.Generated.cshtml +++ b/src/CodeGeneration/ApiGenerator/Views/_Requests.Generated.cshtml @@ -1,3 +1,5 @@ +@using RazorLight +@inherits TemplatePage @using System.Collections.Generic @using System.Linq @using System.Net.Cache @@ -35,24 +37,29 @@ namespace Nest [JsonObject(MemberSerialization = MemberSerialization.OptIn)] public partial interface @(Raw(method.InterfaceType)) : IRequest@(Raw(string.Format("<{0}>", method.QueryStringParamName))) - { + { + foreach (ApiUrlPart part in method.AllParts.Where(p=>!ApiUrl.BlackListRouteValues.Contains(p.Name))) { - @(Raw(part.ClrTypeName)) @(part.InterfaceName) { get; } + @(Raw(part.ClrTypeName)) @(part.InterfaceName) { get; } + } - } + } + } - ///Request parameters for @method.FullName
@method.Documentation
+ ///Request parameters for @method.FullName
@method.Documentation
public partial class @Raw(method.RequestType + method.RequestTypeGeneric) @Raw(string.Format(" : PlainRequestBase<{0}>, {1}", method.QueryStringParamName, method.InterfaceType)) { protected @(Raw(method.InterfaceType)) Self => this; @foreach (ApiUrlPart part in method.AllParts.Where(p=>!ApiUrl.BlackListRouteValues.Contains(p.Name))) { - @(Raw(part.ClrTypeName)) @(Raw(method.InterfaceType)).@(part.InterfaceName) => Self.RouteValues.Get@(Raw(string.Format("<{0}>",part.ClrTypeName)))("@(part.Name)"); + @(Raw(part.ClrTypeName)) @(Raw(method.InterfaceType)).@(part.InterfaceName) => Self.RouteValues.Get@(Raw(string.Format("<{0}>",part.ClrTypeName)))("@(part.Name)"); + } @foreach (Constructor c in method.RequestConstructors()) - { - @(Raw(c.Description)) + { + + @(Raw(c.Description)) @(Raw(c.Generated)) @(Raw(c.AdditionalCode)) @@ -60,9 +67,9 @@ namespace Nest @foreach (KeyValuePair kv in method.Url.Params) { if (method.Url.Parts != null && method.Url.Parts.ContainsKey(kv.Key)) - { + { continue; - } + } var original = kv.Value.OriginalQueryStringParamName; var cased = kv.Key.ToPascalCase(); var mm = (cased != "Type" && cased != "Index" && cased != "Script") ? cased : cased + "QueryString"; @@ -77,19 +84,19 @@ namespace Nest fieldType = "Field"; } var setter = "value"; - ///@kv.Value.Description - @if(!string.IsNullOrWhiteSpace(kv.Value.Obsolete)) + + ///@kv.Value.Description + @if (!string.IsNullOrWhiteSpace(kv.Value.Obsolete)) { - [Obsolete("Scheduled to be removed in 6.0, @kv.Value.Obsolete")] + [Obsolete("Scheduled to be removed in 6.0, @kv.Value.Obsolete")] } @Raw(kv.Value.Generator.Invoke(fieldType, mm, original, setter)) - + } @if (method.RequestTypeUnmapped) { //TODO THIS METHOD IS UNMAPPED! } - } +}
} } - \ No newline at end of file diff --git a/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs b/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs index 13554c6b927..6a9367e2199 100644 --- a/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs +++ b/src/CodeGeneration/DocGenerator/AsciiDoc/GeneratedAsciidocVisitor.cs @@ -33,8 +33,8 @@ public class GeneratedAsciidocVisitor : NoopVisitor private readonly FileInfo _source; private readonly FileInfo _destination; - private readonly Dictionary _projects; - private int _topSectionTitleLevel; + private readonly Dictionary _projects; + private int _topSectionTitleLevel; private Document _document; private Document _newDocument; private bool _topLevel = true; @@ -43,7 +43,7 @@ public GeneratedAsciidocVisitor(FileInfo source, FileInfo destination, Dictionar { _source = source; _destination = destination; - _projects = projects; + _projects = projects; } public Document Convert(Document document) @@ -76,13 +76,8 @@ public override void VisitDocument(Document document) if (document.Attributes.All(a => a.Name != "ref_current")) { - _newDocument.Attributes.Add(new AttributeEntry("ref_current", $"https://www.elastic.co/guide/en/elasticsearch/reference/{Program.DocVersion}")); - } - - if (document.Attributes.All(a => a.Name != "xpack_current")) - { - _newDocument.Attributes.Add(new AttributeEntry("xpack_current", - $"https://www.elastic.co/guide/en/x-pack/{Program.DocVersion}")); + _newDocument.Attributes.Add(new AttributeEntry("ref_current", + $"https://www.elastic.co/guide/en/elasticsearch/reference/{Program.DocVersion}")); } var github = "https://github.com/elastic/elasticsearch-net"; @@ -103,13 +98,13 @@ public override void VisitDocument(Document document) { Style = CommentStyle.MultiLine, Text = $"IMPORTANT NOTE\r\n==============\r\nThis file has been generated from {originalFile}. \r\n" + - "If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file,\r\n" + - "please modify the original csharp file found at the link and submit the PR with that change. Thanks!" + "If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file,\r\n" + + "please modify the original csharp file found at the link and submit the PR with that change. Thanks!" }); _topSectionTitleLevel = _source.Directory.Name.Equals("request", StringComparison.OrdinalIgnoreCase) && - _source.Directory.Parent != null && - _source.Directory.Parent.Name.Equals("search", StringComparison.OrdinalIgnoreCase) + _source.Directory.Parent != null && + _source.Directory.Parent.Name.Equals("search", StringComparison.OrdinalIgnoreCase) ? 2 : 3; @@ -161,8 +156,8 @@ public override void VisitContainer(Container elements) continue; } - // if there is a section title since the last source block, don't add one - var lastSourceBlock = _newDocument.LastOrDefault(e => e is Source); + // if there is a section title since the last source block, don't add one + var lastSourceBlock = _newDocument.LastOrDefault(e => e is Source); var lastSectionTitle = _newDocument.OfType().LastOrDefault(e => e.Level == _topSectionTitleLevel + 1); if (lastSourceBlock != null && lastSectionTitle != null) { @@ -179,18 +174,20 @@ public override void VisitContainer(Container elements) { case "fluent": case "queryfluent": + case "fluentaggs": if (!LastSectionTitleMatches(text => text.StartsWith("Fluent DSL", StringComparison.OrdinalIgnoreCase))) { _newDocument.Add(CreateSubsectionTitle("Fluent DSL example")); } _newDocument.Add(source); - break; + break; case "initializer": - case "queryinitializer": - _newDocument.Add(CreateSubsectionTitle("Object Initializer syntax example")); + case "queryinitializer": + case "initializeraggs": + _newDocument.Add(CreateSubsectionTitle("Object Initializer syntax example")); _newDocument.Add(source); - break; + break; case "expectresponse": // Don't add the Handlng Response section title if it was the last title (it might be defined in the doc already) if (!LastSectionTitleMatches(text => text.Equals("Handling responses", StringComparison.OrdinalIgnoreCase))) @@ -250,8 +247,7 @@ public override void VisitSectionTitle(SectionTitle sectionTitle) { // Check for duplicate ids across documents var key = sectionTitle.Attributes.Anchor.Id; - string existingFile; - if (Ids.TryGetValue(key, out existingFile)) + if (Ids.TryGetValue(key, out var existingFile)) { throw new Exception($"duplicate id {key} in {_destination.FullName}. Id already exists in {existingFile}"); } @@ -262,85 +258,104 @@ public override void VisitSectionTitle(SectionTitle sectionTitle) base.VisitSectionTitle(sectionTitle); } - public override void VisitAttributeEntry(AttributeEntry attributeEntry) - { - if (attributeEntry.Name != "xml-docs") return; - - var value = attributeEntry.Value; - - if (string.IsNullOrEmpty(value)) - { - base.VisitAttributeEntry(attributeEntry); - return; - } - - var parts = value.Split(':'); - var assemblyName = parts[0]; - var typeName = parts[1]; - - string xmlDocsFile; - Assembly assembly; - string assemblyNamespace; - - //TODO: tidy this up - switch (assemblyName.ToLowerInvariant()) - { - case "elasticsearch.net": - xmlDocsFile = Path.GetFullPath(Path.Combine(Program.BuildOutputPath, "Elasticsearch.Net", "net46", "Elasticsearch.Net.XML")); - assembly = typeof(ElasticLowLevelClient).Assembly; - assemblyNamespace = typeof(ElasticLowLevelClient).Namespace; - break; - default: - xmlDocsFile = Path.GetFullPath(Path.Combine(Program.BuildOutputPath, "Nest", "net46", "Nest.XML")); - assembly = typeof(ElasticClient).Assembly; - assemblyNamespace = typeof(ElasticClient).Namespace; - break; - } - - // build xml documentation file on the fly if it doesn't exist - if (!File.Exists(xmlDocsFile)) - { - var project = _projects[assemblyName]; - var compilation = project.GetCompilationAsync().Result; - - using (var peStream = new MemoryStream()) - using (var commentStream = File.Create(xmlDocsFile)) - { - var emitResult = compilation.Emit(peStream, null, commentStream); - - if (!emitResult.Success) - { - var failures = emitResult.Diagnostics.Where(diagnostic => - diagnostic.IsWarningAsError || - diagnostic.Severity == DiagnosticSeverity.Error); - - var builder = new StringBuilder($"Unable to emit compilation for: {assemblyName}"); - foreach (var diagnostic in failures) - { - builder.AppendLine($"{diagnostic.Id}: {diagnostic.GetMessage()}"); - } - builder.AppendLine(new string('-', 30)); - - throw new Exception(builder.ToString()); - } - } - } - - var assemblyMembers = DocReader.Read(assembly, xmlDocsFile); - var type = assembly.GetType(assemblyNamespace + "." + typeName); - var visitor = new XmlDocsVisitor(type); - - visitor.VisitAssembly(assemblyMembers); - if (visitor.LabeledListItems.Any()) - { - var labeledList = new LabeledList(); - foreach (var item in visitor.LabeledListItems.OrderBy(l => l.Label)) - { - labeledList.Items.Add(item); - } - _newDocument.Insert(_newDocument.IndexOf(attributeEntry), labeledList); - } - } + public override void VisitAttributeEntry(AttributeEntry attributeEntry) + { + if (attributeEntry.Name != "xml-docs") return; + //true when running from the IDE, build/output might have not been created + string configuration = null; + if (Program.BuildOutputPath.Contains("src")) + { + //bin/Debug|Release/netcoreapp2.1 + configuration = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)).Parent?.Name; + return; + } + + string XmlFile(string project) + { + if (configuration == null) + return Path.Combine(Program.BuildOutputPath, project, "netstandard1.3", $"{project}.XML"); + return Path.Combine(Program.BuildOutputPath, project, "bin", configuration, "netstandard1.3", + $"{project}.XML"); + } + + var value = attributeEntry.Value; + + if (string.IsNullOrEmpty(value)) + { + base.VisitAttributeEntry(attributeEntry); + return; + } + + var parts = value.Split(':'); + var assemblyName = parts[0]; + var typeName = parts[1]; + + string xmlDocsFile; + Assembly assembly; + string assemblyNamespace; + + //TODO: tidy this up + switch (assemblyName.ToLowerInvariant()) + { + case "elasticsearch.net": + xmlDocsFile = Path.GetFullPath(XmlFile("Elasticsearch.Net")); + assembly = typeof(ElasticLowLevelClient).Assembly; + assemblyNamespace = typeof(ElasticLowLevelClient).Namespace; + break; + default: + xmlDocsFile = Path.GetFullPath(XmlFile("Nest")); + assembly = typeof(ElasticClient).Assembly; + assemblyNamespace = typeof(ElasticClient).Namespace; + break; + } + + // build xml documentation file on the fly if it doesn't exist + if (!File.Exists(xmlDocsFile)) + { + var project = _projects[assemblyName]; + + var compilation = project.GetCompilationAsync().Result; + + using (var peStream = new MemoryStream()) + using (var commentStream = File.Create(xmlDocsFile)) + { + var emitResult = compilation.Emit(peStream, null, commentStream); + + if (!emitResult.Success) + { + var failures = emitResult.Diagnostics.Where(diagnostic => + diagnostic.IsWarningAsError || + diagnostic.Severity == DiagnosticSeverity.Error); + + var builder = new StringBuilder($"Unable to emit compilation for: {assemblyName}"); + foreach (var diagnostic in failures) + { + builder.AppendLine($"{diagnostic.Id}: {diagnostic.GetMessage()}"); + } + + builder.AppendLine(new string('-', 30)); + + throw new Exception(builder.ToString()); + } + } + } + + var assemblyMembers = DocReader.Read(assembly, xmlDocsFile); + var type = assembly.GetType(assemblyNamespace + "." + typeName); + var visitor = new XmlDocsVisitor(type); + + visitor.VisitAssembly(assemblyMembers); + if (visitor.LabeledListItems.Any()) + { + var labeledList = new LabeledList(); + foreach (var item in visitor.LabeledListItems.OrderBy(l => l.Label)) + { + labeledList.Items.Add(item); + } + + _newDocument.Insert(_newDocument.IndexOf(attributeEntry), labeledList); + } + } private void RemoveDocDirectoryAttribute(Document document) { @@ -373,8 +388,8 @@ private SectionTitle CreateSubsectionTitle(string title) var level = _topSectionTitleLevel + 1; var sectionTitle = new SectionTitle(title, level); - // levels 1-3 need to be floating so the Elasticsearch docs generation does not - // split into separate file + // levels 1-3 need to be floating so the Elasticsearch docs generation does not + // split into separate file if (level < 4) sectionTitle.IsFloating = true; diff --git a/src/CodeGeneration/DocGenerator/AsciiDoc/RawAsciidocVisitor.cs b/src/CodeGeneration/DocGenerator/AsciiDoc/RawAsciidocVisitor.cs index d1a6b408498..cb2886825af 100644 --- a/src/CodeGeneration/DocGenerator/AsciiDoc/RawAsciidocVisitor.cs +++ b/src/CodeGeneration/DocGenerator/AsciiDoc/RawAsciidocVisitor.cs @@ -33,7 +33,7 @@ public override void VisitDocument(Document document) } var github = "https://github.com/elastic/elasticsearch-net"; - var originalFile = Regex.Replace(_source.FullName.Replace("\\", "/"), @"^(.*Tests/)", $"{github}/tree/5.x/src/Tests/"); + var originalFile = Regex.Replace(_source.FullName.Replace("\\", "/"), @"^(.*Tests/)", $"{github}/tree/master/src/Tests/"); document.Insert(0, new Comment { Style = CommentStyle.MultiLine, diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManager.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManager.cs index 21d094be22b..9ac58dbc13e 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManager.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/AnalyzerManager.cs @@ -47,7 +47,7 @@ public class AnalyzerManager public string SolutionDirectory { get; } public AnalyzerManager(ILoggerFactory loggerFactory = null, LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal) - : this(null, loggerFactory, loggerVerbosity) + : this(null, null, loggerFactory, loggerVerbosity) { } @@ -56,7 +56,7 @@ public AnalyzerManager(TextWriter logWriter, LoggerVerbosity loggerVerbosity = L { } - public AnalyzerManager(string solutionFilePath, ILoggerFactory loggerFactory = null, LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal) + public AnalyzerManager(string solutionFilePath, string[] projects, ILoggerFactory loggerFactory = null, LoggerVerbosity loggerVerbosity = LoggerVerbosity.Normal) { LoggerVerbosity = loggerVerbosity; ProjectLogger = loggerFactory?.CreateLogger(); @@ -65,7 +65,7 @@ public AnalyzerManager(string solutionFilePath, ILoggerFactory loggerFactory = n { solutionFilePath = ValidatePath(solutionFilePath, true); SolutionDirectory = Path.GetDirectoryName(solutionFilePath); - GetProjectsInSolution(solutionFilePath); + GetProjectsInSolution(solutionFilePath, projects); } } @@ -87,8 +87,9 @@ public AnalyzerManager(string solutionFilePath, TextWriter logWriter, LoggerVerb } } - private void GetProjectsInSolution(string solutionFilePath) + private void GetProjectsInSolution(string solutionFilePath, string[] projects = null) { + projects = projects ?? new string[] { }; var supportedType = new[] { SolutionProjectType.KnownToBeMSBuildFormat, @@ -98,8 +99,8 @@ private void GetProjectsInSolution(string solutionFilePath) SolutionFile solution = SolutionFile.Parse(solutionFilePath); foreach(ProjectInSolution project in solution.ProjectsInOrder) { - if (!supportedType.Contains(project.ProjectType)) - continue; + if (!supportedType.Contains(project.ProjectType)) continue; + if (projects.Length > 0 && !projects.Contains(project.ProjectName)) continue; GetProject(project.AbsolutePath); } } diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/DotnetPathResolver.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/DotnetPathResolver.cs index b13318a1646..a89a5448499 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/DotnetPathResolver.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/Environment/DotnetPathResolver.cs @@ -88,7 +88,7 @@ private static List GetInfo(string projectPath) sw.Start(); while (!process.HasExited) { - if (sw.ElapsedMilliseconds > 1000) + if (sw.ElapsedMilliseconds > 4000) { break; } diff --git a/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzer.cs b/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzer.cs index 1788286b14c..29e93a73776 100644 --- a/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzer.cs +++ b/src/CodeGeneration/DocGenerator/Buildalyzer/ProjectAnalyzer.cs @@ -72,7 +72,8 @@ internal ProjectAnalyzer(AnalyzerManager manager, string projectFilePath, XDocum { Manager = manager; ProjectFilePath = projectFilePath; - _projectDocument = TweakProjectDocument(projectDocument); + var projectFolder = Path.GetDirectoryName(projectFilePath); + _projectDocument = TweakProjectDocument(projectDocument, projectFolder); // Get the paths _buildEnvironment = EnvironmentFactory.GetBuildEnvironment(projectFilePath, _projectDocument); @@ -80,8 +81,8 @@ internal ProjectAnalyzer(AnalyzerManager manager, string projectFilePath, XDocum // Preload/enforce referencing some required asemblies Copy copy = new Copy(); - // Set global properties - string solutionDir = manager.SolutionDirectory ?? Path.GetDirectoryName(projectFilePath); + + string solutionDir = manager.SolutionDirectory ?? projectFolder; _globalProperties = _buildEnvironment.GetGlobalProperties(solutionDir); // Create the logger @@ -119,8 +120,19 @@ public Project Load() } // Tweaks the project file a bit to ensure a succesfull build - private static XDocument TweakProjectDocument(XDocument projectDocument) + private static XDocument TweakProjectDocument(XDocument projectDocument, string projectFolder) { + foreach (XElement import in projectDocument.GetDescendants("Import").ToArray()) + { + var att = import.Attribute("Project"); + if (att == null) continue; + + var project = att.Value; + if (project.EndsWith("Clients.Common.targets")) + att.Value = Path.GetFullPath(Path.Combine(projectFolder, att.Value)); + else if (project.EndsWith("outputpath.props")) + att.Value = Path.GetFullPath(Path.Combine(projectFolder, att.Value)); + } // Add SkipGetTargetFrameworkProperties to every ProjectReference foreach (XElement projectReference in projectDocument.GetDescendants("ProjectReference").ToArray()) { diff --git a/src/CodeGeneration/DocGenerator/DocGenerator.csproj b/src/CodeGeneration/DocGenerator/DocGenerator.csproj index c3d526c535b..7e355306eda 100644 --- a/src/CodeGeneration/DocGenerator/DocGenerator.csproj +++ b/src/CodeGeneration/DocGenerator/DocGenerator.csproj @@ -1,28 +1,21 @@  - Exe - net46 + netcoreapp2.1 6.0.0 alpha + NU1701,NU1605 - + + + - - + - - - - - - - \ No newline at end of file diff --git a/src/CodeGeneration/DocGenerator/Documentation/Files/DocumentationFile.cs b/src/CodeGeneration/DocGenerator/Documentation/Files/DocumentationFile.cs index e0701757667..7e920e9e567 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Files/DocumentationFile.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Files/DocumentationFile.cs @@ -41,9 +41,9 @@ public static DocumentationFile Load(FileInfo fileLocation) protected virtual FileInfo CreateDocumentationLocation() { var testFullPath = this.FileLocation.FullName; - + var p = "\\" + Path.DirectorySeparatorChar.ToString(); var testInDocumentationFolder = - Regex.Replace(testFullPath, @"(^.+\\Tests\\|\" + this.Extension + "$)", "") + Regex.Replace(testFullPath, $@"(^.+{p}Tests{p}|\" + this.Extension + "$)", "") .TrimEnd(".doc") .TrimEnd("Tests") .PascalToHyphen() + ".asciidoc"; diff --git a/src/CodeGeneration/DocGenerator/Documentation/Files/ImageDocumentationFile.cs b/src/CodeGeneration/DocGenerator/Documentation/Files/ImageDocumentationFile.cs index d842de6dd04..f43997f2bae 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Files/ImageDocumentationFile.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Files/ImageDocumentationFile.cs @@ -26,7 +26,8 @@ protected override FileInfo CreateDocumentationLocation() { var testFullPath = this.FileLocation.FullName; - var testInDocumenationFolder = Regex.Replace(testFullPath, @"(^.+\\Tests\\|\" + this.Extension + "$)", "") + var p = "\\" + Path.DirectorySeparatorChar.ToString(); + var testInDocumenationFolder = Regex.Replace(testFullPath, $@"(^.+{p}Tests{p}|\" + this.Extension + "$)", "") .PascalToHyphen() + this.Extension; var documentationTargetPath = Path.GetFullPath(Path.Combine(Program.OutputDirPath, testInDocumenationFolder)); diff --git a/src/CodeGeneration/DocGenerator/Documentation/Files/RawDocumentationFile.cs b/src/CodeGeneration/DocGenerator/Documentation/Files/RawDocumentationFile.cs index 6f06e64ae2e..cfd8e960a48 100644 --- a/src/CodeGeneration/DocGenerator/Documentation/Files/RawDocumentationFile.cs +++ b/src/CodeGeneration/DocGenerator/Documentation/Files/RawDocumentationFile.cs @@ -32,7 +32,8 @@ public override Task SaveToDocumentationFolderAsync() protected override FileInfo CreateDocumentationLocation() { var testFullPath = this.FileLocation.FullName; - var testInDocumenationFolder = Regex.Replace(testFullPath, @"(^.+\\Tests\\|\" + this.Extension + "$)", "").PascalToHyphen() + this.Extension; + var p = "\\" + Path.DirectorySeparatorChar.ToString(); + var testInDocumenationFolder = Regex.Replace(testFullPath, $@"(^.+{p}Tests{p}|\" + this.Extension + "$)", "").PascalToHyphen() + this.Extension; var documenationTargetPath = Path.GetFullPath(Path.Combine(Program.OutputDirPath, testInDocumenationFolder)); var fileInfo = new FileInfo(documenationTargetPath); diff --git a/src/CodeGeneration/DocGenerator/LitUp.cs b/src/CodeGeneration/DocGenerator/LitUp.cs index 6acb81ef5a8..a2e5772f05d 100644 --- a/src/CodeGeneration/DocGenerator/LitUp.cs +++ b/src/CodeGeneration/DocGenerator/LitUp.cs @@ -8,19 +8,18 @@ using DocGenerator.Documentation.Files; using Microsoft.Build.Framework; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.MSBuild; using Microsoft.Extensions.Logging; namespace DocGenerator { public static class LitUp { - private static readonly string[] SkipFolders = { "Debug", "Release" }; + private static readonly string[] SkipFolders = {"Debug", "Release"}; - private static string GetProjectDir(string projectName) => Path.Combine(Program.InputDirPath, projectName); - private static string GetProjectFile(string projectName) => Path.Combine(GetProjectDir(projectName), $"{projectName}.csproj"); + private static string GetProjectDir(string projectName) => Path.Combine(Program.InputDirPath, projectName); + private static string GetProjectFile(string projectName) => Path.Combine(GetProjectDir(projectName), $"{projectName}.csproj"); - public static IEnumerable InputFiles(string path) => + public static IEnumerable InputFiles(string path) => from f in Directory.GetFiles(GetProjectDir("Tests"), $"{path}", SearchOption.AllDirectories) let dir = new DirectoryInfo(f) where dir?.Parent != null && !SkipFolders.Contains(dir.Parent.Name) @@ -28,11 +27,11 @@ from f in Directory.GetFiles(GetProjectDir("Tests"), $"{path}", SearchOption.All public static IEnumerable> GetDocumentFiles(Dictionary projects) { - var testProject = projects["Tests"]; + var testProject = projects["Tests"]; yield return testProject.Documents - .Where(d => d.Name.EndsWith(".doc.cs", StringComparison.OrdinalIgnoreCase)) - .Select(d => new CSharpDocumentationFile(d, projects)); + .Where(d => d.Name.EndsWith(".doc.cs", StringComparison.OrdinalIgnoreCase)) + .Select(d => new CSharpDocumentationFile(d, projects)); yield return testProject.Documents .Where(d => d.Name.EndsWith("UsageTests.cs", StringComparison.OrdinalIgnoreCase)) @@ -44,29 +43,32 @@ public static IEnumerable> GetDocumentFiles(Dicti // process asciidocs last as they may have generated // includes to other output asciidocs yield return InputFiles("*.asciidoc"); - } + } public static async Task GoAsync(string[] args) { //.NET core csprojects are not supported all that well. // https://github.com/dotnet/roslyn/issues/21660 :sadpanda: // Use Buildalyzer to get a workspace from the solution. - var analyzer = new AnalyzerManager(Path.Combine(Program.InputDirPath, "Elasticsearch.DotNetCoreOnly.sln")); + var analyzer = new AnalyzerManager(Path.Combine(Program.InputDirPath, "Elasticsearch.sln"), new[] + { + "Elasticsearch.Net", + "Nest", + "Tests" + }); + var workspace = analyzer.GetWorkspace(); - workspace.WorkspaceFailed += (s, e) => - { - Console.Error.WriteLine(e.Diagnostic.Message); - }; + workspace.WorkspaceFailed += (s, e) => { Console.Error.WriteLine(e.Diagnostic.Message); }; // Buildalyzer, similar to MsBuildWorkspace with the new csproj file format, does // not pick up source documents in the project directory. Manually add them AddDocumentsToWorkspace(workspace); - var projects = workspace.CurrentSolution.Projects - .ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase); + var projects = workspace.CurrentSolution.Projects + .ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase); - foreach (var file in GetDocumentFiles(projects).SelectMany(s => s)) + foreach (var file in GetDocumentFiles(projects).SelectMany(s => s)) { await file.SaveToDocumentationFolderAsync(); } diff --git a/src/CodeGeneration/DocGenerator/Program.cs b/src/CodeGeneration/DocGenerator/Program.cs index d0232039421..c82c8a9c39a 100644 --- a/src/CodeGeneration/DocGenerator/Program.cs +++ b/src/CodeGeneration/DocGenerator/Program.cs @@ -8,18 +8,25 @@ public static class Program { static Program() { + string P(string path) + { + return path.Replace(@"\", Path.DirectorySeparatorChar.ToString()); + } + var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory()); if (currentDirectory.Name == "DocGenerator" && currentDirectory.Parent.Name == "CodeGeneration") { - InputDirPath = @"..\..\"; - OutputDirPath = @"..\..\..\docs"; - BuildOutputPath = @"..\..\..\build\output"; + Console.WriteLine("IDE: " + currentDirectory); + InputDirPath = P(@"..\..\"); + OutputDirPath = P(@"..\..\..\docs"); + BuildOutputPath = P(@"..\..\..\src"); } else { - InputDirPath = @"..\..\..\..\..\src"; - OutputDirPath = @"..\..\..\..\..\docs"; - BuildOutputPath = @"..\..\..\..\..\build\output"; + Console.WriteLine("CMD: " + currentDirectory); + InputDirPath = P(@"..\..\..\..\src"); + OutputDirPath = P(@"..\..\..\..\docs"); + BuildOutputPath = P(@"..\..\..\..\build\output"); } var process = new Process @@ -39,13 +46,11 @@ static Program() { process.Start(); BranchName = process.StandardOutput.ReadToEnd().Trim(); - Console.WriteLine($"Using branch name {BranchName} in documentation"); process.WaitForExit(); } catch (Exception) { BranchName = "master"; - Console.WriteLine($"Could not get the git branch name. Assuming {BranchName}"); } finally { @@ -59,7 +64,7 @@ static Program() public static string OutputDirPath { get; } - public static string BranchName { get; } + public static string BranchName { get; set; } public static string DocVersion => "5.6"; @@ -67,6 +72,11 @@ static int Main(string[] args) { try { + if (args.Length > 0) + BranchName = args[0]; + + Console.WriteLine($"Using branch name {BranchName} in documentation"); + LitUp.GoAsync(args).Wait(); return 0; } diff --git a/src/CodeGeneration/DocGenerator/StringExtensions.cs b/src/CodeGeneration/DocGenerator/StringExtensions.cs index 6997130990e..1cfdd262efd 100644 --- a/src/CodeGeneration/DocGenerator/StringExtensions.cs +++ b/src/CodeGeneration/DocGenerator/StringExtensions.cs @@ -195,13 +195,26 @@ public string Write() var syntaxTree = CSharpSyntaxTree.ParseText(text); var assemblyName = Path.GetRandomFileName(); - var references = new MetadataReference[] + var references = new List { MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location), MetadataReference.CreateFromFile(typeof(Enumerable).GetTypeInfo().Assembly.Location), MetadataReference.CreateFromFile(typeof(JsonConvert).GetTypeInfo().Assembly.Location), MetadataReference.CreateFromFile(typeof(ITypedList).GetTypeInfo().Assembly.Location), }; + var systemReferences = new string[] + { + "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", + "System.ObjectModel, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", + "System.Dynamic.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", + "System.Linq.Expressions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", + "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" + }; + foreach (var r in systemReferences) + { + var location = Assembly.Load(r).Location; + references.Add(MetadataReference.CreateFromFile(location)); + } var compilation = CSharpCompilation.Create( diff --git a/src/CodeGeneration/DocGenerator/Walkers/UsageTestsWalker.cs b/src/CodeGeneration/DocGenerator/Walkers/UsageTestsWalker.cs index 42fbf904b27..ced0f8ccd47 100644 --- a/src/CodeGeneration/DocGenerator/Walkers/UsageTestsWalker.cs +++ b/src/CodeGeneration/DocGenerator/Walkers/UsageTestsWalker.cs @@ -15,16 +15,20 @@ public UsageTestsWalker(IList blocks) : base(blocks) private static readonly string[] ConvertToJson = { "ExpectJson", "QueryJson", + "AggregationJson" }; private static readonly string[] MembersOfInterest = { "ExpectJson", "QueryJson", + "AggregationJson", "Fluent", "Initializer", "QueryFluent", "QueryInitializer", - "ExpectResponse" + "ExpectResponse", + "FluentAggs", + "InitializerAggs" }; public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node) @@ -46,19 +50,17 @@ public override void VisitMethodDeclaration(MethodDeclarationSyntax node) protected override bool SerializePropertyDeclarationToJson(PropertyDeclarationSyntax node) => SerializeToJson(node, node.Identifier.Text); - protected override bool SerializeMethodDeclarationToJson(MethodDeclarationSyntax node) => + protected override bool SerializeMethodDeclarationToJson(MethodDeclarationSyntax node) => SerializeToJson(node, node.Identifier.Text); private bool SerializeToJson(SyntaxNode node, string memberName) { if (!ConvertToJson.Contains(memberName)) return false; - string json; - if (node.TryGetJsonForSyntaxNode(out json)) + if (node.TryGetJsonForSyntaxNode(out var json)) { var startingLine = node.StartingLine(); Blocks.Add(new JavaScriptBlock(json, startingLine, ClassDepth, memberName)); - return true; } return true; diff --git a/src/Elasticsearch.DotNetCoreOnly.sln b/src/Elasticsearch.DotNetCoreOnly.sln deleted file mode 100644 index 276f2aba624..00000000000 --- a/src/Elasticsearch.DotNetCoreOnly.sln +++ /dev/null @@ -1,33 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26403.7 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nest", "Nest\Nest.csproj", "{072BA7DA-7B60-407D-8B6E-95E3186BE70C}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elasticsearch.Net", "Elasticsearch.Net\Elasticsearch.Net.csproj", "{E97CCF40-0BA6-43FE-9F2D-58D454134088}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{37164C11-88EF-4428-803A-9AA24FB8B44D}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {072BA7DA-7B60-407D-8B6E-95E3186BE70C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {072BA7DA-7B60-407D-8B6E-95E3186BE70C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {072BA7DA-7B60-407D-8B6E-95E3186BE70C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {072BA7DA-7B60-407D-8B6E-95E3186BE70C}.Release|Any CPU.Build.0 = Release|Any CPU - {E97CCF40-0BA6-43FE-9F2D-58D454134088}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E97CCF40-0BA6-43FE-9F2D-58D454134088}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E97CCF40-0BA6-43FE-9F2D-58D454134088}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E97CCF40-0BA6-43FE-9F2D-58D454134088}.Release|Any CPU.Build.0 = Release|Any CPU - {37164C11-88EF-4428-803A-9AA24FB8B44D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {37164C11-88EF-4428-803A-9AA24FB8B44D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {37164C11-88EF-4428-803A-9AA24FB8B44D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {37164C11-88EF-4428-803A-9AA24FB8B44D}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/Elasticsearch.Net/ConnectionPool/Node.cs b/src/Elasticsearch.Net/ConnectionPool/Node.cs index f883f0d9daa..c903bbc4235 100644 --- a/src/Elasticsearch.Net/ConnectionPool/Node.cs +++ b/src/Elasticsearch.Net/ConnectionPool/Node.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using Purify; namespace Elasticsearch.Net { @@ -13,7 +12,7 @@ public Node(Uri uri) //http://my-saas-provider.com/instance if (!uri.OriginalString.EndsWith("/", StringComparison.Ordinal)) uri = new Uri(uri.OriginalString + "/"); - this.Uri = uri.Purify(); + this.Uri = uri; this.IsAlive = true; this.HoldsData = true; this.MasterEligible = true; @@ -74,7 +73,7 @@ public void MarkAlive() this.DeadUntil = default(DateTime); } - public Uri CreatePath(string path) => new Uri(this.Uri, path).Purify(); + public Uri CreatePath(string path) => new Uri(this.Uri, path); public Node Clone() => new Node(this.Uri) diff --git a/src/Elasticsearch.Net/CrossPlatform/FormattableString.cs b/src/Elasticsearch.Net/CrossPlatform/FormattableString.cs deleted file mode 100644 index 413558e1f31..00000000000 --- a/src/Elasticsearch.Net/CrossPlatform/FormattableString.cs +++ /dev/null @@ -1,38 +0,0 @@ -#if NET45 -namespace System.Runtime.CompilerServices -{ - internal class FormattableStringFactory - { - public static FormattableString Create(string messageFormat, params object[] args) - { - return new FormattableString(messageFormat, args); - } - - public static FormattableString Create(string messageFormat, DateTime bad, params object[] args) - { - var realArgs = new object[args.Length + 1]; - realArgs[0] = "Please don't use DateTime"; - Array.Copy(args, 0, realArgs, 1, args.Length); - return new FormattableString(messageFormat, realArgs); - } - } -} - -namespace System -{ - internal class FormattableString - { - private readonly string _messageFormat; - private readonly object[] _args; - - public FormattableString(string messageFormat, object[] args) - { - this._messageFormat = messageFormat; - this._args = args; - } - public override string ToString() => string.Format(_messageFormat, _args); - - public string ToString(IFormatProvider formatProvider) => string.Format(formatProvider, _messageFormat, _args); - } -} -#endif diff --git a/src/Elasticsearch.Net/Purify/Purify.cs b/src/Elasticsearch.Net/Purify/Purify.cs deleted file mode 100644 index 7d14dd3eeea..00000000000 --- a/src/Elasticsearch.Net/Purify/Purify.cs +++ /dev/null @@ -1,207 +0,0 @@ -using System; -using System.Globalization; -using System.Reflection; - -namespace Purify -{ - -#if DOTNETCORE - public static class Purifier - { - public static Uri Purify(this Uri uri) => uri; - } -#else - /// - /// The Uri classes in .NET prior to 4.5 and Mono scrub through your Uris and modify them in order to prevent vulnerabilities, for - /// example escaped slashes are unescaped. This scrubbing however prevents Uris that are inline with RFC 3986. Beyond that it prevents - /// using .NET's HTTP clients (HttpClient and WebClient) to talk to APIs that require accessing resources using escaped - /// slashes unless you are using .NET 4.5. - ///
-	/// This static class allows you to purify a Uri instance so that it remains untouched across all .NET runtime versions
-	/// 
- ///
- public static class Purifier - { - - private static readonly bool hasBrokenDotNetUri; - - private static readonly bool isMono; - - static Purifier() - { - isMono = typeof(Uri).GetField("m_Flags", BindingFlags.Instance | BindingFlags.NonPublic) == null; - if (isMono) - return; - - //ShouldUseLegacyV2Quirks was introduced in .net 4.5 - //Eventhough 4.5 is an inplace update of 4.0 this call will return - //a different value if an application specifically targets 4.0 or 4.5+ - var legacyV2Quirks = typeof(UriParser).GetProperty("ShouldUseLegacyV2Quirks", BindingFlags.Static | BindingFlags.NonPublic); - if (legacyV2Quirks == null) - { - hasBrokenDotNetUri = true; //neither 4.0 or 4.5 - return; - } - var isBrokenUri = (bool)legacyV2Quirks.GetValue(null, null); - if (!isBrokenUri) - return; //application targets 4.5 - - //4.0 uses legacyV2quirks on the UriParser but you can set - // - // - // - // - // - // - // this will fix AbsoluteUri but not ToString() - // - // i.e new Uri("http://google.com/%2F").AbsoluteUri - // will return the url untouched but: - // new Uri("http://google.com/%2F").ToString() - // will still return http://google.com// - // - // so instead of using reflection perform a one off functional test. - - hasBrokenDotNetUri = !new Uri("http://google.com/%2F") - .ToString() - .EndsWith("%2F", StringComparison.InvariantCulture); - } - - /// - /// Will purify the to the unscrubed version. - ///
Calling this will be a NOOP on .NET 4.5 and up.
- ///
- /// The uri to be purified - /// The purified uri - public static Uri Purify(this Uri uri) - { - IPurifier purifier = null; - if (isMono) - purifier = new PurifierMono(); - else if (hasBrokenDotNetUri) - purifier = new PurifierDotNet(); - else return uri; - - return purifier.Purify(uri); - } - - private interface IPurifier - { - /// - /// purifies and returns the passed - /// - Uri Purify(Uri uri); - } - - private class PurifierDotNet : IPurifier - { - private static FieldInfo flagsField; - private static FieldInfo infoField; - private static FieldInfo stringField; - private static FieldInfo infoStringField; - private static FieldInfo moreInfoField; - private static FieldInfo moreInfoAbsoluteUri; - private static FieldInfo moreInfoPath; - private static FieldInfo moreInfoQuery; - - static PurifierDotNet() - { - var uriType = typeof(Uri); - flagsField = uriType.GetField("m_Flags", BindingFlags.NonPublic | BindingFlags.Instance); - stringField = uriType.GetField("m_String", BindingFlags.NonPublic | BindingFlags.Instance); - infoField = uriType.GetField("m_Info", BindingFlags.NonPublic | BindingFlags.Instance); - var infoFieldType = infoField.FieldType; - infoStringField = infoFieldType.GetField("String", BindingFlags.Public | BindingFlags.Instance); - moreInfoField = infoFieldType.GetField("MoreInfo", BindingFlags.Public | BindingFlags.Instance); - var moreInfoType = moreInfoField.FieldType; - moreInfoAbsoluteUri = moreInfoType.GetField("AbsoluteUri", BindingFlags.Public | BindingFlags.Instance); - moreInfoQuery = moreInfoType.GetField("Query", BindingFlags.Public | BindingFlags.Instance); - moreInfoPath = moreInfoType.GetField("Path", BindingFlags.Public | BindingFlags.Instance); - } - - //Code inspired by Rasmus Faber's solution in this post: http://stackoverflow.com/questions/781205/getting-a-url-with-an-url-encoded-slash - public Uri Purify(Uri uri) - { - string paq = uri.PathAndQuery; // need to access PathAndQuery - var abs = uri.AbsoluteUri; //need to access this as well the MoreInfo prop is initialized. - ulong flags = (ulong)flagsField.GetValue(uri); - flags &= ~((ulong)0x30); // Flags.PathNotCanonical|Flags.QueryNotCanonical - flagsField.SetValue(uri, flags); - object info = infoField.GetValue(uri); - var source = (string)stringField.GetValue(uri); - infoStringField.SetValue(info, source); - object moreInfo = moreInfoField.GetValue(info); - moreInfoAbsoluteUri.SetValue(moreInfo, source); - var uriInfo = new UriInfo(uri, source); - moreInfoPath.SetValue(moreInfo, uriInfo.Path); - moreInfoQuery.SetValue(moreInfo, uriInfo.Query); - return uri; - } - } - - private class PurifierMono : IPurifier - { - private static Type uriType = typeof(Uri); - private static FieldInfo mono_sourceField; - private static FieldInfo mono_queryField; - private static FieldInfo mono_pathField; - private static FieldInfo mono_cachedToStringField; - private static FieldInfo mono_cachedAbsoluteUriField; - - static PurifierMono() - { - mono_sourceField = uriType.GetField("source", BindingFlags.NonPublic | BindingFlags.Instance); - mono_queryField = uriType.GetField("query", BindingFlags.NonPublic | BindingFlags.Instance); - mono_pathField = uriType.GetField("path", BindingFlags.NonPublic | BindingFlags.Instance); - mono_cachedToStringField = uriType.GetField("cachedToString", BindingFlags.NonPublic | BindingFlags.Instance); - mono_cachedAbsoluteUriField = uriType.GetField("cachedAbsoluteUri", - BindingFlags.NonPublic | BindingFlags.Instance); - } - - public Uri Purify(Uri uri) - { - var source = (string)mono_sourceField.GetValue(uri); - mono_cachedToStringField.SetValue(uri, source ?? string.Empty); - mono_cachedAbsoluteUriField.SetValue(uri, source ?? string.Empty); - var uriInfo = new UriInfo(uri, source); - mono_pathField.SetValue(uri, uriInfo.Path ?? string.Empty); - mono_queryField.SetValue(uri, uriInfo.Query ?? string.Empty); - return uri; - } - } - - /// - /// Class that breaks a Uri into path and query components given its orignal source - /// - private class UriInfo - { - public string Path { get; private set; } - public string Query { get; private set; } - - public UriInfo(Uri uri, string source) - { - var fragPos = source.IndexOf("#", StringComparison.Ordinal); - var queryPos = source.IndexOf("?", StringComparison.Ordinal); - var start = source.IndexOf(uri.Host, StringComparison.Ordinal) + uri.Host.Length; - var pathEnd = queryPos == -1 ? fragPos : queryPos; - if (pathEnd == -1) - pathEnd = source.Length + 1; - - if (start < pathEnd - 1 && source[start] == ':') - { - var portLength = uri.Port.ToString().Length; - start += portLength + 1; - } - - Path = queryPos > -1 ? source.Substring(start, pathEnd - start) : source.Substring(start); - Query = fragPos > -1 - ? source.Substring(queryPos, fragPos - queryPos) - : queryPos > -1 - ? source.Substring(queryPos, (source.Length - queryPos)) - : null; - } - } - } - -#endif -} diff --git a/src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs b/src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs index 1d635b540b6..8d68c89ad63 100644 --- a/src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs +++ b/src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using System.Security.Cryptography.X509Certificates; -using Purify; namespace Elasticsearch.Net { @@ -13,7 +12,7 @@ public class RequestData public const string MimeType = "application/json"; public const string RunAsSecurityHeader = "es-security-runas-user"; - public Uri Uri => this.Node != null ? new Uri(this.Node.Uri, this.Path).Purify() : null; + public Uri Uri => this.Node != null ? new Uri(this.Node.Uri, this.Path) : null; public HttpMethod Method { get; private set; } public string Path { get; } @@ -109,7 +108,7 @@ private string CreatePathWithQueryStrings(string path, IConnectionConfigurationV if (!copy.HasKeys()) return path; var queryString = copy.ToQueryString(); - var tempUri = new Uri("http://localhost:9200/" + path).Purify(); + var tempUri = new Uri("http://localhost:9200/" + path); if (tempUri.Query.IsNullOrEmpty()) path += queryString; else diff --git a/src/Elasticsearch.sln b/src/Elasticsearch.sln index 9ac80e56eab..307e2d514b5 100644 --- a/src/Elasticsearch.sln +++ b/src/Elasticsearch.sln @@ -23,6 +23,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Build", "_Build", "{432D55 ..\paket.bat = ..\paket.bat ..\paket.dependencies = ..\paket.dependencies ..\readme.md = ..\readme.md + outputpath.props = outputpath.props EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CodeGeneration", "CodeGeneration", "{93331BEE-0AA0-47B7-B1D2-BD5BD31634D1}" diff --git a/src/Nest/CrossPlatform/TypeExtensions.cs b/src/Nest/CrossPlatform/TypeExtensions.cs index 00763025afc..4dc4c718ef7 100644 --- a/src/Nest/CrossPlatform/TypeExtensions.cs +++ b/src/Nest/CrossPlatform/TypeExtensions.cs @@ -17,6 +17,15 @@ internal static bool IsGeneric(this Type type) #endif } + internal static Assembly Assembly(this Type type) + { +#if DOTNETCORE + return type.GetTypeInfo().Assembly; +#else + return type.Assembly; +#endif + } + internal static bool IsGenericDictionary(this Type type) { return type.GetInterfaces().Any(t => diff --git a/src/Tests/ClientConcepts/Certificates/WorkingWithCertificates.doc.cs b/src/Tests/ClientConcepts/Certificates/WorkingWithCertificates.doc.cs index 0f4601a8d55..488e92a3327 100644 --- a/src/Tests/ClientConcepts/Certificates/WorkingWithCertificates.doc.cs +++ b/src/Tests/ClientConcepts/Certificates/WorkingWithCertificates.doc.cs @@ -174,7 +174,7 @@ protected override void AssertHttpRequestException(HttpRequestException e) * the local CA certificate is part of the chain that was used to generate the servers key. */ -#if !DOTNETCORE +#if FEATURE_HTTPWEBREQUEST /** * ==== Client Certificates * @@ -227,7 +227,7 @@ public PkiApiTests(PkiCluster cluster, EndpointUsage usage) : base(cluster, usag #endif } -#if !DOTNETCORE +#if FEATURE_HTTPWEBREQUEST /** * Or per request on `RequestConfiguration` which will take precedence over the ones defined on `ConnectionConfiguration` */ diff --git a/src/Tests/ClientConcepts/Connection/ModifyingDefaultConnection.doc.cs b/src/Tests/ClientConcepts/Connection/ModifyingDefaultConnection.doc.cs index aee16bbfa54..b612e6e9ab2 100644 --- a/src/Tests/ClientConcepts/Connection/ModifyingDefaultConnection.doc.cs +++ b/src/Tests/ClientConcepts/Connection/ModifyingDefaultConnection.doc.cs @@ -122,7 +122,7 @@ public void InMemoryConnectionOverloadedCtor() * If you are running on the Desktop CLR you can override specific properties for the current `ServicePoint` easily * by overriding `AlterServicePoint` on an `IConnection` implementation deriving from `HttpConnection` */ -#if !DOTNETCORE +#if FEATURE_HTTPWEBREQUEST public class MyCustomHttpConnection : HttpConnection { protected override void AlterServicePoint(ServicePoint requestServicePoint, RequestData requestData) diff --git a/src/Tests/ClientConcepts/HighLevel/Inference/FieldInference.doc.cs b/src/Tests/ClientConcepts/HighLevel/Inference/FieldInference.doc.cs index 5cc8ada76f6..cc40c4b9782 100644 --- a/src/Tests/ClientConcepts/HighLevel/Inference/FieldInference.doc.cs +++ b/src/Tests/ClientConcepts/HighLevel/Inference/FieldInference.doc.cs @@ -444,6 +444,7 @@ public override IPropertyMapping CreatePropertyMapping(MemberInfo memberInfo) } [U] + [ProjectReferenceOnly] public void PrecedenceIsAsExpected() { /** Here we provide an explicit rename of a property on `ConnectionSettings` using `.Rename()` diff --git a/src/Tests/Document/Multiple/ReindexOnServer/ReindexOnServerRemoteApiTests.cs b/src/Tests/Document/Multiple/ReindexOnServer/ReindexOnServerRemoteApiTests.cs index aa8e436259a..0a4f2028024 100644 --- a/src/Tests/Document/Multiple/ReindexOnServer/ReindexOnServerRemoteApiTests.cs +++ b/src/Tests/Document/Multiple/ReindexOnServer/ReindexOnServerRemoteApiTests.cs @@ -5,7 +5,6 @@ using Elasticsearch.Net; using FluentAssertions; using Nest; -using Purify; using Tests.Framework; using Tests.Framework.Integration; using Tests.Framework.ManagedElasticsearch.Clusters; diff --git a/src/Tests/Framework/Benchmarks/BenchmarkConfig.cs b/src/Tests/Framework/Benchmarks/BenchmarkConfig.cs index f565f82ad4c..8d8d4d6dda2 100644 --- a/src/Tests/Framework/Benchmarks/BenchmarkConfig.cs +++ b/src/Tests/Framework/Benchmarks/BenchmarkConfig.cs @@ -12,7 +12,6 @@ namespace Tests.Framework.Benchmarks { -#if NET46 public class CustomJsonExporter : BenchmarkDotNet.Exporters.ExporterBase { protected override string FileExtension => "json"; @@ -55,7 +54,7 @@ public override void ExportToLog(Summary summary, ILogger logger) return data; }); - + logger.WriteLine(JsonConvert.SerializeObject(new Dictionary { { "Title", summary.Title }, @@ -65,7 +64,6 @@ public override void ExportToLog(Summary summary, ILogger logger) })); } } -#endif public class BenchmarkConfigAttribute : Attribute, IConfigSource { public IConfig Config { get; } @@ -74,17 +72,13 @@ public BenchmarkConfigAttribute(int runCount = 1) { var jobs = new[] { Job.Dry.With(Runtime.Core).With(Jit.RyuJit).WithTargetCount(runCount), - Job.Dry.With(Runtime.Clr).With(Jit.RyuJit).WithTargetCount(runCount), + Job.Dry.With(Runtime.Clr).With(Jit.RyuJit).WithTargetCount(runCount), Job.Dry.With(Runtime.Clr).With(Jit.LegacyJit).WithTargetCount(runCount) }; -#if !NET46 - Config = DefaultConfig.Instance.With(jobs).With(JsonExporter.Brief); -#else Config = DefaultConfig.Instance .With(jobs) .With(new CustomJsonExporter()) .With(MemoryDiagnoser.Default); -#endif } } } diff --git a/src/Tests/Framework/Configuration/EnvironmentConfiguration.cs b/src/Tests/Framework/Configuration/EnvironmentConfiguration.cs index e7e4d56393f..318a91412fa 100644 --- a/src/Tests/Framework/Configuration/EnvironmentConfiguration.cs +++ b/src/Tests/Framework/Configuration/EnvironmentConfiguration.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Bogus; using Elastic.Managed.Configuration; +using Tests.Framework.MockData; namespace Tests.Framework.Configuration { @@ -34,8 +35,7 @@ public EnvironmentConfiguration() var newRandom = new Random().Next(1, 100000); this.Seed = TryGetEnv("NEST_TEST_SEED", out var seed) ? int.Parse(seed) : newRandom; - Randomizer.Seed = new Random(this.Seed); - var randomizer = new Randomizer(); + var randomizer = new Randomizer(this.Seed); this.Random = new RandomConfiguration { diff --git a/src/Tests/Framework/Configuration/ITestConfiguration.cs b/src/Tests/Framework/Configuration/ITestConfiguration.cs index 47beccd29ec..4518097c9a3 100644 --- a/src/Tests/Framework/Configuration/ITestConfiguration.cs +++ b/src/Tests/Framework/Configuration/ITestConfiguration.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Elastic.Managed.Configuration; +using Elastic.Managed.Configuration; namespace Tests.Framework.Configuration { public interface ITestConfiguration { - int Seed { get; } TestMode Mode { get; } ElasticsearchVersion ElasticsearchVersion { get; } string ClusterFilter { get; } @@ -17,13 +11,14 @@ public interface ITestConfiguration bool ForceReseed { get; } bool TestAgainstAlreadyRunningElasticsearch { get; } + int Seed { get; } + bool RunIntegrationTests { get; } bool RunUnitTests { get; } RandomConfiguration Random { get; } } - //TODO these dont make sense in 5.x get rid of them public class RandomConfiguration { public bool SourceSerializer { get; set; } diff --git a/src/Tests/Framework/Configuration/TestConfigurationBase.cs b/src/Tests/Framework/Configuration/TestConfigurationBase.cs index 66d04cd0d76..2cd314b6b26 100644 --- a/src/Tests/Framework/Configuration/TestConfigurationBase.cs +++ b/src/Tests/Framework/Configuration/TestConfigurationBase.cs @@ -11,6 +11,7 @@ public abstract class TestConfigurationBase : ITestConfiguration public abstract string ClusterFilter { get; protected set; } public abstract string TestFilter { get; protected set; } + public virtual bool RunIntegrationTests => Mode == TestMode.Mixed || Mode == TestMode.Integration; public virtual bool RunUnitTests => Mode == TestMode.Mixed || Mode == TestMode.Unit; diff --git a/src/Tests/Framework/Configuration/YamlConfiguration.cs b/src/Tests/Framework/Configuration/YamlConfiguration.cs index a88711978a6..9f53b772eef 100644 --- a/src/Tests/Framework/Configuration/YamlConfiguration.cs +++ b/src/Tests/Framework/Configuration/YamlConfiguration.cs @@ -4,6 +4,7 @@ using System.Linq; using Bogus; using Elastic.Managed.Configuration; +using Tests.Framework.MockData; namespace Tests.Framework.Configuration { @@ -34,8 +35,7 @@ public YamlConfiguration(string configurationFile) this.TestFilter = _config.ContainsKey("test_filter") ? _config["test_filter"] : null; this.Seed = _config.TryGetValue("seed", out var seed) ? int.Parse(seed) : 1337; - Randomizer.Seed = new Random(this.Seed); - var randomizer = new Randomizer(); + var randomizer = new Randomizer(this.Seed); this.Random = new RandomConfiguration { SourceSerializer = RandomBool("source_serializer", randomizer), diff --git a/src/Tests/Framework/ConfigurationLoader.cs b/src/Tests/Framework/ConfigurationLoader.cs new file mode 100644 index 00000000000..9df94a58617 --- /dev/null +++ b/src/Tests/Framework/ConfigurationLoader.cs @@ -0,0 +1,38 @@ +using System; +using System.IO; +using Tests.Framework.Configuration; +using Tests.Framework.MockData; + +namespace Tests.Framework +{ + public static class ConfigurationLoader + { + public static ITestConfiguration LoadConfiguration() + { + // The build script sets a FAKEBUILD env variable, so if it exists then + // we must be running tests from the build script + if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("FAKEBUILD"))) + return new EnvironmentConfiguration(); + + var directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory()); + + // If running the classic .NET solution, tests run from bin/{config} directory, + // but when running DNX solution, tests run from the test project root + var yamlConfigurationPath = (directoryInfo.Name == "Tests" + && directoryInfo.Parent != null + && directoryInfo.Parent.Name == "src") + ? "." + : @"../../../"; + + var localYamlFile = Path.GetFullPath(Path.Combine(yamlConfigurationPath, "tests.yaml")); + if (File.Exists(localYamlFile)) + return new YamlConfiguration(localYamlFile); + + var defaultYamlFile = Path.GetFullPath(Path.Combine(yamlConfigurationPath, "tests.default.yaml")); + if (File.Exists(defaultYamlFile)) + return new YamlConfiguration(defaultYamlFile); + + throw new Exception($"Tried to load a yaml file from {yamlConfigurationPath} but it does not exist : pwd:{directoryInfo.FullName}"); + } + } +} diff --git a/src/Tests/Framework/ManagedElasticsearch/XunitSetup.cs b/src/Tests/Framework/ManagedElasticsearch/XunitSetup.cs index 20def9e98a5..d7739508554 100644 --- a/src/Tests/Framework/ManagedElasticsearch/XunitSetup.cs +++ b/src/Tests/Framework/ManagedElasticsearch/XunitSetup.cs @@ -8,6 +8,7 @@ using Elastic.Xunit; using Tests.Framework.Configuration; using Tests.Framework.ManagedElasticsearch; +using Tests.Framework.MockData; using static System.Console; [assembly: Xunit.TestFrameworkAttribute("Elastic.Xunit.Sdk.ElasticTestFramework", "Elastic.Xunit")] @@ -25,6 +26,8 @@ public NestXunitRunOptions() this.ClusterFilter = TestClient.Configuration.ClusterFilter; this.TestFilter = TestClient.Configuration.TestFilter; this.Version = TestClient.Configuration.ElasticsearchVersion; + + Generators.Initialize(); } public override void OnBeforeTestsRun() => DumpConfiguration(); @@ -33,8 +36,6 @@ private static void DumpConfiguration() { var config = TestClient.Configuration; - Randomizer.Seed = new Random(config.Seed); - WriteLine(new string('-', 20)); WriteLine("Starting tests using config:"); WriteLine($" - {nameof(config.TestAgainstAlreadyRunningElasticsearch)}: {config.TestAgainstAlreadyRunningElasticsearch}"); @@ -53,6 +54,7 @@ private static void DumpConfiguration() WriteLine($" - Random:"); WriteLine($" \t- {nameof(config.Random.SourceSerializer)}: {config.Random.SourceSerializer}"); WriteLine($" \t- {nameof(config.Random.TypedKeys)}: {config.Random.TypedKeys}"); + WriteLine($" \t- {nameof(config.Random.OldConnection)}: {config.Random.OldConnection}"); WriteLine(new string('-', 20)); } @@ -109,6 +111,9 @@ private static void DumpReproduceFilters(ConcurrentBag> fa AppendExplictConfig(nameof(RandomConfiguration.SourceSerializer), sb); AppendExplictConfig(nameof(RandomConfiguration.TypedKeys), sb); +#if FEATURE_HTTPWEBREQUEST + AppendExplictConfig(nameof(RandomConfiguration.OldConnection), sb); +#endif if (runningIntegrations) sb.Append("integrate ") diff --git a/src/Tests/Framework/MockData/Generators.cs b/src/Tests/Framework/MockData/Generators.cs new file mode 100644 index 00000000000..9b92fe86c7a --- /dev/null +++ b/src/Tests/Framework/MockData/Generators.cs @@ -0,0 +1,21 @@ +namespace Tests.Framework.MockData +{ + /// + /// Class that materializes generators in static context. + /// + public static class Generators + { + static Generators() + { + var r = Gimme.Random.Number(1, 3); + var tags = Tag.Generator; + var messages = Message.Generator; + var people = Person.People; + var developers = Developer.Developers; + var projects = Project.Projects; + var commits = CommitActivity.CommitActivities; + } + + public static void Initialize() { } + } +} diff --git a/src/Tests/Framework/MockData/Gimme.cs b/src/Tests/Framework/MockData/Gimme.cs index b065c5bf43d..2dba9128260 100644 --- a/src/Tests/Framework/MockData/Gimme.cs +++ b/src/Tests/Framework/MockData/Gimme.cs @@ -1,10 +1,9 @@ -using System; using Bogus; namespace Tests.Framework.MockData { internal static class Gimme { - public static Randomizer Random = new Randomizer(TestClient.Configuration.Seed); + public static Randomizer Random { get; } = new Randomizer(TestClient.Configuration.Seed); } } diff --git a/src/Tests/Framework/MockData/Person.cs b/src/Tests/Framework/MockData/Person.cs index 4326976f602..a2dcbc310e9 100644 --- a/src/Tests/Framework/MockData/Person.cs +++ b/src/Tests/Framework/MockData/Person.cs @@ -26,6 +26,6 @@ public class Person .RuleFor(p => p.Location, p => new GeoLocation(Gimme.Random.Number(-90, 90), Gimme.Random.Number(-180, 180))) ; - public static IList Persons { get; } = Person.Generator.Clone().Generate(1000); + public static IList People { get; } = Person.Generator.Clone().Generate(1000); } } diff --git a/src/Tests/Framework/MockData/Project.cs b/src/Tests/Framework/MockData/Project.cs index 4ff1d4a1324..64f9b25869d 100644 --- a/src/Tests/Framework/MockData/Project.cs +++ b/src/Tests/Framework/MockData/Project.cs @@ -86,6 +86,7 @@ public class SimpleGeoPoint public static Faker Generator { get; } = new Faker() + .UseSeed(TestClient.Configuration.Seed) .RuleFor(p => p.Lat, f => f.Address.Latitude()) .RuleFor(p => p.Lon, f => f.Address.Longitude()) ; diff --git a/src/Tests/Framework/MockData/Ranges.cs b/src/Tests/Framework/MockData/Ranges.cs index 5d1c5530583..2f67e4a43ae 100644 --- a/src/Tests/Framework/MockData/Ranges.cs +++ b/src/Tests/Framework/MockData/Ranges.cs @@ -106,6 +106,7 @@ private static void SwapAssign(bool b, T value, Action first, Action se public static Faker Generator { get; } = new Faker() + .UseSeed(TestClient.Configuration.Seed) .CustomInstantiator((f) => new Ranges(f)) ; } diff --git a/src/Tests/Framework/Profiling/Memory/MemoryProfile.cs b/src/Tests/Framework/Profiling/Memory/MemoryProfile.cs index c5b525e651c..c8394dd4345 100644 --- a/src/Tests/Framework/Profiling/Memory/MemoryProfile.cs +++ b/src/Tests/Framework/Profiling/Memory/MemoryProfile.cs @@ -1,6 +1,6 @@ -#if !DOTNETCORE using System.IO; using System.Threading; +#if FEATURE_PROFILING using JetBrains.Profiler.Windows.Api; using JetBrains.Profiler.Windows.SelfApi; using JetBrains.Profiler.Windows.SelfApi.Config; diff --git a/src/Tests/Framework/Profiling/Memory/MemoryProfileFactory.cs b/src/Tests/Framework/Profiling/Memory/MemoryProfileFactory.cs index 3e2870f1731..aa7595a2dc4 100644 --- a/src/Tests/Framework/Profiling/Memory/MemoryProfileFactory.cs +++ b/src/Tests/Framework/Profiling/Memory/MemoryProfileFactory.cs @@ -1,4 +1,3 @@ -#if !DOTNETCORE using System; using System.Reflection; using Tests.Framework.Integration; @@ -24,4 +23,3 @@ protected override IDisposable BeginProfiling(string resultsDirectory) } } } -#endif diff --git a/src/Tests/Framework/Profiling/Performance/PerformanceProfile.cs b/src/Tests/Framework/Profiling/Performance/PerformanceProfile.cs index f7012f8e6e8..9b4efd44799 100644 --- a/src/Tests/Framework/Profiling/Performance/PerformanceProfile.cs +++ b/src/Tests/Framework/Profiling/Performance/PerformanceProfile.cs @@ -1,4 +1,3 @@ -#if !DOTNETCORE using System.IO; using System.Threading; using JetBrains.Profiler.Windows.Api; @@ -54,4 +53,3 @@ public override void Dispose() } } } -#endif diff --git a/src/Tests/Framework/Profiling/Performance/PerformanceProfileFactory.cs b/src/Tests/Framework/Profiling/Performance/PerformanceProfileFactory.cs index 7d4c668053c..2e2129ec7a6 100644 --- a/src/Tests/Framework/Profiling/Performance/PerformanceProfileFactory.cs +++ b/src/Tests/Framework/Profiling/Performance/PerformanceProfileFactory.cs @@ -1,4 +1,3 @@ -#if !DOTNETCORE using System; using System.Reflection; using Tests.Framework.Integration; @@ -24,4 +23,3 @@ protected override IDisposable BeginProfiling(string resultsDirectory) } } } -#endif diff --git a/src/Tests/Framework/Profiling/Profile.cs b/src/Tests/Framework/Profiling/Profile.cs index 8a5e46e6546..2ca4be4ce80 100644 --- a/src/Tests/Framework/Profiling/Profile.cs +++ b/src/Tests/Framework/Profiling/Profile.cs @@ -1,4 +1,3 @@ -#if !DOTNETCORE using System; using System.Collections.Generic; using System.Diagnostics; @@ -65,10 +64,9 @@ protected void WaitForProfilerToAttachToProcess() } else { - throw new ApplicationException($"Could not attach profiler to process after {WaitTime}"); + throw new Exception($"Could not attach profiler to process after {WaitTime}"); } } } } } -#endif diff --git a/src/Tests/Framework/Profiling/Timeline/TimelineProfile.cs b/src/Tests/Framework/Profiling/Timeline/TimelineProfile.cs index ef0250bff8b..e0c44014b1c 100644 --- a/src/Tests/Framework/Profiling/Timeline/TimelineProfile.cs +++ b/src/Tests/Framework/Profiling/Timeline/TimelineProfile.cs @@ -1,4 +1,3 @@ -#if !DOTNETCORE using System.IO; using JetBrains.Profiler.Windows.Api; using JetBrains.Profiler.Windows.SelfApi; @@ -44,4 +43,3 @@ public override void Dispose() } } } -#endif diff --git a/src/Tests/Framework/Profiling/Timeline/TimelineProfileFactory.cs b/src/Tests/Framework/Profiling/Timeline/TimelineProfileFactory.cs index 9456b228fb3..40ee775f1c4 100644 --- a/src/Tests/Framework/Profiling/Timeline/TimelineProfileFactory.cs +++ b/src/Tests/Framework/Profiling/Timeline/TimelineProfileFactory.cs @@ -1,4 +1,3 @@ -#if !DOTNETCORE using System; using System.Reflection; using Tests.Framework.Integration; @@ -23,4 +22,3 @@ protected override IDisposable BeginProfiling(string resultsDirectory) } } } -#endif diff --git a/src/Tests/Framework/TestClient.cs b/src/Tests/Framework/TestClient.cs index af4740f8350..db541a03636 100644 --- a/src/Tests/Framework/TestClient.cs +++ b/src/Tests/Framework/TestClient.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; -using System.IO; using System.Linq; using System.Net; using System.Text; @@ -39,9 +38,9 @@ public class SkipOnTeamCityAttribute : SkipTestAttributeBase } public static class TestClient { - public static bool RunningFiddler = Process.GetProcessesByName("fiddler").Any(); + public static readonly bool RunningFiddler = Process.GetProcessesByName("fiddler").Any(); + public static readonly ITestConfiguration Configuration = ConfigurationLoader.LoadConfiguration(); - public static ITestConfiguration Configuration = LoadConfiguration(); public static ConnectionSettings GlobalDefaultSettings = CreateSettings(); public static IElasticClient Default = new ElasticClient(GlobalDefaultSettings); public static IElasticClient DefaultInMemoryClient = GetInMemoryClient(); @@ -54,34 +53,6 @@ public static Uri CreateUri(int port = 9200, bool forceSsl = false) => public static string DefaultHost => "localhost"; public static string Host => (RunningFiddler) ? "ipv4.fiddler" : DefaultHost; - private static ITestConfiguration LoadConfiguration() - { - // The build script sets a FAKEBUILD env variable, so if it exists then - // we must be running tests from the build script - if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("FAKEBUILD"))) - return new EnvironmentConfiguration(); - - var directoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory()); - - // If running the classic .NET solution, tests run from bin/{config} directory, - // but when running DNX solution, tests run from the test project root - var yamlConfigurationPath = (directoryInfo.Name == "Tests" - && directoryInfo.Parent != null - && directoryInfo.Parent.Name == "src") - ? "." - : @"../../../"; - - var localYamlFile = Path.GetFullPath(Path.Combine(yamlConfigurationPath, "tests.yaml")); - if (File.Exists(localYamlFile)) - return new YamlConfiguration(localYamlFile); - - var defaultYamlFile = Path.GetFullPath(Path.Combine(yamlConfigurationPath, "tests.default.yaml")); - if (File.Exists(defaultYamlFile)) - return new YamlConfiguration(defaultYamlFile); - - throw new Exception($"Tried to load a yaml file from {yamlConfigurationPath} but it does not exist : pwd:{directoryInfo.FullName}"); - } - private static int ConnectionLimitDefault => int.TryParse(Environment.GetEnvironmentVariable("NEST_NUMBER_OF_CONNECTIONS"), out int x) ? x diff --git a/src/Tests/Program.cs b/src/Tests/Program.cs index b33f0068828..b2da9a2ec38 100644 --- a/src/Tests/Program.cs +++ b/src/Tests/Program.cs @@ -62,8 +62,8 @@ static BenchmarkProgram() private const string SelfProfileSdkDirectory = "dottrace-selfprofile"; - private static string SdkPath { get; } - private static string OutputPath { get; } + private static string SdkPath { get; } + private static string OutputPath { get; } public static void Main(string[] args) { @@ -73,10 +73,7 @@ public static void Main(string[] args) var arguments = args.Skip(1).ToArray(); if (args[0].Equals("Profile", StringComparison.OrdinalIgnoreCase)) { -#if DOTNETCORE - Console.Error.WriteLine("DotTrace Profiling is not currently supported on .NET Core"); - return; -#else +#if FEATURE_PROFILING var configuration = ProfileConfiguration.Parse(arguments); Console.WriteLine("Running Profiling with the following:"); Console.WriteLine($"- SdkPath: {SdkPath}"); @@ -91,6 +88,11 @@ public static void Main(string[] args) profilingFactory.RunAsync(configuration).Wait(); } } +#else + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Tests.exe is not built with Profiling support"); + Console.ResetColor(); + Environment.Exit(9); #endif } else if (args[0].Equals("Benchmark", StringComparison.OrdinalIgnoreCase)) @@ -112,15 +114,14 @@ public static void Main(string[] args) } } -#if !DOTNETCORE +#if FEATURE_PROFILING private static IEnumerable CreateProfilingFactory(ProfilingCluster cluster) { - yield return new PerformanceProfileFactory(SdkPath, OutputPath, cluster, Assembly.GetExecutingAssembly(), new ColoredConsoleWriter()); - yield return new TimelineProfileFactory(SdkPath, OutputPath, cluster, Assembly.GetExecutingAssembly(), new ColoredConsoleWriter()); - yield return new MemoryProfileFactory(SdkPath, OutputPath, cluster, Assembly.GetExecutingAssembly(), new ColoredConsoleWriter()); + yield return new PerformanceProfileFactory(SdkPath, OutputPath, cluster, Assembly.GetEntryAssembly(), new ColoredConsoleWriter()); + yield return new TimelineProfileFactory(SdkPath, OutputPath, cluster, Assembly.GetEntryAssembly(), new ColoredConsoleWriter()); + yield return new MemoryProfileFactory(SdkPath, OutputPath, cluster, Assembly.GetEntryAssembly(), new ColoredConsoleWriter()); } #endif - private static Type[] GetBenchmarkTypes() { IEnumerable types; diff --git a/src/Tests/Search/Request/InnerHitsUsageTests.cs b/src/Tests/Search/Request/InnerHitsUsageTests.cs index 59ee8675dd0..11a341f5c40 100644 --- a/src/Tests/Search/Request/InnerHitsUsageTests.cs +++ b/src/Tests/Search/Request/InnerHitsUsageTests.cs @@ -30,6 +30,7 @@ public abstract class RoyalBase : IRoyal public string Name { get; set; } public static Faker Generator { get; } = new Faker() + .UseSeed(TestClient.Configuration.Seed) .RuleFor(p => p.Name, f => f.Person.Company.Name + IdState++); } diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 7e599ad39f3..aecb0ce63d6 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -2,13 +2,13 @@ Exe - netcoreapp2.0;net46 - netcoreapp2.0 + netcoreapp2.1;net46 + netcoreapp2.1 6.0.0 alpha Tests.BenchmarkProgram $(NoWarn);xUnit1013 - $(DefineConstants);DOTNETCORE + $(DefineConstants);FEATURE_HTTPWEBREQUEST $(DefineConstants);FEATURE_PROFILING @@ -16,14 +16,14 @@ ../../build/output/_packages;https://api.nuget.org/v3/index.json $(DefineConstants);TESTINGNUGETPACKAGE - - + + - - + + - 0.0.0-bad - 0.0.0 - 0.0.0.0 - - 1 - - - - - $(CurrentVersion) - $(CurrentVersion) - - $(CurrentAssemblyVersion) - - $(CurrentAssemblyFileVersion) - - true - ..\..\build\keys\keypair.snk - true - 1591,1572,1571,1573,1587,1570 - false - $(DefineConstants);DOTNETCORE - embedded - full - $(BaseIntermediateOutputPath)\sl-$(MsBuildProjectName)-$(TargetFramework).json - https://raw.githubusercontent.com/elastic/elasticsearch-net - - - - - - - - - - - - -