Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
1 change: 0 additions & 1 deletion build-tools/installers/create-installers.targets
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, is System.Text.Json in the pack?

It would be needed for .NET framework.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea. Probably. We need to figure out how to get #9727 and #8746 working so we can test under .NET framework to catch all this stuff.

<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)NuGet.Common.dll" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)NuGet.Configuration.dll" />
<_MSBuildFiles Include="$(MicrosoftAndroidSdkOutDir)NuGet.DependencyResolver.Core.dll" />
Expand Down
30 changes: 14 additions & 16 deletions src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -318,7 +319,7 @@ public MicrosoftNuGetPackageFinder (string? file, TaskLoggingHelper log)

try {
var json = File.ReadAllText (file);
package_list = JsonConvert.DeserializeObject<PackageListFile> (json);
package_list = JsonSerializer.Deserialize<PackageListFile> (json);
} catch (Exception ex) {
log.LogMessage ("There was an error reading 'microsoft-packages.json', Android NuGet suggestions will not be provided: {0}", ex);
}
Expand All @@ -331,16 +332,16 @@ public MicrosoftNuGetPackageFinder (string? file, TaskLoggingHelper log)

public class PackageListFile
{
[JsonProperty ("packages")]
[JsonPropertyName ("packages")]
public List<Package>? Packages { get; set; }
}

public class Package
{
[JsonProperty ("javaId")]
[JsonPropertyName ("javaId")]
public string? JavaId { get; set; }

[JsonProperty ("nugetId")]
[JsonPropertyName ("nugetId")]
public string? NuGetId { get; set; }
}
}
Expand Down
50 changes: 50 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Utilities/JsonExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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<string, JsonNode?> [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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<PackageReference Include="Mono.Cecil" Version="$(MonoCecilVersion)" GeneratePathProperty="true" />
<PackageReference Include="Irony" />
<PackageReference Include="NuGet.ProjectModel" Version="6.13.1" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
<PackageReference Include="System.CodeDom" />
<PackageReference Include="System.IO.Hashing" Version="$(SystemIOHashingPackageVersion)" />
<PackageReference Include="System.Reflection.Metadata" Version="8.0.0" />
Expand Down
Loading