From 7fda7e55a1d8a0e42c80b7bf4227a57d103b7ffe Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Fri, 21 Feb 2025 15:42:44 +0000 Subject: [PATCH 1/9] Switch more over to System.Text.Json --- .../Tasks/BuildAppBundle.cs | 30 +++++----- .../Tasks/JavaDependencyVerification.cs | 11 ++-- .../Utilities/JsonExtensions.cs | 58 +++++++++++++++++++ 3 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 src/Xamarin.Android.Build.Tasks/Utilities/JsonExtensions.cs diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs b/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs index aeb91b1f25c..13d730106eb 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs @@ -1,7 +1,7 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using System.Text.Json; +using System.Text.Json.Nodes; using System; using System.Collections.Generic; using System.IO; @@ -88,26 +88,24 @@ public override bool RunTask () } } - var json = JObject.FromObject (new { }); + JsonNode json = JsonNode.Parse("{}"); if (!string.IsNullOrEmpty (CustomBuildConfigFile) && File.Exists (CustomBuildConfigFile)) { - using (StreamReader file = File.OpenText (CustomBuildConfigFile)) - using (JsonTextReader reader = new JsonTextReader (file)) { - json = (JObject)JToken.ReadFrom(reader); - } + using Stream fs = File.OpenRead (CustomBuildConfigFile); + json = JsonNode.Parse (fs); } - var jsonAddition = JObject.FromObject (new { + var jsonAddition = new { compression = new { uncompressedGlob = uncompressed, } - }); - - var mergeSettings = new JsonMergeSettings () { - MergeArrayHandling = MergeArrayHandling.Union, - MergeNullValueHandling = MergeNullValueHandling.Ignore }; - json.Merge (jsonAddition, mergeSettings); - Log.LogDebugMessage ("BundleConfig.json: {0}", json); - File.WriteAllText (temp, json.ToString ()); + + var jsonAdditionDoc = JsonSerializer.SerializeToNode(jsonAddition); + + var mergedJson = json.Merge(jsonAdditionDoc); + var output = mergedJson.ToJsonString(new JsonSerializerOptions { WriteIndented = true }); + + Log.LogDebugMessage ("BundleConfig.json: {0}", output); + File.WriteAllText (temp, output); //NOTE: bundletool will not overwrite if (File.Exists (Output)) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs b/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs index 5ccd8309b75..c5e6f9f741d 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs @@ -11,7 +11,8 @@ using Microsoft.Android.Build.Tasks; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; -using Newtonsoft.Json; +using System.Text.Json; +using System.Text.Json.Serialization; using NuGet.ProjectModel; namespace Xamarin.Android.Tasks; @@ -318,7 +319,7 @@ public MicrosoftNuGetPackageFinder (string? file, TaskLoggingHelper log) try { var json = File.ReadAllText (file); - package_list = JsonConvert.DeserializeObject (json); + package_list = JsonSerializer.Deserialize (json); } catch (Exception ex) { log.LogMessage ("There was an error reading 'microsoft-packages.json', Android NuGet suggestions will not be provided: {0}", ex); } @@ -331,16 +332,16 @@ public MicrosoftNuGetPackageFinder (string? file, TaskLoggingHelper log) public class PackageListFile { - [JsonProperty ("packages")] + [JsonPropertyName ("packages")] public List? Packages { get; set; } } public class Package { - [JsonProperty ("javaId")] + [JsonPropertyName ("javaId")] public string? JavaId { get; set; } - [JsonProperty ("nugetId")] + [JsonPropertyName ("nugetId")] public string? NuGetId { get; set; } } } diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/JsonExtensions.cs b/src/Xamarin.Android.Build.Tasks/Utilities/JsonExtensions.cs new file mode 100644 index 00000000000..67e91bf509f --- /dev/null +++ b/src/Xamarin.Android.Build.Tasks/Utilities/JsonExtensions.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Nodes; + +public static class JsonExtensions +{ + public static JsonNode Merge(this JsonNode jsonBase, JsonNode jsonMerge) + { + if (jsonBase == null || jsonMerge == null) + return jsonBase; + + switch (jsonBase) + { + case JsonObject jsonBaseObj when jsonMerge is JsonObject jsonMergeObj: + { + var mergeNodesArray = new KeyValuePair[jsonMergeObj.Count]; + int index = 0; + foreach (var prop in jsonMergeObj) + { + mergeNodesArray[index++] = prop; + } + jsonMergeObj.Clear(); + + foreach (var prop in mergeNodesArray) + { + jsonBaseObj[prop.Key] = jsonBaseObj[prop.Key] switch + { + JsonObject jsonBaseChildObj when prop.Value is JsonObject jsonMergeChildObj => jsonBaseChildObj.Merge(jsonMergeChildObj), + JsonArray jsonBaseChildArray when prop.Value is JsonArray jsonMergeChildArray => jsonBaseChildArray.Merge(jsonMergeChildArray), + _ => prop.Value + }; + } + break; + } + case JsonArray jsonBaseArray when jsonMerge is JsonArray jsonMergeArray: + { + var mergeNodesArray = new JsonNode?[jsonMergeArray.Count]; + int index = 0; + foreach (var mergeNode in jsonMergeArray) + { + mergeNodesArray[index++] = mergeNode; + } + jsonMergeArray.Clear(); + foreach (var mergeNode in mergeNodesArray) + { + jsonBaseArray.Add(mergeNode); + } + break; + } + default: + throw new ArgumentException($"The JsonNode type [{jsonBase.GetType().Name}] is incompatible for merging with the target/base " + + $"type [{jsonMerge.GetType().Name}]; merge requires the types to be the same."); + } + + return jsonBase; + } +} \ No newline at end of file From a763c57d7a5807f710f599efc63a54bbaf0e21f9 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Fri, 21 Feb 2025 16:43:58 +0000 Subject: [PATCH 2/9] Remove Newtonsoft.Json package reference --- build-tools/installers/create-installers.targets | 1 - .../Xamarin.Android.Build.Tasks.csproj | 1 - 2 files changed, 2 deletions(-) diff --git a/build-tools/installers/create-installers.targets b/build-tools/installers/create-installers.targets index 2131682f2eb..d7ed385f907 100644 --- a/build-tools/installers/create-installers.targets +++ b/build-tools/installers/create-installers.targets @@ -116,7 +116,6 @@ <_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)Mono.Options.dll" /> <_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)Mono.Options.pdb" /> <_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)MULTIDEX_JAR_LICENSE" /> - <_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)Newtonsoft.Json.dll" /> <_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)NuGet.Common.dll" /> <_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)NuGet.Configuration.dll" /> <_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)NuGet.DependencyResolver.Core.dll" /> diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj index 98e552cdf44..1eef89eeb0c 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj @@ -29,7 +29,6 @@ - From e9ac79d7eefbc0d990c86d23df1a1a4b2dc59fb2 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Fri, 21 Feb 2025 16:46:34 +0000 Subject: [PATCH 3/9] Formatting --- .../Utilities/JsonExtensions.cs | 66 ++++++++----------- 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/JsonExtensions.cs b/src/Xamarin.Android.Build.Tasks/Utilities/JsonExtensions.cs index 67e91bf509f..7aa1d0fe7da 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/JsonExtensions.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/JsonExtensions.cs @@ -5,54 +5,46 @@ public static class JsonExtensions { - public static JsonNode Merge(this JsonNode jsonBase, JsonNode jsonMerge) + public static JsonNode Merge (this JsonNode jsonBase, JsonNode jsonMerge) { if (jsonBase == null || jsonMerge == null) return jsonBase; switch (jsonBase) { - case JsonObject jsonBaseObj when jsonMerge is JsonObject jsonMergeObj: - { - var mergeNodesArray = new KeyValuePair[jsonMergeObj.Count]; - int index = 0; - foreach (var prop in jsonMergeObj) - { - mergeNodesArray[index++] = prop; - } - jsonMergeObj.Clear(); + case JsonObject jsonBaseObj when jsonMerge is JsonObject jsonMergeObj: { + var mergeNodesArray = new KeyValuePair [jsonMergeObj.Count]; + int index = 0; + foreach (var prop in jsonMergeObj) { + mergeNodesArray [index++] = prop; + } + jsonMergeObj.Clear (); - foreach (var prop in mergeNodesArray) - { - jsonBaseObj[prop.Key] = jsonBaseObj[prop.Key] switch - { - JsonObject jsonBaseChildObj when prop.Value is JsonObject jsonMergeChildObj => jsonBaseChildObj.Merge(jsonMergeChildObj), - JsonArray jsonBaseChildArray when prop.Value is JsonArray jsonMergeChildArray => jsonBaseChildArray.Merge(jsonMergeChildArray), - _ => prop.Value - }; - } - break; + foreach (var prop in mergeNodesArray) { + jsonBaseObj [prop.Key] = jsonBaseObj [prop.Key] switch { + JsonObject jsonBaseChildObj when prop.Value is JsonObject jsonMergeChildObj => jsonBaseChildObj.Merge (jsonMergeChildObj), + JsonArray jsonBaseChildArray when prop.Value is JsonArray jsonMergeChildArray => jsonBaseChildArray.Merge (jsonMergeChildArray), + _ => prop.Value + }; + } + break; + } + case JsonArray jsonBaseArray when jsonMerge is JsonArray jsonMergeArray: { + var mergeNodesArray = new JsonNode? [jsonMergeArray.Count]; + int index = 0; + foreach (var mergeNode in jsonMergeArray) { + mergeNodesArray [index++] = mergeNode; } - case JsonArray jsonBaseArray when jsonMerge is JsonArray jsonMergeArray: - { - var mergeNodesArray = new JsonNode?[jsonMergeArray.Count]; - int index = 0; - foreach (var mergeNode in jsonMergeArray) - { - mergeNodesArray[index++] = mergeNode; - } - jsonMergeArray.Clear(); - foreach (var mergeNode in mergeNodesArray) - { - jsonBaseArray.Add(mergeNode); - } - break; + jsonMergeArray.Clear (); + foreach (var mergeNode in mergeNodesArray) { + jsonBaseArray.Add (mergeNode); } + break; + } default: - throw new ArgumentException($"The JsonNode type [{jsonBase.GetType().Name}] is incompatible for merging with the target/base " + - $"type [{jsonMerge.GetType().Name}]; merge requires the types to be the same."); + throw new ArgumentException ($"The JsonNode type [{jsonBase.GetType ().Name}] is incompatible for merging with the target/base " + + $"type [{jsonMerge.GetType ().Name}]; merge requires the types to be the same."); } - return jsonBase; } } \ No newline at end of file From 7d5fba548b5e3f3d50bd1e2b40be731891ea3157 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Fri, 21 Feb 2025 16:47:33 +0000 Subject: [PATCH 4/9] Formatting --- src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs b/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs index 13d730106eb..720971d5fc8 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs @@ -99,10 +99,10 @@ public override bool RunTask () } }; - var jsonAdditionDoc = JsonSerializer.SerializeToNode(jsonAddition); + var jsonAdditionDoc = JsonSerializer.SerializeToNode (jsonAddition); - var mergedJson = json.Merge(jsonAdditionDoc); - var output = mergedJson.ToJsonString(new JsonSerializerOptions { WriteIndented = true }); + var mergedJson = json.Merge (jsonAdditionDoc); + var output = mergedJson.ToJsonString (new JsonSerializerOptions { WriteIndented = true }); Log.LogDebugMessage ("BundleConfig.json: {0}", output); File.WriteAllText (temp, output); From b0f9e6e2d278cf1f8bd682821760caac343b2507 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Mon, 24 Feb 2025 13:12:41 +0000 Subject: [PATCH 5/9] Fix some build errors --- .../Tasks/BuildAppBundle.cs | 25 +++++++------ .../Utilities/JsonExtensions.cs | 37 +++++++++++++++++++ .../Utilities/MamJsonParser.cs | 7 ++-- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs b/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs index 720971d5fc8..2333966d18c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs @@ -60,27 +60,27 @@ public class BuildAppBundle : BundleTool }; [Required] - public string BaseZip { get; set; } + public string BaseZip { get; set; } = ""; - public string CustomBuildConfigFile { get; set; } + public string? CustomBuildConfigFile { get; set; } - public string [] Modules { get; set; } + public string []? Modules { get; set; } - public ITaskItem [] MetaDataFiles { get; set; } + public ITaskItem []? MetaDataFiles { get; set; } [Required] - public string Output { get; set; } + public string Output { get; set; } = ""; - public string UncompressedFileExtensions { get; set; } + public string? UncompressedFileExtensions { get; set; } - string temp; + string temp = ""; public override bool RunTask () { temp = Path.GetTempFileName (); try { var uncompressed = new List (UncompressedByDefault); - if (!string.IsNullOrEmpty (UncompressedFileExtensions)) { + if (UncompressedFileExtensions is { Length: > 0 }) { //NOTE: these are file extensions, that need converted to glob syntax var split = UncompressedFileExtensions.Split (new char [] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var extension in split) { @@ -88,10 +88,11 @@ public override bool RunTask () } } - JsonNode json = JsonNode.Parse("{}"); - if (!string.IsNullOrEmpty (CustomBuildConfigFile) && File.Exists (CustomBuildConfigFile)) { + JsonNode json = JsonNode.Parse ("{}")!; + if (CustomBuildConfigFile is { Length: > 0 } && File.Exists (CustomBuildConfigFile)) { using Stream fs = File.OpenRead (CustomBuildConfigFile); - json = JsonNode.Parse (fs); + using JsonDocument doc = JsonDocument.Parse (fs, new JsonDocumentOptions { AllowTrailingCommas = true }); + json = doc.RootElement.ToNode (); } var jsonAddition = new { compression = new { @@ -130,7 +131,7 @@ internal override CommandLineBuilder GetCommandLineBuilder () cmd.AppendSwitchIfNotNull ("--modules ", string.Join (",", modules)); cmd.AppendSwitchIfNotNull ("--output ", Output); cmd.AppendSwitchIfNotNull ("--config ", temp); - foreach (var file in MetaDataFiles ?? Array.Empty ()) { + foreach (var file in MetaDataFiles ?? []) { cmd.AppendSwitch ($"--metadata-file={file.ItemSpec}"); } return cmd; diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/JsonExtensions.cs b/src/Xamarin.Android.Build.Tasks/Utilities/JsonExtensions.cs index 7aa1d0fe7da..9a399d2f8e0 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/JsonExtensions.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/JsonExtensions.cs @@ -47,4 +47,41 @@ public static JsonNode Merge (this JsonNode jsonBase, JsonNode jsonMerge) } return jsonBase; } + + public static JsonNode? ToNode (this JsonElement element) + { + switch (element.ValueKind) { + case JsonValueKind.Object: + var obj = new JsonObject (); + foreach (JsonProperty prop in element.EnumerateObject()) { + obj [prop.Name] = prop.Value.ToNode (); + } + return obj; + + case JsonValueKind.Array: + var arr = new JsonArray(); + foreach (JsonElement item in element.EnumerateArray ()) { + arr.Add (item.ToNode ()); + } + return arr; + + case JsonValueKind.String: + return element.GetString (); + + case JsonValueKind.Number: + return element.TryGetInt32 (out int intValue) ? intValue : element.GetDouble (); + + case JsonValueKind.True: + return true; + + case JsonValueKind.False: + return false; + + case JsonValueKind.Null: + return null; + + default: + throw new NotSupportedException ($"Unsupported JSON value kind: {element.ValueKind}"); + } + } } \ No newline at end of file diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/MamJsonParser.cs b/src/Xamarin.Android.Build.Tasks/Utilities/MamJsonParser.cs index cde98c9cc56..1db618d91c2 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/MamJsonParser.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/MamJsonParser.cs @@ -57,10 +57,11 @@ public XElement ToXml () GetReplacementMethods ()); } - static JsonObject ReadJson (string path) + static JsonNode ReadJson (string path) { - using (var f = File.OpenRead (path)) { - return JsonNode.Parse (f)!.AsObject (); + using (var fs = File.OpenRead (path)) { + using JsonDocument doc = JsonDocument.Parse (fs, new JsonDocumentOptions { AllowTrailingCommas = true }); + return doc.RootElement.ToNode () ?? JsonNode.Parse ("{}")!; } } From 07ebf8a8b49b2caea20467145795a9705e5d9428 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Mon, 24 Feb 2025 13:56:51 +0000 Subject: [PATCH 6/9] Try JsonSerializerContext --- .../Tasks/JavaDependencyVerification.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs b/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs index c5e6f9f741d..83aa940ca8a 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs @@ -306,7 +306,7 @@ public Project Resolve (Artifact artifact) } } -class MicrosoftNuGetPackageFinder +partial class MicrosoftNuGetPackageFinder { readonly PackageListFile? package_list; @@ -319,7 +319,7 @@ public MicrosoftNuGetPackageFinder (string? file, TaskLoggingHelper log) try { var json = File.ReadAllText (file); - package_list = JsonSerializer.Deserialize (json); + package_list = JsonSerializer.Deserialize (json, PackageListFileContext.Default.PackageListFile); } catch (Exception ex) { log.LogMessage ("There was an error reading 'microsoft-packages.json', Android NuGet suggestions will not be provided: {0}", ex); } @@ -344,6 +344,14 @@ public class Package [JsonPropertyName ("nugetId")] public string? NuGetId { get; set; } } + + [JsonSourceGenerationOptions(WriteIndented = true)] + [JsonSerializable(typeof(PackageListFile))] + [JsonSerializable(typeof(List))] + [JsonSerializable(typeof(string))] + internal partial class PackageListFileContext : JsonSerializerContext + { + } } public class NuGetPackageVersionFinder From 9e3bdab2f26d3d572460e758ca4f3bd881478eae Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Mon, 24 Feb 2025 16:59:48 +0000 Subject: [PATCH 7/9] back out copilot changes --- .../Tasks/BuildAppBundle.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs b/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs index 2333966d18c..32b52ae1a92 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs @@ -60,7 +60,7 @@ public class BuildAppBundle : BundleTool }; [Required] - public string BaseZip { get; set; } = ""; + public string BaseZip { get; set; } public string? CustomBuildConfigFile { get; set; } @@ -69,18 +69,18 @@ public class BuildAppBundle : BundleTool public ITaskItem []? MetaDataFiles { get; set; } [Required] - public string Output { get; set; } = ""; + public string Output { get; set; } public string? UncompressedFileExtensions { get; set; } - string temp = ""; + string temp; public override bool RunTask () { temp = Path.GetTempFileName (); try { var uncompressed = new List (UncompressedByDefault); - if (UncompressedFileExtensions is { Length: > 0 }) { + if (!string.IsNullOrEmpty (UncompressedFileExtensions)) { //NOTE: these are file extensions, that need converted to glob syntax var split = UncompressedFileExtensions.Split (new char [] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var extension in split) { @@ -89,7 +89,7 @@ public override bool RunTask () } JsonNode json = JsonNode.Parse ("{}")!; - if (CustomBuildConfigFile is { Length: > 0 } && File.Exists (CustomBuildConfigFile)) { + if (!string.IsNullOrEmpty (CustomBuildConfigFile) && File.Exists (CustomBuildConfigFile)) { using Stream fs = File.OpenRead (CustomBuildConfigFile); using JsonDocument doc = JsonDocument.Parse (fs, new JsonDocumentOptions { AllowTrailingCommas = true }); json = doc.RootElement.ToNode (); @@ -131,7 +131,7 @@ internal override CommandLineBuilder GetCommandLineBuilder () cmd.AppendSwitchIfNotNull ("--modules ", string.Join (",", modules)); cmd.AppendSwitchIfNotNull ("--output ", Output); cmd.AppendSwitchIfNotNull ("--config ", temp); - foreach (var file in MetaDataFiles ?? []) { + foreach (var file in MetaDataFiles ?? Array.Empty ()) { cmd.AppendSwitch ($"--metadata-file={file.ItemSpec}"); } return cmd; From b219dcfd2c169fc72939dc68d1d9f67ea4fa5fad Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Tue, 25 Feb 2025 08:52:52 +0000 Subject: [PATCH 8/9] Back out more nullable changes --- src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs b/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs index 32b52ae1a92..edd74511b5f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs @@ -62,16 +62,16 @@ public class BuildAppBundle : BundleTool [Required] public string BaseZip { get; set; } - public string? CustomBuildConfigFile { get; set; } + public string CustomBuildConfigFile { get; set; } - public string []? Modules { get; set; } + public string [] Modules { get; set; } - public ITaskItem []? MetaDataFiles { get; set; } + public ITaskItem [] MetaDataFiles { get; set; } [Required] public string Output { get; set; } - public string? UncompressedFileExtensions { get; set; } + public string UncompressedFileExtensions { get; set; } string temp; From 45f7b624384bcb3c06f3e04ef4baad6e9d987e88 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Tue, 25 Feb 2025 12:02:42 +0000 Subject: [PATCH 9/9] Remove redundant attributes --- .../Tasks/JavaDependencyVerification.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs b/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs index 83aa940ca8a..25956bc5b0b 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs @@ -332,20 +332,20 @@ public MicrosoftNuGetPackageFinder (string? file, TaskLoggingHelper log) public class PackageListFile { - [JsonPropertyName ("packages")] public List? Packages { get; set; } } public class Package { - [JsonPropertyName ("javaId")] public string? JavaId { get; set; } - - [JsonPropertyName ("nugetId")] public string? NuGetId { get; set; } } - [JsonSourceGenerationOptions(WriteIndented = true)] + [JsonSourceGenerationOptions( + AllowTrailingCommas = true, + WriteIndented = true, + PropertyNameCaseInsensitive = true + )] [JsonSerializable(typeof(PackageListFile))] [JsonSerializable(typeof(List))] [JsonSerializable(typeof(string))]