Skip to content

[release/11.0.1xx] [xabt] Replace <ValidateJavaVersion/> with MSBuild targets XML - #13870

Open
jonathanpeppers wants to merge 3 commits into
release/11.0.1xxfrom
jonathanpeppers-backport-validate-java-version-xml
Open

jonathanpeppers wants to merge 3 commits into
release/11.0.1xxfrom
jonathanpeppers-backport-validate-java-version-xml

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 844a7f3fe465e93c4b3221c2a58f94d43c3a3dce

Dimension Assessment Rationale
Change confidence 8/10 ↑ All 14 isolated MSBuild cases pass against the real release Tooling.targets.
↑ Release tooling parameters are unchanged; no nested-build tooling-reuse code was added.
↓ Checks use stub tasks and resource text; the product build and NUnit suite are left to CI.

Pull Request
title and
description
should follow the
commit-messages.md workflow documentation, and in particular should include:

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests

Backport of #13322 and #13472.

Replace the Java validation task with MSBuild XML so validation no longer needs a process-state-dependent managed task. This combines the two changes in one release PR. The branch starts at c1065ecd7bc73fab6894385f4edd7dd3a75b99c9, confirmed by git merge-base HEAD origin/release/11.0.1xx.

Conflict resolutions

  • Tooling.targets: port only the Java validation XML and its dependency into the release target layout. Preserve the existing DesignTimeBuild / AndroidUseManagedDesignTimeResourceGenerator condition, _AndroidUseJavaExeVersion default and executable-selection behavior, _JdkVersion, _DefaultJdkVersion, and coded diagnostics. Do not copy _ComputeAndroidToolingInputs, _AndroidUseResolvedTooling, _AndroidOuter*, or other [Xamarin.Android.Build.Tasks] Reuse tooling in nested builds #13202 changes.
  • Release tooling contract: leave the ResolveAndroidTooling, RuntimeIdentifierToAbi, and Google SDK checks unchanged. ReferenceAssemblyPaths is already present in the release XML and supported by its release task; this backport does not add or change it. No GetCanonicalForm code is added.
  • DesignTimeResourceTargetsTests.cs: keep this file deleted. Add four design-time condition cases to the existing release ValidateJavaVersionTests fixture instead.
  • XASdkTests.cs: retain the release file unchanged. The conflicting upstream assertions belong to nested-build tooling-reuse tests that do not exist on release.
  • ValidateJavaVersionTests.cs: use the XML-based upstream tests, retain and adapt the release five-part version test for both release-file and forced-executable paths, and add the release design-time checks.
  • Superseded [xabt] Enable MT for ValidateJavaVersion #13322 helpers: remove the new MonoAndroidHelper.RunProcess(TaskEnvironment, ...) overload and lazy OS.ProgramFilesX86 change from the final change. The deleted Java task was the only caller of the new overload; both helper files now match the release base. The two cherry-pick -x commits retain source history, followed by a cleanup commit.
  • Five-part JDK versions: [Xamarin.Android.Build.Tasks] Fix 5-part JDK versions #13524 is already on release through [release/11.0.1xx] [Xamarin.Android.Build.Tasks] Fix 5-part JDK versions (#13524) #13598 (d94c7d6bc0). No additional prerequisite is included. The XML keeps its four-component normalization, including 21.0.13.0.2 → 21.0.13.0.
  • Documentation: retire XA0034 for this release rather than .NET 12, and remove the deleted task's debug prefix entry. Keep historical guide examples unchanged.

Validation

No full repository or SDK build was run. Full validation runs in CI.

  • & 'C:\Users\jopepper\.copilot\session-state\8c684457-0a8b-4fac-8e46-fdcf6b0b7acc\files\Validate-JavaXml.ps1' — passed, 14 cases, using .NET SDK 11.0.100. Imports the real Tooling.targets and uses a ResolveAndroidTooling stub plus diagnostic stubs populated from the real English resources. Checks supported and major-only versions, exact old/new JDK error codes and resource text, five-part versions, missing/invalid release fallback, forced executable with a conflicting release file, downgraded errors, XA0033, XA5300, and all four release design-time conditions. Logs and harness are retained in the session artifacts.
  • Earlier runs of that same command failed in the scratch harness, then were corrected: missing assembly placeholder; qualified inline-task class names; generated unreachable-code warning; diagnostic stub return value; multiline resource-text assertion. These were harness-only failures, not product changes. The final complete run passes.
  • git diff --check origin/release/11.0.1xx — passed.
  • git grep -n -w ValidateJavaVersion -- '*.targets' '*.cs' '*.csproj' — passed, no task references or registrations (expected grep exit 1). An unrestricted grep finds only historical documentation examples.
  • Per-file comparison with both upstream patches — passed. Resource removals and ResolveSdks test removals match upstream. XML and Java tests differ only for the release conditions and existing release coverage; unrelated main-only test files and helper changes are omitted.

Final release change: eight files, +241/-464. Product build, full NUnit suite, and device checks were not run, as requested.

jonathanpeppers and others added 3 commits December 1, 2026 16:43
Enable in-process `-mt` execution for `ValidateJavaVersion`. Use `MultithreadedAndroidTask`, declare `[MSBuildMultiThreadableTask]`, and add a `TaskEnvironment` overload to `MonoAndroidHelper.RunProcess` for the project's working directory and environment.

Keep the existing output callbacks and buffer, with locks for concurrent writes. Resolve tool paths before release-file lookup and cache versions by tool path and Java options. Keep JDK bounds and diagnostics unchanged.

Keep using `OS.IsWindows`. Fix the shared `OS` initializer by deferring `ProgramFilesX86` discovery until its first use, then caching the value. Reading the OS flags no longer queries special folders.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 6da1226)
)

Context: #13460

`<ValidateJavaVersion/>` parses `java -version` and `javac -version` output with two fixed regular expressions, which are constructed and interpreted at runtime because Xamarin.Android.Build.Tasks targets netstandard2.0. Microsoft.Android.Build.Tasks targets net12.0, where `[GeneratedRegex]` is available.

Move the task into Microsoft.Android.Build.Tasks, following the BuildAppBundle move in #13460:

  * The task now lives in the `Microsoft.Android.Tasks` namespace and keeps its `MultithreadedAndroidTask` base. `Microsoft.Android.Sdk.Tooling.targets` registers it with a single `<UsingTask/>` against `$(_MicrosoftAndroidBuildTasksAssembly)`; the unqualified `<ValidateJavaVersion/>` invocation is unchanged.
  * `JavaVersionRegex` and `JavacVersionRegex` become `[GeneratedRegex]` partial properties with the same patterns and default options. Neither uses `RegexOptions.IgnoreCase`, so there is no culture-sensitivity change.
  * `MonoAndroidHelper.RunProcess(TaskEnvironment, …)` and its `TaskEnvironment.Fallback` overload move verbatim from `MonoAndroidHelper.cs` into `MonoAndroidHelper.RunProcess.cs`, which is compile-linked into Microsoft.Android.Build.Tasks. `ResolveAndroidTooling`, `Lint`, and `MonoAndroidHelper.GetOSBinDirName()` still use it.
  * Two nullable warnings surfaced by net12.0 annotations are fixed without changing behavior for real JDK paths.

The unit tests move to Microsoft.Android.Build.Tasks.Tests with a private copy of the faux-JDK helpers, plus a new test that loads the shipped `<UsingTask/>` and runs both `<ValidateJavaVersion/>` and `<Microsoft.Android.Tasks.ValidateJavaVersion/>` through `dotnet msbuild`. `ToolingTargetRejectsOldJavaForModernAndroidApi` stays in Xamarin.Android.Build.Tests to cover the task through `_ResolveAndroidTooling`. `ResolveSdksTaskTests` no longer instantiates `ValidateJavaVersion`; its JDK assertions were already covered by `ValidateJavaVersionTests`.

The task now requires .NET 12 MSBuild, like the other Microsoft.Android.Build.Tasks tasks.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Register ValidateJavaVersion with the Full/Core UsingTask pair

Visual Studio (Full MSBuild) must load the net12.0 task through TaskHostFactory, matching BuildAppBundle, GetAndroidPackageName, and BuildArchive.

Remove JavaVersionTargetsTests: it ran 27 \dotnet msbuild\ processes
to cover the same _ValidateJavaVersion cases as ValidateJavaVersionTests,
and needed AndroidError.cs/AndroidWarning.cs compiled into a second
test assembly.

In ValidateJavaVersionTests:

  * Test the version range once, from the release file. Add a
    major-only \21\ case for the \.0\ normalization.
  * Add JavaToolExeSelectsJdk for the JavaToolExe override.
  * Use one directory name for the special-character path test.
  * Build the full-project tooling test once.
  * Remove ConfiguredMinimumJavaVersionIsRequired, which the range
    test already covers.

In XASdkTests, count the _ValidateJavaVersion target under its own key.

Co-authored-by: Jonathan Peppers <jonathan.peppers@microsoft.com>
(cherry picked from commit 1c5fe22)
Keep the release tooling contract and omit unused MT process helpers after replacing the Java validation task. Update the retired diagnostic documentation for the release branch.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 22:48

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.

🟢 Approval recommended

No active review issues remain for the Java version validation backport.

No open issues 🎉

1 file not reviewed
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Generated file
What changed in this PR

Backports Java version validation from a managed task to MSBuild XML, removing a process-state-dependent task from the .NET for Android release build pipeline without importing unrelated nested-build tooling changes.

Changes:

  • Adds _ValidateJavaVersion with release-file parsing, executable fallback, and release-specific design-time conditions.
  • Reworks validation tests to exercise the target, including five-part versions, path handling, and diagnostics.
  • Removes the managed task and XA0034 resources, documenting the diagnostic’s retirement in 11.0.1xx.
File Description
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​Tasks/​ValidateJavaVersionTests.cs Tests XML-based validation and release-specific behavior.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​Tasks/​ResolveSdksTaskTests.cs Removes calls and assertions for the deleted task.
src/​Xamarin.Android.Build.Tasks/​Tasks/​ValidateJavaVersion.cs Deletes the managed validation implementation.
src/​Xamarin.Android.Build.Tasks/​Properties/​Resources.resx Removes the retired XA0034 resource.
src/​Xamarin.Android.Build.Tasks/​Properties/​Resources.Designer.cs Removes the corresponding resource accessor.
src/​Xamarin.Android.Build.Tasks/​Microsoft.Android.Sdk/​targets/​Microsoft.Android.Sdk.Tooling.targets Implements Java validation and connects it to tooling resolution.
Documentation/​docs-mobile/​messages/​xa0034.md Documents retirement and points to XA0033.
Documentation/​docs-mobile/​messages/​index.md Updates XA0034’s status and removes the deleted task’s debug prefix.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants