[WIP] Update core-setup local tools to use S.T.Json for netstandard2.0 instead#5010
[WIP] Update core-setup local tools to use S.T.Json for netstandard2.0 instead#5010ahsonkhan wants to merge 3 commits intodotnet:masterfrom
Conversation
| string jsonFileText = projectFileReader.ReadToEnd(); | ||
|
|
||
| // TODO: Replace the use of the Utf8JsonReader with the Deserializer once it is available. | ||
| ConfigJson configJson = GetConfigJson(jsonFileText); |
There was a problem hiding this comment.
This isn't a great way to deserialize a POCO object. I used the JsonReader just as an experiment.
|
|
||
| private void ReadWritePropertyName(string propertyName, ref Utf8JsonReader reader, ref Utf8JsonWriter writer) | ||
| { | ||
| if (propertyName == "targets") |
There was a problem hiding this comment.
We need to use the JsonDocument here. The order in which the "targets" property and the "libraries" property show up could affect the end results here if we use the Reader and Writer. This relies on "targets" coming up before "libraries".
There was a problem hiding this comment.
https://dotnet.myget.org/feed/dotnet-core/package/nuget/Microsoft.Bcl.Json.Sources says JsonDocument is available now (4.6.0-preview.19073.1 is bigger than the previous version)
| if (!File.Exists(ConfigJsonFile)) | ||
| { | ||
| throw new FileNotFoundException($"Expected file {ConfigJsonFile} was not found."); | ||
| } |
There was a problem hiding this comment.
Won't File.OpenText throw the same exception, and without the inherent race condition? You're just trying to provide a better exception message in some cases?
There was a problem hiding this comment.
|
|
||
| // Open the Config Json and read the values into the model | ||
| TextReader projectFileReader = File.OpenText(ConfigJsonFile); | ||
| if (projectFileReader != null) |
There was a problem hiding this comment.
Copy/pasted from the origin impl. Will fix there.
| } | ||
|
|
||
| // Open the Config Json and read the values into the model | ||
| TextReader projectFileReader = File.OpenText(ConfigJsonFile); |
There was a problem hiding this comment.
This should be disposed of when you're done with it; otherwise you're leaving the file open until it's eventually closed by a finalizer.
There was a problem hiding this comment.
Most of these exist in the current implementation and I didn't modify most of it. I am going to remove BuildFPMToolPreReqs.Netstandard2_0.cs since we should wait for the Deserializer anyway, but will fix the issues you mentioned here.
| string jsonFileText = projectFileReader.ReadToEnd(); | ||
|
|
||
| // TODO: Replace the use of the Utf8JsonReader with the Deserializer once it is available. | ||
| ConfigJson configJson = GetConfigJson(jsonFileText); |
There was a problem hiding this comment.
So we're opening the file, reading all of its contents into a string (which will involve converting from UTF8 to UTF16 if it's saved as UTF8), and then turning around and encoding that string into a UTF8 byte[]? Isn't the point of having a UTF8-based JSON reader to avoid that? Or it simply doesn't matter perf-wise here and this is what's cleanest?
There was a problem hiding this comment.
I was going to ask the same question, but then I realized that the reader does encoding-sniffing. So if someone saves the file as UTF-16 this would still successfully read it.
If we're willing to say "the file is UTF-8" (or, more likely, "the file is 7-bit ASCII") then this can be simplified a lot.
| while (reader.Read() && reader.TokenType == JsonTokenType.PropertyName) | ||
| { | ||
| string propertyName = reader.GetStringValue().ToLower(); | ||
| if (propertyName == Maintainer_Name_String) |
There was a problem hiding this comment.
Does perf not matter here? Or could we instead compare span to span rather than materializing the string? And if we stick with strings, could the comparison be done as ordinal ignore case rather than lower casing the property name?
| /// <summary> | ||
| /// Model classes for reading and storing the JSON. | ||
| /// </summary> | ||
| public class ConfigJson |
There was a problem hiding this comment.
As with the other PR; there's a lot of duplication between this file and the alternate for this file.
Is the intention to ever put this code in? I don't see a valid reason for complicating this code. |
|
Closing as stale. |
|
Sounds good. Will re-visit post 3.0. |
Initial attempt to port tools-local to use the
System.Text.Jsonsource package for TFM netstandard2.0. Note: There are some API changes going through so this is still WIP. We have the JsonReader and JsonWriter available atm so only using the components that are ready.The System.Text.Json binary is in-box on .NET Core 3.0.
I added TODOs to use the
JsonDocumentandDeserializeronce they are available. Using theUtf8Readerin these scenarios is less than ideal and requires a lot of code change.This PR is mainly to experiment to gather feedback and showcase the capabilities. Hence, marked as no merge.
We can't remove the reference to Newtonsoft since the tools are targeting net46 on Unix.
Is it possible to drop support for all but netstandard2.0? Otherwise, we have to conditionally include the source package.
See https://github.com/dotnet/corefx/blob/master/src/System.Text.Json/source_package/README.md
Related PR: #5009
cc @joshfree, @bartonjs, @steveharter, @eerhardt, @KrzysztofCwalina, @JamesNK, @glennc, @ericstj