-
Notifications
You must be signed in to change notification settings - Fork 734
System.Text.Json Migration - Adding code to parse the PackageSpec using STJ #5541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
22f3566
b92d83f
e6219c5
b3c8f85
96e628a
de5f9e8
ee98406
0803621
08c02b2
51a1aa9
31d06f1
0b26816
2c5e756
192ee52
f1200e5
8e2c300
eef2428
7eb51ae
4db5fea
c01a509
d38617a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,11 +19,10 @@ | |
|
|
||
| namespace NuGet.ProjectModel | ||
| { | ||
| public static class JsonPackageSpecReader | ||
| public static partial class JsonPackageSpecReader | ||
| { | ||
| private static readonly char[] DelimitedStringSeparators = { ' ', ',' }; | ||
| private static readonly char[] VersionSeparators = new[] { ';' }; | ||
|
|
||
| public static readonly string RestoreOptions = "restore"; | ||
| public static readonly string RestoreSettings = "restoreSettings"; | ||
| public static readonly string HideWarningsAndErrors = "hideWarningsAndErrors"; | ||
|
|
@@ -49,19 +48,15 @@ public static PackageSpec GetPackageSpec(string json, string name, string packag | |
| } | ||
| } | ||
|
|
||
| [Obsolete("This method is obsolete and will be removed in a future release.")] | ||
| public static PackageSpec GetPackageSpec(JObject json) | ||
| public static PackageSpec GetPackageSpec(Stream stream, string name, string packageSpecPath, string snapshotValue) | ||
| { | ||
| return GetPackageSpec(json, name: null, packageSpecPath: null, snapshotValue: null); | ||
| return GetPackageSpec(stream, name, packageSpecPath, snapshotValue, EnvironmentVariableWrapper.Instance); | ||
| } | ||
|
|
||
| public static PackageSpec GetPackageSpec(Stream stream, string name, string packageSpecPath, string snapshotValue) | ||
| [Obsolete("This method is obsolete and will be removed in a future release.")] | ||
| public static PackageSpec GetPackageSpec(JObject json) | ||
| { | ||
| using (var streamReader = new StreamReader(stream)) | ||
| using (var jsonReader = new JsonTextReader(streamReader)) | ||
| { | ||
| return GetPackageSpec(jsonReader, name, packageSpecPath, snapshotValue); | ||
| } | ||
| return GetPackageSpec(json, name: null, packageSpecPath: null, snapshotValue: null); | ||
| } | ||
|
|
||
| [Obsolete("This method is obsolete and will be removed in a future release.")] | ||
|
|
@@ -74,12 +69,33 @@ public static PackageSpec GetPackageSpec(JObject rawPackageSpec, string name, st | |
| } | ||
| } | ||
|
|
||
| [Obsolete] | ||
| internal static PackageSpec GetPackageSpec(JsonTextReader jsonReader, string packageSpecPath) | ||
| { | ||
| return GetPackageSpec(jsonReader, name: null, packageSpecPath, snapshotValue: null); | ||
| } | ||
|
|
||
| private static PackageSpec GetPackageSpec(JsonTextReader jsonReader, string name, string packageSpecPath, string snapshotValue) | ||
| internal static PackageSpec GetPackageSpec(Stream stream, string name, string packageSpecPath, string snapshotValue, IEnvironmentVariableReader environmentVariableReader) | ||
| { | ||
| var useNj = environmentVariableReader.GetEnvironmentVariable("NUGET_EXPERIMENTAL_USE_NJ_FOR_FILE_PARSING"); | ||
| if (string.IsNullOrEmpty(useNj) || useNj.Equals("false", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| return GetPackageSpecUtf8JsonStreamReader(stream, name, packageSpecPath, snapshotValue); | ||
| } | ||
| else | ||
| { | ||
| using (var textReader = new StreamReader(stream)) | ||
| using (var jsonReader = new JsonTextReader(textReader)) | ||
| { | ||
| #pragma warning disable CS0612 // Type or member is obsolete | ||
| return GetPackageSpec(jsonReader, name, packageSpecPath, snapshotValue); | ||
| #pragma warning restore CS0612 // Type or member is obsolete | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Obsolete] | ||
| internal static PackageSpec GetPackageSpec(JsonTextReader jsonReader, string name, string packageSpecPath, string snapshotValue) | ||
| { | ||
| var packageSpec = new PackageSpec(); | ||
|
|
||
|
|
@@ -237,6 +253,7 @@ private static PackageSpec GetPackageSpec(JsonTextReader jsonReader, string name | |
| return packageSpec; | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static PackageType CreatePackageType(JsonTextReader jsonReader) | ||
| { | ||
| var name = (string)jsonReader.Value; | ||
|
|
@@ -258,6 +275,7 @@ private static void ReadBuildOptions(JsonTextReader jsonReader, PackageSpec pack | |
| }); | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static void ReadCentralPackageVersions( | ||
| JsonTextReader jsonReader, | ||
| IDictionary<string, CentralPackageVersion> centralPackageVersions, | ||
|
|
@@ -292,6 +310,7 @@ private static void ReadCentralPackageVersions( | |
| }); | ||
| } | ||
|
|
||
| [Obsolete] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An obsolete attribute allows to add a short explanation suggesting alternative workarounds. It could be great if we can add that information here. Are these methods marked as obsolete due to their usage in the Newtonsoft.Json API? If that's the case, perhaps we could add a message to inform the caller. In certain instances, the caller might be a customer of the NuGet SDK.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is private so we shouldn't have any customers calling it right? The public functions have a message in them already but I can update it if you think a specific call out to STJ would be better. |
||
| private static CompatibilityProfile ReadCompatibilityProfile(JsonTextReader jsonReader, string profileName) | ||
| { | ||
| List<FrameworkRuntimePair> sets = null; | ||
|
|
@@ -308,6 +327,7 @@ private static CompatibilityProfile ReadCompatibilityProfile(JsonTextReader json | |
| return new CompatibilityProfile(profileName, sets ?? Enumerable.Empty<FrameworkRuntimePair>()); | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static IEnumerable<FrameworkRuntimePair> ReadCompatibilitySets(JsonTextReader jsonReader, string compatibilitySetName) | ||
| { | ||
| NuGetFramework framework = NuGetFramework.Parse(compatibilitySetName); | ||
|
|
@@ -320,7 +340,8 @@ private static IEnumerable<FrameworkRuntimePair> ReadCompatibilitySets(JsonTextR | |
| } | ||
| } | ||
|
|
||
| internal static void ReadDependencies( | ||
| [Obsolete] | ||
| private static void ReadDependencies( | ||
| JsonTextReader jsonReader, | ||
| IList<LibraryDependency> results, | ||
| string packageSpecPath, | ||
|
|
@@ -519,6 +540,7 @@ internal static void ReadDependencies( | |
| }); | ||
| } | ||
|
|
||
| [Obsolete] | ||
| internal static void ReadCentralTransitiveDependencyGroup( | ||
| JsonTextReader jsonReader, | ||
| IList<LibraryDependency> results, | ||
|
|
@@ -641,6 +663,7 @@ internal static void ReadCentralTransitiveDependencyGroup( | |
| }); | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static void ReadDownloadDependencies( | ||
| JsonTextReader jsonReader, | ||
| IList<DownloadDependency> downloadDependencies, | ||
|
|
@@ -731,13 +754,15 @@ private static void ReadDownloadDependencies( | |
| } | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static IReadOnlyList<string> ReadEnumerableOfString(JsonTextReader jsonReader) | ||
| { | ||
| string value = jsonReader.ReadNextTokenAsString(); | ||
|
|
||
| return value.Split(DelimitedStringSeparators, StringSplitOptions.RemoveEmptyEntries); | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static void ReadFrameworkReferences( | ||
| JsonTextReader jsonReader, | ||
| ISet<FrameworkDependency> frameworkReferences, | ||
|
|
@@ -773,6 +798,7 @@ private static void ReadFrameworkReferences( | |
| }); | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static void ReadFrameworks(JsonTextReader jsonReader, PackageSpec packageSpec) | ||
| { | ||
| jsonReader.ReadObject(_ => | ||
|
|
@@ -791,6 +817,7 @@ private static void ReadFrameworks(JsonTextReader jsonReader, PackageSpec packag | |
| }); | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static void ReadImports(PackageSpec packageSpec, JsonTextReader jsonReader, TargetFrameworkInformation targetFrameworkInformation) | ||
| { | ||
| int lineNumber = jsonReader.LineNumber; | ||
|
|
@@ -822,6 +849,7 @@ private static void ReadImports(PackageSpec packageSpec, JsonTextReader jsonRead | |
| } | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static void ReadMappings(JsonTextReader jsonReader, string mappingKey, IDictionary<string, IncludeExcludeFiles> mappings) | ||
| { | ||
| if (jsonReader.ReadNextToken()) | ||
|
|
@@ -899,6 +927,7 @@ private static void ReadMappings(JsonTextReader jsonReader, string mappingKey, I | |
| } | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static void ReadMSBuildMetadata(JsonTextReader jsonReader, PackageSpec packageSpec) | ||
| { | ||
| var centralPackageVersionsManagementEnabled = false; | ||
|
|
@@ -1205,6 +1234,7 @@ private static void ReadMSBuildMetadata(JsonTextReader jsonReader, PackageSpec p | |
| packageSpec.RestoreMetadata = msbuildMetadata; | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static bool ReadNextTokenAsBoolOrFalse(JsonTextReader jsonReader, string filePath) | ||
| { | ||
| if (jsonReader.ReadNextToken() && jsonReader.TokenType == JsonToken.Boolean) | ||
|
|
@@ -1222,6 +1252,7 @@ private static bool ReadNextTokenAsBoolOrFalse(JsonTextReader jsonReader, string | |
| return false; | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static void ReadNuGetLogCodes(JsonTextReader jsonReader, HashSet<NuGetLogCode> hashCodes) | ||
| { | ||
| if (jsonReader.ReadNextToken() && jsonReader.TokenType == JsonToken.StartArray) | ||
|
|
@@ -1236,6 +1267,7 @@ private static void ReadNuGetLogCodes(JsonTextReader jsonReader, HashSet<NuGetLo | |
| } | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static List<NuGetLogCode> ReadNuGetLogCodesList(JsonTextReader jsonReader) | ||
| { | ||
| List<NuGetLogCode> items = null; | ||
|
|
@@ -1256,6 +1288,7 @@ private static List<NuGetLogCode> ReadNuGetLogCodesList(JsonTextReader jsonReade | |
| return items; | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static void ReadPackageTypes(PackageSpec packageSpec, JsonTextReader jsonReader) | ||
| { | ||
| var errorLine = 0; | ||
|
|
@@ -1460,7 +1493,8 @@ private static bool ReadPackOptionsFiles(PackageSpec packageSpec, JsonTextReader | |
| return wasMappingsRead; | ||
| } | ||
|
|
||
| private static RuntimeDependencySet ReadRuntimeDependencySet(JsonTextReader jsonReader, string dependencySetName) | ||
| [Obsolete] | ||
| static RuntimeDependencySet ReadRuntimeDependencySet(JsonTextReader jsonReader, string dependencySetName) | ||
| { | ||
| List<RuntimePackageDependency> dependencies = null; | ||
|
|
||
|
|
@@ -1478,6 +1512,7 @@ private static RuntimeDependencySet ReadRuntimeDependencySet(JsonTextReader json | |
| dependencies); | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static RuntimeDescription ReadRuntimeDescription(JsonTextReader jsonReader, string runtimeName) | ||
| { | ||
| List<string> inheritedRuntimes = null; | ||
|
|
@@ -1505,6 +1540,7 @@ private static RuntimeDescription ReadRuntimeDescription(JsonTextReader jsonRead | |
| additionalDependencies); | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static List<RuntimeDescription> ReadRuntimes(JsonTextReader jsonReader) | ||
| { | ||
| var runtimeDescriptions = new List<RuntimeDescription>(); | ||
|
|
@@ -1553,13 +1589,15 @@ private static void ReadScripts(JsonTextReader jsonReader, PackageSpec packageSp | |
| }); | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static string[] ReadStringArray(JsonTextReader jsonReader) | ||
| { | ||
| List<string> list = jsonReader.ReadStringArrayAsList(); | ||
|
|
||
| return list?.ToArray(); | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static List<CompatibilityProfile> ReadSupports(JsonTextReader jsonReader) | ||
| { | ||
| var compatibilityProfiles = new List<CompatibilityProfile>(); | ||
|
|
@@ -1574,6 +1612,7 @@ private static List<CompatibilityProfile> ReadSupports(JsonTextReader jsonReader | |
| return compatibilityProfiles; | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static LibraryDependencyTarget ReadTarget( | ||
| JsonTextReader jsonReader, | ||
| string packageSpecPath, | ||
|
|
@@ -1604,6 +1643,7 @@ private static LibraryDependencyTarget ReadTarget( | |
| return targetFlagsValue; | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static List<ProjectRestoreMetadataFrameworkInfo> ReadTargetFrameworks(JsonTextReader jsonReader) | ||
| { | ||
| var targetFrameworks = new List<ProjectRestoreMetadataFrameworkInfo>(); | ||
|
|
@@ -1677,6 +1717,7 @@ private static List<ProjectRestoreMetadataFrameworkInfo> ReadTargetFrameworks(Js | |
| return targetFrameworks; | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static void ReadTargetFrameworks(PackageSpec packageSpec, JsonTextReader jsonReader, out int frameworkLine, out int frameworkColumn) | ||
| { | ||
| frameworkLine = 0; | ||
|
|
@@ -1757,6 +1798,12 @@ private static void ReadTargetFrameworks(PackageSpec packageSpec, JsonTextReader | |
| } | ||
| }, out frameworkLine, out frameworkColumn); | ||
|
|
||
| AddTargetFramework(packageSpec, frameworkName, secondaryFramework, targetFrameworkInformation); | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static void AddTargetFramework(PackageSpec packageSpec, NuGetFramework frameworkName, NuGetFramework secondaryFramework, TargetFrameworkInformation targetFrameworkInformation) | ||
| { | ||
| NuGetFramework updatedFramework = frameworkName; | ||
|
|
||
| if (targetFrameworkInformation.Imports.Count > 0) | ||
|
|
@@ -1782,6 +1829,8 @@ private static void ReadTargetFrameworks(PackageSpec packageSpec, JsonTextReader | |
| packageSpec.TargetFrameworks.Add(targetFrameworkInformation); | ||
| } | ||
|
|
||
|
|
||
| [Obsolete] | ||
| private static NuGetFramework GetDualCompatibilityFrameworkIfNeeded(NuGetFramework frameworkName, NuGetFramework secondaryFramework) | ||
| { | ||
| if (secondaryFramework != default) | ||
|
|
@@ -1792,6 +1841,7 @@ private static NuGetFramework GetDualCompatibilityFrameworkIfNeeded(NuGetFramewo | |
| return frameworkName; | ||
| } | ||
|
|
||
| [Obsolete] | ||
| private static bool ValidateDependencyTarget(LibraryDependencyTarget targetValue) | ||
| { | ||
| var isValid = false; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.