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
Fixes from PR
  • Loading branch information
jgonz120 committed Jan 11, 2024
commit 08835675183f84a816190a07e0c2891472480b8f
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Text.Json;

namespace NuGet.ProjectModel
Expand All @@ -10,6 +11,13 @@ namespace NuGet.ProjectModel
/// </summary>
internal class Utf8JsonStreamLockFileItemConverter<T> : IUtf8JsonStreamReaderConverter<T> where T : LockFileItem
{
private Func<string, T> _lockFileItemCreator;

public Utf8JsonStreamLockFileItemConverter(Func<string, T> lockFileItemCreator)
{
_lockFileItemCreator = lockFileItemCreator;
}

public T Read(ref Utf8JsonStreamReader reader)
{
var genericType = typeof(T);
Expand All @@ -21,19 +29,7 @@ public T Read(ref Utf8JsonStreamReader reader)

//We want to read the property name right away
var lockItemPath = reader.GetString();
LockFileItem lockFileItem;
if (genericType == typeof(LockFileContentFile))
{
lockFileItem = new LockFileContentFile(lockItemPath);
}
else if (genericType == typeof(LockFileRuntimeTarget))
{
lockFileItem = new LockFileRuntimeTarget(lockItemPath);
}
else
{
lockFileItem = new LockFileItem(lockItemPath);
}
LockFileItem lockFileItem = _lockFileItemCreator(lockItemPath);

reader.Read();
if (reader.TokenType == JsonTokenType.StartObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Text;
using System.Text.Json;
using NuGet.Packaging.Core;
using NuGet.Versioning;

namespace NuGet.ProjectModel
{
Expand Down Expand Up @@ -70,7 +69,7 @@ public LockFileTargetLibrary Read(ref Utf8JsonStreamReader reader)
else if (reader.ValueTextEquals(FrameworkAssembliesPropertyName))
{
reader.Read();
lockFileTargetLibrary.FrameworkAssemblies = reader.ReadStringArrayAsIList(new List<string>());
lockFileTargetLibrary.FrameworkAssemblies = reader.ReadStringArrayAsIList() ?? Array.Empty<string>();
}
else if (reader.ValueTextEquals(RuntimePropertyName))
{
Expand Down Expand Up @@ -143,12 +142,11 @@ private IList<PackageDependency> ReadPackageDependencyList(ref Utf8JsonStreamRea
return Array.Empty<PackageDependency>();
}

var packageDependencies = new List<PackageDependency>();
var packageDependencies = new List<PackageDependency>(10);
while (reader.Read() && reader.TokenType == JsonTokenType.PropertyName)
{
string propertyName = reader.GetString();
string versionString = reader.ReadNextTokenAsString();

packageDependencies.Add(new PackageDependency(
propertyName,
versionString == null ? null : JsonUtility.ParseVersionRange(versionString)));
Expand Down
9 changes: 3 additions & 6 deletions src/NuGet.Core/NuGet.ProjectModel/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable

using System;
using System.Globalization;

namespace NuGet.ProjectModel
{
Expand All @@ -14,11 +14,8 @@ internal static (string firstPart, string? secondPart) SplitInTwo(this string s,
{
return (s, null);
}
#if NETCOREAPP2_1_OR_GREATER
var index = s.IndexOf(separator, StringComparison.OrdinalIgnoreCase);
#else
var index = s.IndexOf(separator.ToString(), StringComparison.OrdinalIgnoreCase);
#endif
var index = CultureInfo.CurrentCulture.CompareInfo.IndexOf(s, separator, CompareOptions.Ordinal);

if (index == -1)
{
return (s, null);
Expand Down
6 changes: 3 additions & 3 deletions src/NuGet.Core/NuGet.ProjectModel/Utf8JsonReaderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace NuGet.ProjectModel
internal static class Utf8JsonReaderExtensions
{
internal static readonly Utf8JsonStreamLockFileConverter LockFileConverter = new Utf8JsonStreamLockFileConverter();
internal static readonly Utf8JsonStreamLockFileItemConverter<LockFileItem> LockFileItemConverter = new Utf8JsonStreamLockFileItemConverter<LockFileItem>();
internal static readonly Utf8JsonStreamLockFileItemConverter<LockFileContentFile> LockFileContentFileConverter = new Utf8JsonStreamLockFileItemConverter<LockFileContentFile>();
internal static readonly Utf8JsonStreamLockFileItemConverter<LockFileRuntimeTarget> LockFileRuntimeTargetConverter = new Utf8JsonStreamLockFileItemConverter<LockFileRuntimeTarget>();
internal static readonly Utf8JsonStreamLockFileItemConverter<LockFileItem> LockFileItemConverter = new Utf8JsonStreamLockFileItemConverter<LockFileItem>((string filePath) => new LockFileItem(filePath));
internal static readonly Utf8JsonStreamLockFileItemConverter<LockFileContentFile> LockFileContentFileConverter = new Utf8JsonStreamLockFileItemConverter<LockFileContentFile>((string filePath) => new LockFileContentFile(filePath));
internal static readonly Utf8JsonStreamLockFileItemConverter<LockFileRuntimeTarget> LockFileRuntimeTargetConverter = new Utf8JsonStreamLockFileItemConverter<LockFileRuntimeTarget>((string filePath) => new LockFileRuntimeTarget(filePath));
internal static readonly Utf8JsonStreamLockFileTargetLibraryConverter LockFileTargetLibraryConverter = new Utf8JsonStreamLockFileTargetLibraryConverter();
internal static readonly Utf8JsonStreamLockFileLibraryConverter LockFileLibraryConverter = new Utf8JsonStreamLockFileLibraryConverter();
internal static readonly Utf8JsonStreamLockFileTargetConverter LockFileTargetConverter = new Utf8JsonStreamLockFileTargetConverter();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using System;
using System.Text.Json;

namespace NuGet.ProjectModel
Expand All @@ -20,7 +20,7 @@ public ProjectFileDependencyGroup Read(ref Utf8JsonStreamReader reader)

var frameworkName = reader.GetString();
reader.Read();
var dependencies = reader.ReadStringArrayAsIList(new List<string>());
var dependencies = reader.ReadStringArrayAsIList() ?? Array.Empty<string>();

return new ProjectFileDependencyGroup(frameworkName, dependencies);
}
Expand Down