dependabot-nuget 0.240.0 → 0.242.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/helpers/build +45 -0
- data/helpers/lib/NuGetUpdater/.editorconfig +364 -0
- data/helpers/lib/NuGetUpdater/.gitignore +5 -0
- data/helpers/lib/NuGetUpdater/Directory.Build.props +10 -0
- data/helpers/lib/NuGetUpdater/Directory.Common.props +16 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Build.props +14 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Build.targets +7 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/Directory.Packages.props +29 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Build.Tasks/NuGet.Build.Tasks.csproj +27 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.CommandLine/AssemblyMetadataExtractor.cs +203 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.CommandLine/NuGet.CommandLine.csproj +33 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Commands/NuGet.Commands.csproj +26 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Common/NuGet.Common.csproj +21 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Config +6 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Configuration/NuGet.Configuration.csproj +24 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Credentials/NuGet.Credentials.csproj +20 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.DependencyResolver.Core/NuGet.DependencyResolver.Core.csproj +22 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Frameworks/NuGet.Frameworks.csproj +17 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.LibraryModel/NuGet.LibraryModel.csproj +17 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.PackageManagement/NuGet.PackageManagement.csproj +27 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Packaging/NuGet.Packaging.csproj +28 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.ProjectModel/NuGet.ProjectModel.csproj +20 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Protocol/NuGet.Protocol.csproj +21 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Resolver/NuGet.Resolver.csproj +20 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/NuGet.Versioning/NuGet.Versioning.csproj +17 -0
- data/helpers/lib/NuGetUpdater/NuGetProjects/README.md +1 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/FrameworkCheckCommand.cs +35 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Commands/UpdateCommand.cs +43 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/NuGetUpdater.Cli.csproj +20 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli/Program.cs +31 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.FrameworkCheck.cs +42 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/EntryPointTests.Update.cs +323 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Cli.Test/NuGetUpdater.Cli.Test.csproj +24 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Dependency.cs +3 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/DependencyType.cs +12 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/BuildFile.cs +97 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/DotNetToolsJsonBuildFile.cs +23 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/GlobalJsonBuildFile.cs +36 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/JsonBuildFile.cs +47 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/PackagesConfigBuildFile.cs +31 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/ProjectBuildFile.cs +94 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Files/XmlBuildFile.cs +14 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/CompatabilityChecker.cs +39 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/FrameworkCompatibilityService.cs +73 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/FrameworkChecker/SupportedFrameworks.cs +146 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/NuGetUpdater.Core.csproj +27 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectManager.cs +316 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/BindingRedirectResolver.cs +87 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/ConfigurationFile.cs +3 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/DotNetToolsJsonUpdater.cs +66 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/GlobalJsonUpdater.cs +48 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/PackagesConfigUpdater.cs +172 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/SdkPackageUpdater.cs +498 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdateResult.cs +7 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs +105 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/JsonHelper.cs +222 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/Logger.cs +24 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/MSBuildHelper.cs +460 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/NuGetHelper.cs +15 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/PathHelper.cs +69 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ProcessExtensions.cs +83 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/XmlExtensions.cs +124 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/DotNetToolsJsonBuildFileTests.cs +53 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/GlobalJsonBuildFileTests.cs +80 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/PackagesConfigBuildFileTests.cs +63 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Files/ProjectBuildFileTests.cs +154 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/CompatibilityCheckerFacts.cs +64 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/FrameworkCompatibilityServiceFacts.cs +122 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/FrameworkChecker/SupportedFrameworkFacts.cs +68 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/NuGetUpdater.Core.Test.csproj +23 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TemporaryDirectory.cs +36 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestExtensions.cs +15 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/PackagesConfigUpdaterTests.cs +79 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorker.DirsProj.cs +201 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTestBase.cs +147 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.DotNetTools.cs +225 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.GlobalJson.cs +217 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Mixed.cs +94 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs +938 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.Sdk.cs +2177 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/JsonHelperTests.cs +239 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/MSBuildHelperTests.cs +598 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterHelperTests.cs +179 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/SdkPackageUpdaterTests.cs +238 -0
- data/helpers/lib/NuGetUpdater/NuGetUpdater.sln +152 -0
- data/helpers/lib/NuGetUpdater/xunit.runner.json +4 -0
- data/lib/dependabot/nuget/metadata_finder.rb +4 -4
- metadata +91 -5
@@ -0,0 +1,222 @@
|
|
1
|
+
using System;
|
2
|
+
using System.Collections.Generic;
|
3
|
+
using System.IO;
|
4
|
+
using System.Linq;
|
5
|
+
using System.Runtime.InteropServices;
|
6
|
+
using System.Text;
|
7
|
+
using System.Text.Json;
|
8
|
+
using System.Text.Json.Nodes;
|
9
|
+
|
10
|
+
namespace NuGetUpdater.Core.Utilities
|
11
|
+
{
|
12
|
+
internal static class JsonHelper
|
13
|
+
{
|
14
|
+
public static JsonDocumentOptions DocumentOptions { get; } = new JsonDocumentOptions()
|
15
|
+
{
|
16
|
+
CommentHandling = JsonCommentHandling.Skip,
|
17
|
+
};
|
18
|
+
|
19
|
+
public static JsonNode? ParseNode(string content)
|
20
|
+
{
|
21
|
+
var node = JsonNode.Parse(content, documentOptions: DocumentOptions);
|
22
|
+
return node;
|
23
|
+
}
|
24
|
+
|
25
|
+
public static string UpdateJsonProperty(string json, string[] propertyPath, string newValue, StringComparison comparisonType = StringComparison.Ordinal)
|
26
|
+
{
|
27
|
+
var readerOptions = new JsonReaderOptions()
|
28
|
+
{
|
29
|
+
CommentHandling = JsonCommentHandling.Allow,
|
30
|
+
};
|
31
|
+
var bytes = Encoding.UTF8.GetBytes(json);
|
32
|
+
var reader = new Utf8JsonReader(bytes, readerOptions);
|
33
|
+
using var ms = new MemoryStream();
|
34
|
+
var writerOptions = new JsonWriterOptions()
|
35
|
+
{
|
36
|
+
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
37
|
+
Indented = true,
|
38
|
+
};
|
39
|
+
var writer = new Utf8JsonWriter(ms, writerOptions);
|
40
|
+
|
41
|
+
var pathDepth = -1;
|
42
|
+
var currentPath = new List<string>();
|
43
|
+
var replaceNextToken = false;
|
44
|
+
while (reader.Read())
|
45
|
+
{
|
46
|
+
if (replaceNextToken)
|
47
|
+
{
|
48
|
+
// replace this specific token
|
49
|
+
writer.WriteStringValue(newValue);
|
50
|
+
replaceNextToken = false;
|
51
|
+
}
|
52
|
+
else
|
53
|
+
{
|
54
|
+
// just mirror the token
|
55
|
+
switch (reader.TokenType)
|
56
|
+
{
|
57
|
+
case JsonTokenType.Comment:
|
58
|
+
var commentValue = reader.GetComment();
|
59
|
+
var commentStart = json.Substring((int)reader.TokenStartIndex, 2);
|
60
|
+
if (commentStart == "//")
|
61
|
+
{
|
62
|
+
// Utf8JsonWriter only supports block comments, so we have to manually inject a single line comment when appropriate
|
63
|
+
writer.Flush();
|
64
|
+
var commentPrefix = GetCurrentTokenTriviaPrefix((int)reader.TokenStartIndex, json);
|
65
|
+
ms.Write(Encoding.UTF8.GetBytes(commentPrefix));
|
66
|
+
ms.Write(Encoding.UTF8.GetBytes("//" + commentValue));
|
67
|
+
}
|
68
|
+
else
|
69
|
+
{
|
70
|
+
// let the default block comment writer handle it
|
71
|
+
writer.WriteCommentValue(reader.GetComment());
|
72
|
+
}
|
73
|
+
break;
|
74
|
+
case JsonTokenType.EndArray:
|
75
|
+
writer.WriteEndArray();
|
76
|
+
break;
|
77
|
+
case JsonTokenType.EndObject:
|
78
|
+
writer.WriteEndObject();
|
79
|
+
pathDepth--;
|
80
|
+
break;
|
81
|
+
case JsonTokenType.False:
|
82
|
+
writer.WriteBooleanValue(false);
|
83
|
+
break;
|
84
|
+
case JsonTokenType.None:
|
85
|
+
// do nothing
|
86
|
+
break;
|
87
|
+
case JsonTokenType.Null:
|
88
|
+
writer.WriteNullValue();
|
89
|
+
break;
|
90
|
+
case JsonTokenType.Number:
|
91
|
+
writer.WriteNumberValue(reader.GetDouble());
|
92
|
+
break;
|
93
|
+
case JsonTokenType.PropertyName:
|
94
|
+
writer.WritePropertyName(reader.GetString()!);
|
95
|
+
break;
|
96
|
+
case JsonTokenType.StartArray:
|
97
|
+
writer.WriteStartArray();
|
98
|
+
break;
|
99
|
+
case JsonTokenType.StartObject:
|
100
|
+
writer.WriteStartObject();
|
101
|
+
pathDepth++;
|
102
|
+
break;
|
103
|
+
case JsonTokenType.String:
|
104
|
+
writer.WriteStringValue(reader.GetString());
|
105
|
+
break;
|
106
|
+
case JsonTokenType.True:
|
107
|
+
writer.WriteBooleanValue(true);
|
108
|
+
break;
|
109
|
+
default:
|
110
|
+
throw new NotImplementedException($"Unexpected token type: {reader.TokenType}");
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
// see if we need to replace the next token
|
115
|
+
if (reader.TokenType == JsonTokenType.PropertyName)
|
116
|
+
{
|
117
|
+
var pathValue = reader.GetString()!;
|
118
|
+
|
119
|
+
// ensure the current path object is of the correct size
|
120
|
+
while (currentPath.Count < pathDepth + 1)
|
121
|
+
{
|
122
|
+
currentPath.Add(string.Empty);
|
123
|
+
}
|
124
|
+
|
125
|
+
while (currentPath.Count > 0 && currentPath.Count > pathDepth + 1)
|
126
|
+
{
|
127
|
+
currentPath.RemoveAt(currentPath.Count - 1);
|
128
|
+
}
|
129
|
+
|
130
|
+
currentPath[pathDepth] = pathValue;
|
131
|
+
if (IsPathMatch(currentPath, propertyPath, comparisonType))
|
132
|
+
{
|
133
|
+
replaceNextToken = true;
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
|
+
writer.Flush();
|
139
|
+
ms.Flush();
|
140
|
+
ms.Seek(0, SeekOrigin.Begin);
|
141
|
+
var resultBytes = ms.ToArray();
|
142
|
+
var resultJson = Encoding.UTF8.GetString(resultBytes);
|
143
|
+
|
144
|
+
// single line comments might have had a trailing comma appended by the property writer that we can't
|
145
|
+
// control, so we have to manually correct for it
|
146
|
+
var originalJsonLines = json.Split('\n').Select(l => l.TrimEnd('\r')).ToArray();
|
147
|
+
var updatedJsonLines = resultJson.Split('\n').Select(l => l.TrimEnd('\r')).ToArray();
|
148
|
+
for (int i = 0; i < Math.Min(originalJsonLines.Length, updatedJsonLines.Length); i++)
|
149
|
+
{
|
150
|
+
if (updatedJsonLines[i].EndsWith(",") && !originalJsonLines[i].EndsWith(","))
|
151
|
+
{
|
152
|
+
updatedJsonLines[i] = updatedJsonLines[i][..^1];
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
|
157
|
+
resultJson = string.Join('\n', updatedJsonLines);
|
158
|
+
|
159
|
+
// the JSON writer doesn't properly maintain newlines, so we need to normalize everything
|
160
|
+
resultJson = resultJson.Replace("\r\n", "\n"); // CRLF => LF
|
161
|
+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
162
|
+
{
|
163
|
+
resultJson = resultJson.Replace("\n", "\r\n"); // LF => CRLF
|
164
|
+
}
|
165
|
+
|
166
|
+
return resultJson;
|
167
|
+
}
|
168
|
+
|
169
|
+
private static bool IsPathMatch(List<string> currentPath, string[] expectedPath, StringComparison comparisonType) =>
|
170
|
+
currentPath.Count == expectedPath.Length &&
|
171
|
+
currentPath.Zip(expectedPath).All(pair => string.Compare(pair.First, pair.Second, comparisonType) == 0);
|
172
|
+
|
173
|
+
private static string GetCurrentTokenTriviaPrefix(int tokenStartIndex, string originalJson)
|
174
|
+
{
|
175
|
+
var prefixStart = tokenStartIndex - 1;
|
176
|
+
for (; prefixStart >= 0; prefixStart--)
|
177
|
+
{
|
178
|
+
var c = originalJson[prefixStart];
|
179
|
+
switch (c)
|
180
|
+
{
|
181
|
+
case ' ':
|
182
|
+
case '\t':
|
183
|
+
// just more whitespace; keep looking
|
184
|
+
break;
|
185
|
+
case '\r':
|
186
|
+
case '\n':
|
187
|
+
// quit at newline, modulo some special cases
|
188
|
+
if (c == '\n')
|
189
|
+
{
|
190
|
+
// check for preceeding CR
|
191
|
+
if (IsPreceedingCharacterEqual(originalJson, prefixStart, '\r'))
|
192
|
+
{
|
193
|
+
prefixStart--;
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
197
|
+
// check for preceeding comma
|
198
|
+
if (IsPreceedingCharacterEqual(originalJson, prefixStart, ','))
|
199
|
+
{
|
200
|
+
prefixStart--;
|
201
|
+
}
|
202
|
+
goto done;
|
203
|
+
default:
|
204
|
+
// found regular character; move forward one and quit
|
205
|
+
prefixStart++;
|
206
|
+
goto done;
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
done:
|
211
|
+
var prefix = originalJson.Substring(prefixStart, tokenStartIndex - prefixStart);
|
212
|
+
return prefix;
|
213
|
+
}
|
214
|
+
|
215
|
+
private static bool IsPreceedingCharacterEqual(string originalText, int currentIndex, char expectedCharacter)
|
216
|
+
{
|
217
|
+
return currentIndex > 0
|
218
|
+
&& currentIndex < originalText.Length
|
219
|
+
&& originalText[currentIndex - 1] == expectedCharacter;
|
220
|
+
}
|
221
|
+
}
|
222
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
using System;
|
2
|
+
using System.IO;
|
3
|
+
|
4
|
+
namespace NuGetUpdater.Core;
|
5
|
+
|
6
|
+
public sealed class Logger
|
7
|
+
{
|
8
|
+
public bool Verbose { get; set; }
|
9
|
+
private readonly TextWriter _logOutput;
|
10
|
+
|
11
|
+
public Logger(bool verbose)
|
12
|
+
{
|
13
|
+
Verbose = verbose;
|
14
|
+
_logOutput = Console.Out;
|
15
|
+
}
|
16
|
+
|
17
|
+
public void Log(string message)
|
18
|
+
{
|
19
|
+
if (Verbose)
|
20
|
+
{
|
21
|
+
_logOutput.WriteLine(message);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|