Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a57aabf
Copied initial files over and addressred some PR comments
jgonz120 Dec 20, 2023
05ed3db
Test updates
jgonz120 Dec 21, 2023
c285f0f
optimized string split
jgonz120 Dec 21, 2023
c06e3f5
cleanup
jgonz120 Dec 21, 2023
ef90a51
switch to stream
jgonz120 Dec 21, 2023
4c31cbf
fix typo
jgonz120 Dec 21, 2023
b787826
fix typo
jgonz120 Dec 21, 2023
c627b25
create static json reader state
jgonz120 Dec 21, 2023
ef35381
typo
jgonz120 Dec 21, 2023
084986d
typo
jgonz120 Dec 21, 2023
5850754
added lazy string split
jgonz120 Dec 22, 2023
014739f
using
jgonz120 Dec 22, 2023
d28a482
Update unit tests
jgonz120 Dec 22, 2023
c9cb53f
unit tests
jgonz120 Dec 22, 2023
d083e23
fix references
jgonz120 Dec 22, 2023
0b22126
Fix typo
jgonz120 Dec 22, 2023
e81974f
Added test for invalid logs
jgonz120 Jan 4, 2024
d2cc5d6
removed extra name assignment from package spec reader
jgonz120 Jan 4, 2024
2de68c4
use array empty
jgonz120 Jan 4, 2024
79e2b71
move public method up
jgonz120 Jan 4, 2024
ccd6fe1
remove uneeded string list
jgonz120 Jan 4, 2024
8d719c6
use false string
jgonz120 Jan 4, 2024
212b7bd
add is final block to test
jgonz120 Jan 4, 2024
b5a82d7
rename test
jgonz120 Jan 4, 2024
82363ee
style
jgonz120 Jan 4, 2024
0cc4e51
style
jgonz120 Jan 4, 2024
c525dc8
add tests for validating empty streams on creationg of utf8jsonstream…
jgonz120 Jan 4, 2024
4e5112a
Added test and implemented string split in two
jgonz120 Jan 5, 2024
2398980
fix validation for lazy string split
jgonz120 Jan 8, 2024
1693913
reduce methods in LikeFileFormat
jgonz120 Jan 8, 2024
e0ef66d
set the list values with the results directly
jgonz120 Jan 8, 2024
b4d0169
store environment variable to avoid calling GetEnvironmentVariable se…
jgonz120 Jan 8, 2024
f060670
switch to splitintwo
jgonz120 Jan 9, 2024
4602b44
Update conditional for framework
jgonz120 Jan 9, 2024
a240062
Caching the parsed NugetVersion and VersionRange objects.
jgonz120 Jan 11, 2024
0883567
Fixes from PR
jgonz120 Jan 11, 2024
c4adaf7
Avoid creating empty lists
jgonz120 Jan 11, 2024
bda30bb
Revert "Caching the parsed NugetVersion and VersionRange objects."
jgonz120 Jan 17, 2024
fb7ebd5
Fix netwonsoft json parsing
jgonz120 Jan 17, 2024
32aba9a
Add missing reference
jgonz120 Jan 17, 2024
8853734
added some examples of the json to be parsed
jgonz120 Jan 17, 2024
1b29455
Fix references in comments
jgonz120 Jan 17, 2024
1877448
Fixes from PR
jgonz120 Jan 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Caching the parsed NugetVersion and VersionRange objects."
This reverts commit a240062.
  • Loading branch information
jgonz120 committed Jan 17, 2024
commit bda30bbb8822b98143705b754a9aa7026aea55ca
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private static LibraryDependency ReadLibraryDependency(ref Utf8JsonStreamReader
{
try
{
dependencyVersionRange = JsonUtility.ParseVersionRange(dependencyVersionValue);
dependencyVersionRange = VersionRange.Parse(dependencyVersionValue);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -489,7 +489,7 @@ private static void ReadDependencies(
var versionPropValue = jsonReader.GetString();
try
{
versionOverride = JsonUtility.ParseVersionRange(versionPropValue);
versionOverride = VersionRange.Parse(versionPropValue);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -518,7 +518,7 @@ private static void ReadDependencies(
{
try
{
dependencyVersionRange = JsonUtility.ParseVersionRange(dependencyVersionValue);
dependencyVersionRange = VersionRange.Parse(dependencyVersionValue);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -628,7 +628,7 @@ private static void ReadCentralPackageVersions(
throw FileFormatException.Create("The version cannot be null or empty.", filePath);
}

centralPackageVersions[propertyName] = new CentralPackageVersion(propertyName, JsonUtility.ParseVersionRange(version));
centralPackageVersions[propertyName] = new CentralPackageVersion(propertyName, VersionRange.Parse(version));
}
}
}
Expand Down Expand Up @@ -735,7 +735,7 @@ private static void ReadDownloadDependencies(

try
{
VersionRange version = JsonUtility.ParseVersionRange(singleVersionValue);
VersionRange version = VersionRange.Parse(singleVersionValue);

downloadDependencies.Add(new DownloadDependency(name, version));
}
Expand Down Expand Up @@ -1494,7 +1494,7 @@ private static RuntimeDependencySet ReadRuntimeDependencySet(ref Utf8JsonStreamR
var propertyName = jsonReader.GetString();
dependencies ??= [];

var dependency = new RuntimePackageDependency(propertyName, JsonUtility.ParseVersionRange(jsonReader.ReadNextTokenAsString()));
var dependency = new RuntimePackageDependency(propertyName, VersionRange.Parse(jsonReader.ReadNextTokenAsString()));

dependencies.Add(dependency);
}
Expand Down
12 changes: 6 additions & 6 deletions src/NuGet.Core/NuGet.ProjectModel/JsonPackageSpecReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private static void ReadCentralPackageVersions(
filePath);
}

centralPackageVersions[propertyName] = new CentralPackageVersion(propertyName, JsonUtility.ParseVersionRange(version));
centralPackageVersions[propertyName] = new CentralPackageVersion(propertyName, VersionRange.Parse(version));
});
}

Expand Down Expand Up @@ -449,7 +449,7 @@ private static void ReadDependencies(
{
try
{
versionOverride = JsonUtility.ParseVersionRange((string)jsonReader.Value);
versionOverride = VersionRange.Parse((string)jsonReader.Value);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -478,7 +478,7 @@ private static void ReadDependencies(
{
try
{
dependencyVersionRange = JsonUtility.ParseVersionRange(dependencyVersionValue);
dependencyVersionRange = VersionRange.Parse(dependencyVersionValue);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -620,7 +620,7 @@ internal static void ReadCentralTransitiveDependencyGroup(
{
try
{
dependencyVersionRange = JsonUtility.ParseVersionRange(dependencyVersionValue);
dependencyVersionRange = VersionRange.Parse(dependencyVersionValue);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -737,7 +737,7 @@ private static void ReadDownloadDependencies(
{
try
{
VersionRange version = JsonUtility.ParseVersionRange(singleVersionValue);
VersionRange version = VersionRange.Parse(singleVersionValue);

downloadDependencies.Add(new DownloadDependency(name, version));
}
Expand Down Expand Up @@ -1502,7 +1502,7 @@ static RuntimeDependencySet ReadRuntimeDependencySet(JsonTextReader jsonReader,
{
dependencies ??= new List<RuntimePackageDependency>();

var dependency = new RuntimePackageDependency(propertyName, JsonUtility.ParseVersionRange(jsonReader.ReadNextTokenAsString()));
var dependency = new RuntimePackageDependency(propertyName, VersionRange.Parse(jsonReader.ReadNextTokenAsString()));

dependencies.Add(dependency);
});
Expand Down
36 changes: 1 addition & 35 deletions src/NuGet.Core/NuGet.ProjectModel/JsonUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ namespace NuGet.ProjectModel
{
internal static class JsonUtility
{
private static readonly Dictionary<string, NuGetVersion> NuGetVersionCache = new();
private static readonly Dictionary<string, VersionRange> VersionRangeCache = new();

internal const string NUGET_EXPERIMENTAL_USE_NJ_FOR_FILE_PARSING = nameof(NUGET_EXPERIMENTAL_USE_NJ_FOR_FILE_PARSING);
internal static bool? UseNewtonsoftJson = null;
internal static readonly char[] PathSplitChars = new[] { LockFile.DirectorySeparatorChar };
Expand Down Expand Up @@ -60,7 +57,7 @@ internal static PackageDependency ReadPackageDependency(string property, JToken
var versionStr = json.Value<string>();
return new PackageDependency(
property,
versionStr == null ? null : JsonUtility.ParseVersionRange(versionStr));
versionStr == null ? null : VersionRange.Parse(versionStr));
}

internal static bool UseNewstonSoftJsonForParsing(IEnvironmentVariableReader environmentVariableReader, bool bypassCache)
Expand Down Expand Up @@ -170,36 +167,5 @@ internal static JToken WriteString(string item)
{
return item != null ? new JValue(item) : JValue.CreateNull();
}

internal static NuGetVersion ParseNugetVersion(string value)
{
if (!NuGetVersionCache.ContainsKey(value))
{
var result = NuGetVersion.Parse(value);
NuGetVersionCache[value] = result;
}
return NuGetVersionCache[value];
}

internal static bool TryParseNugetVersion(string value, out NuGetVersion version)
{
if (!NuGetVersionCache.ContainsKey(value))
{
_ = NuGetVersion.TryParse(value, out version);
NuGetVersionCache[value] = version;
}
version = NuGetVersionCache[value];
return version is not null;
}

internal static VersionRange ParseVersionRange(string value)
{
if (!VersionRangeCache.ContainsKey(value))
{
var result = VersionRange.Parse(value);
VersionRangeCache[value] = result;
}
return VersionRangeCache[value];
}
}
}
6 changes: 3 additions & 3 deletions src/NuGet.Core/NuGet.ProjectModel/LockFile/LockFileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public LockFile Read(Stream stream, ILogger log, string path)

internal LockFile Read(Stream stream, ILogger log, string path, IEnvironmentVariableReader environmentVariableReader, bool bypassCache = false)
{
if (!JsonUtility.UseNewstonSoftJsonForParsing(environmentVariableReader, bypassCache))
if (JsonUtility.UseNewstonSoftJsonForParsing(environmentVariableReader, bypassCache))
{
return Utf8JsonRead(stream, log, path);
}
Expand Down Expand Up @@ -284,7 +284,7 @@ private static LockFileLibrary ReadLibrary(string property, JToken json)
library.Name = parts[0];
if (parts.Length == 2)
{
library.Version = JsonUtility.ParseNugetVersion(parts[1]);
library.Version = NuGetVersion.Parse(parts[1]);
}

library.Type = ReadString(json[TypeProperty]);
Expand Down Expand Up @@ -560,7 +560,7 @@ private static LockFileTargetLibrary ReadTargetLibrary(string property, JToken j
else
{
library.Name = property.Substring(0, slashIndex);
library.Version = JsonUtility.ParseNugetVersion(property.Substring(slashIndex + 1));
library.Version = NuGetVersion.Parse(property.Substring(slashIndex + 1));
}

var jObject = json as JObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public LockFileLibrary Read(ref Utf8JsonStreamReader reader)
lockFileLibrary.Name = name;
if (!string.IsNullOrWhiteSpace(version))
{
lockFileLibrary.Version = JsonUtility.ParseNugetVersion(version);
lockFileLibrary.Version = NuGetVersion.Parse(version);
}

reader.Read();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public LockFileTargetLibrary Read(ref Utf8JsonStreamReader reader)
var propertyName = reader.GetString();
var (targetLibraryName, version) = propertyName.SplitInTwo('/');
lockFileTargetLibrary.Name = targetLibraryName;
lockFileTargetLibrary.Version = version is null ? null : JsonUtility.ParseNugetVersion(version);
lockFileTargetLibrary.Version = version is null ? null : NuGetVersion.Parse(version);

reader.Read();
if (reader.TokenType != JsonTokenType.StartObject)
Expand Down Expand Up @@ -149,7 +149,7 @@ private IList<PackageDependency> ReadPackageDependencyList(ref Utf8JsonStreamRea
string versionString = reader.ReadNextTokenAsString();
packageDependencies.Add(new PackageDependency(
propertyName,
versionString == null ? null : JsonUtility.ParseVersionRange(versionString)));
versionString == null ? null : VersionRange.Parse(versionString)));
}
return packageDependencies;
}
Expand Down
4 changes: 2 additions & 2 deletions src/NuGet.Core/NuGet.ProjectModel/PackageSpecUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static NuGetVersion SpecifySnapshot(string version, string snapshotValue)
}
}

return JsonUtility.ParseNugetVersion(version);
return NuGetVersion.Parse(version);
}

/// <summary>
Expand All @@ -44,7 +44,7 @@ public static bool IsSnapshotVersion(string version)
{
// Verify the version is valid
NuGetVersion parsed = null;
return JsonUtility.TryParseNugetVersion(version.Substring(0, version.Length - 2), out parsed);
return NuGetVersion.TryParse(version.Substring(0, version.Length - 2), out parsed);
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,7 @@ public void LockFileFormat_WritesCentralTransitiveDependencyGroups()
Assert.Equal(expected.ToString(), output.ToString());
}

public static LockFile Read(string filePath, IEnvironmentVariableReader environmentVariableReader)
private LockFile Read(string filePath, IEnvironmentVariableReader environmentVariableReader)
{
var reader = new LockFileFormat();
using (var stream = File.OpenRead(filePath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,12 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using NuGet.Common;
using Test.Utility;

namespace NuGet.ProjectModel.Test
namespace NuGet.ProjectModel
{
public class LockFileParsingEnvironmentVariable
{
public static readonly IEnvironmentVariableReader UseNjForProcessingEnvironmentVariable = new TestEnvironmentVariableReader(
new Dictionary<string, string>()
{
["NUGET_EXPERIMENTAL_USE_NJ_FOR_FILE_PARSING"] = bool.TrueString
}, "NUGET_EXPERIMENTAL_USE_NJ_FOR_FILE_PARSING: true");

public static readonly IEnvironmentVariableReader UseStjForProcessingEnvironmentVariable = new TestEnvironmentVariableReader(
new Dictionary<string, string>()
{
["NUGET_EXPERIMENTAL_USE_NJ_FOR_FILE_PARSING"] = bool.FalseString
}, "NUGET_EXPERIMENTAL_USE_NJ_FOR_FILE_PARSING: false");

public static IEnumerable<object[]> TestEnvironmentVariableReader()
{
return GetTestEnvironmentVariableReader();
Expand All @@ -43,8 +30,20 @@ public static IEnumerable<object[]> TestEnvironmentVariableReader(object value1,

private static IEnumerable<object[]> GetTestEnvironmentVariableReader(params object[] objects)
{
var UseNjForFileTrue = new List<object> { UseNjForProcessingEnvironmentVariable };
var UseNjForFileFalse = new List<object> { UseStjForProcessingEnvironmentVariable };
var UseNjForFileTrue = new List<object> {
new TestEnvironmentVariableReader(
new Dictionary<string, string>()
{
["NUGET_EXPERIMENTAL_USE_NJ_FOR_FILE_PARSING"] = bool.TrueString
}, "NUGET_EXPERIMENTAL_USE_NJ_FOR_FILE_PARSING: true")
};
var UseNjForFileFalse = new List<object> {
new TestEnvironmentVariableReader(
new Dictionary<string, string>()
{
["NUGET_EXPERIMENTAL_USE_NJ_FOR_FILE_PARSING"] = bool.FalseString
}, "NUGET_EXPERIMENTAL_USE_NJ_FOR_FILE_PARSING: false")
};

if (objects != null)
{
Expand Down