Skip to content

[Microsoft.Android.Build.Tasks] Move MamJsonToXml to .NET - #13459

Merged
jonathanpeppers merged 9 commits into
mainfrom
simonrozsival-migrate-mam-json-task
Nov 17, 2026
Merged

jonathanpeppers merged 9 commits into
mainfrom
simonrozsival-migrate-mam-json-task

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Context: #12988

<MamJsonToXml/> currently runs from the netstandard2.0 task assembly and uses its System.Text.Json package. Move the task and parser to Microsoft.Android.Build.Tasks so the task uses the framework-provided JSON implementation. Delete the legacy task rather than maintain two implementations. The legacy assembly still retains its System.Text.Json package and compile-links JsonExtensions.cs for other consumers.

Register the .NET task for both Core and Full MSBuild. Full uses Runtime="NET" and TaskHostFactory, following the other .NET task registrations. The task retains the existing MSBuild parameters and XML conversion, supports multithreaded execution, and resolves paths through TaskEnvironment.

Validation (current head):

./dotnet-local.sh test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj --filter FullyQualifiedName~MamJsonToXmlTests --no-restore
# Passed: 5/5.

./dotnet-local.sh build src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj --no-restore
# Passed: 0 warnings, 0 errors.

make prepare && make all
make leeroy
# Both failed during ConfigureLocalWorkload: bin/Debug/lib/xamarin.android/xbuild-frameworks/Microsoft.Android/37/Mono.Android.xml was missing.

Full/Mono-hosted execution was not tested on macOS. Earlier revisions passed make leeroy CONFIGURATION=Release, the complete modern suite (871 passed, 5 skipped), and MamRemappingTransitionsUpdatePackages (3/3); those runs were not repeated after the final registration changes.

…sembly

Move the `<MamJsonToXml/>` task and its `MamJsonParser` helper from
`Xamarin.Android.Build.Tasks` into `Microsoft.Android.Build.Tasks`, so
it runs on .NET with the framework-provided System.Text.Json.

  * `Xamarin.Android.Common.targets` registers
    `Microsoft.Android.Tasks.MamJsonToXml` with the existing Full/Core
    `UsingTask` pair (TaskHostFactory + Runtime="NET" on .NET Framework
    MSBuild, in-proc Runtime="NET" on .NET MSBuild). The `<MamJsonToXml/>`
    element name and parameters used by
    `_ConvertAndroidMamMappingFileToXmlFile` are unchanged.
  * The task derives from `MultithreadedAndroidTask`, is marked
    `[MSBuildMultiThreadableTask]`, and resolves input/output paths via
    `TaskEnvironment`. `MamJsonParser.Load()` now takes a `Stream` so the
    task owns file access; parsing and XML generation are unchanged.
  * `JsonExtensions.cs` is linked (not moved), since the legacy
    `BuildAppBundle` task still uses it, and the legacy
    System.Text.Json PackageReference is left in place.
  * The task test and its mam.json/mam.xml fixtures move to
    `Microsoft.Android.Build.Tasks.Tests`.

The public `Xamarin.Android.Tasks.MamJsonToXml` type is removed from
`Xamarin.Android.Build.Tasks.dll`; only the MSBuild task contract is
preserved.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 10, 2026 15:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The required XmlMappingOutput parameter is nullable and defaults to null; it should expose a non-nullable contract while retaining explicit validation for unset or empty output items.

1 open issue
What changed in this PR

Moves MAM JSON-to-XML conversion into Microsoft.Android.Build.Tasks to use framework-provided System.Text.Json, continuing the build-tool modernization described in #12988 without depending on it.

Changes:

  • Migrates the task and parser, adding multithreaded task support and project-relative path resolution.
  • Updates Full/Core MSBuild registrations while preserving the short task name and parameters.
  • Relocates the conversion test and fixtures to the modern task test project.
File Description
src/​Xamarin.Android.Build.Tasks/​Xamarin.Android.Common.targets Registers the modern task for Full/Core MSBuild.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​Utilities/​ResourceData.cs Removes obsolete MAM fixture accessors.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​Tasks/​MamJsonToXmlTests.cs Removes the legacy test implementation.
src/​Xamarin.Android.Build.Tasks/​MamJsonToXml.cs Removes the legacy public task type.
src/​Microsoft.Android.Build.Tasks/​Utilities/​MamJsonParser.cs Moves the parser namespace and accepts an open stream.
src/​Microsoft.Android.Build.Tasks/​Tests/​Microsoft.Android.Build.Tasks.Tests/​Resources/​MamJsonToXml/​mam.xml Supplies the expected XML fixture.
src/​Microsoft.Android.Build.Tasks/​Tests/​Microsoft.Android.Build.Tasks.Tests/​Resources/​MamJsonToXml/​mam.json Supplies the JSON input fixture.
src/​Microsoft.Android.Build.Tasks/​Tests/​Microsoft.Android.Build.Tasks.Tests/​Microsoft.Android.Build.Tasks.Tests.csproj Copies MAM fixtures to test output.
src/​Microsoft.Android.Build.Tasks/​Tests/​Microsoft.Android.Build.Tasks.Tests/​MamJsonToXmlTests.cs Tests conversion with project-relative paths and normalized line endings.
src/​Microsoft.Android.Build.Tasks/​Tasks/​MamJsonToXml.cs Adds the modern task using TaskEnvironment.
src/​Microsoft.Android.Build.Tasks/​Microsoft.Android.Build.Tasks.csproj Links the existing JSON extension helpers.

Review effort: Balanced

simonrozsival and others added 3 commits November 10, 2026 17:25
Context: #13459

Keep task registration attribute-free so Core MSBuild loads the modern MamJsonToXml implementation in process, while every non-Core host continues to load the legacy class and assembly. The mutually exclusive Core/non-Core conditions retain coverage for Full, Mono, and any other non-Core host without depending on Runtime or TaskFactory hosting support.

Restore the legacy task, tests, and fixtures. Compile-link MamJsonParser and JsonExtensions into the modern assembly instead of maintaining separate parser implementations; the legacy path-based parser entry point delegates to the shared stream-based implementation. Keep the legacy System.Text.Json package dependency. The modern task continues to reuse MultithreadedAndroidTask and the framework-provided JSON library.

Focused tests pass for both the net11 legacy task (1 test) and net12 modern task (2 tests). Ordinary and strict multithreaded Core MSBuild runs execute the production MAM targets and produce byte-identical XML. Full/Mono host execution remains unvalidated on macOS.

Co-authored-by: Copilot App <[email protected]>
Context: #13459

Make Microsoft.Android.Build.Tasks the canonical source owner for MamJsonParser and JsonExtensions. Link those sources back into Xamarin.Android.Build.Tasks so its non-Core compatibility implementation and other legacy JSON consumers continue to work without duplicated helper code. This keeps ownership aligned with the eventual removal of the legacy task project.

Both helper moves are byte-preserving. Focused modern tests pass 2/2; legacy MAM, JsonExtensions, and bundle-tool tests pass 7/7. Ordinary and strict multithreaded Core MSBuild smoke runs still load the modern task and produce XML byte-identical to the original fixture and baseline. Full/Mono host execution remains unvalidated on macOS.

Co-authored-by: Copilot App <[email protected]>
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13459

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ LGTM — source review

Findings: 0 errors, 0 warnings, 1 non-blocking inline suggestion.

Reviewed all eight changed files in full, the parser's callers, the task base/logger, project references, and the consuming remapping targets. The mutually exclusive registrations preserve the legacy non-Core implementation, while Core uses the modern assembly. The modern adapter resolves both input and output paths through TaskEnvironment; parser state remains per task, and the stream overload preserves the existing parsing options and XML conversion. Reusing the canonical parser sources avoids conversion drift between hosts. No blocking correctness regression found.

CI evidence: All 40 GitHub checks report success, including the overall dotnet-android check for Azure build 1673210. Direct Azure build/timeline verification could not be completed: the CLI required authentication and the parallel timeline query failed during CLI initialization. This is not an independent Azure timeline confirmation.

Local validation: Attempted dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj -c Release -v minimal --filter FullyQualifiedName~MamJsonToXmlTests --no-restore; the .NET CLI failed before building or running tests while initializing the NuGet-Migrations mutex. No local test result is claimed. Full/Mono host execution also remains unverified here, consistent with the limitation documented in the PR.

Generated by Android PR Reviewer for #13459 · copilot · gpt61 · 40 AIC · ⌖ 4.96 AIC · ⊞ 20.1K
Comment /review to run again

@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Nov 11, 2026
simonrozsival and others added 3 commits November 12, 2026 14:53
The BuildAppBundle migration on main reintroduced a link to the legacy path after the MAM migration moved JsonExtensions into the modern task project. Use the SDK's default source inclusion instead.

Co-authored-by: Copilot App <[email protected]>
@simonrozsival simonrozsival removed the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Nov 13, 2026
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13459

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No blocking code findings — 0 errors, 0 warnings, 1 non-blocking inline suggestion.

Reviewed all nine changed files in full, the calling target, task base classes, and logging paths. The Core/non-Core registrations are mutually exclusive, the modern task declares multithreaded support and resolves both input and output paths through TaskEnvironment, and the shared parser preserves the existing conversion and stream-disposal behavior. Keeping the legacy sources compile-linked and its System.Text.Json dependency intact preserves the current netstandard2.0 fallback. The documented integration overlap with #12988 remains relevant if the changes are combined.

CI verification incomplete: all 40 head-commit GitHub checks report success, including the aggregate dotnet-android check for Azure build 1678722. Direct Azure build/timeline confirmation was unavailable: the build query required authentication and the concurrent timeline query failed during CLI initialization. No CI failure was observed, but I cannot independently confirm the Azure result. This was a source review; local builds/tests were not rerun.

Generated by Android PR Reviewer for #13459 · copilot · gpt61 · 35.9 AIC · ⌖ 4.14 AIC · ⊞ 20.2K
Comment /review to run again

BuildEngine = new MockBuildEngine (TestContext.Out, errors),
};
if (supplyEmptyItem) {
task.XmlMappingOutput = new TaskItem ("");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 💡 Testing — Both cases currently exercise an empty TaskItem: when supplyEmptyItem is false, XmlMappingOutput retains its new TaskItem ("") default; when true, it is replaced with an equivalent item. Consider adding an explicit XmlMappingOutput = null case (keeping the omitted/default and explicit-empty cases if desired) so the separate null guard in RunTask() is covered as well.

{Rule: Test edge cases}

@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Nov 16, 2026
Keep the Lint shared helper and Java dependency test entries while moving JsonExtensions and adding the MAM test resources.

Co-authored-by: Copilot App <[email protected]>
@jonathanpeppers

Copy link
Copy Markdown
Member

@dalexsoto review

@jonathanpeppers
jonathanpeppers enabled auto-merge (squash) November 16, 2026 22:22

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed e5c17ef7 against main at b0843532 (merge-base b0843532). This was a static, read-only review. I didn't build or run anything.

LGTM. I compared the move against the full old files.

  • Parser and helper: MamJsonParser only gains a Load(Stream) overload. Parse options (AllowTrailingCommas), the empty-object fallback and the XML generation are unchanged. JsonExtensions.cs is byte-identical.
  • Task: MamJsonToXml keeps the same [Required] inputs and output. Paths go through TaskEnvironment.GetAbsolutePath, and each stream is disposed.
  • Registration: the Full (TaskHostFactory, Runtime="NET") and Core UsingTask entries match the other moved tasks and point at the shipped tools\net assembly. The call site keeps the short name and the same parameters.
  • Project files: the SDK-style csproj globs the moved utilities, and XABT links JsonExtensions.cs back so its other users and JsonExtensionsTests still compile. create-installers.targets already ships the net assembly, so no packaging change is needed.
  • Tests: the new tests line up with the shared infrastructure. MultithreadedAndroidTask catches the guard's exception and logs it with a Fallback TaskEnvironment, MockBuildEngine has the overload the tests call, and the linked mam.json/mam.xml resources exist.

@jonathanpeppers
jonathanpeppers merged commit 5d51368 into main Nov 17, 2026
39 checks passed
@jonathanpeppers
jonathanpeppers deleted the simonrozsival-migrate-mam-json-task branch November 17, 2026 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants