Skip to content

[xabt] Enable MT for ValidateJavaVersion - #13322

Merged
jonathanpeppers merged 4 commits into
mainfrom
jonathanpeppers-mt-java-version-validation
Oct 30, 2026
Merged

jonathanpeppers merged 4 commits into
mainfrom
jonathanpeppers-mt-java-version-validation

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

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.

Local validation used a source-built Debug SDK with .NET 11 RC2 and JDK 21. Temporary SDK pins and the local-only adb teardown safety change were restored.

  • build.cmd Prepare — passed.
  • dotnet-local.cmd build Microsoft.Android.slnx -t:BuildDotNet -c Debug -m:4 -nr:false -v:minimal -clp:Summary — passed before the helper revisions; existing warnings, no errors.
  • dotnet-local.cmd build src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj --no-restore -p:BuildProjectReferences=false -nr:false -v:minimal — passed after the OS fix; no warnings or errors.
  • dotnet-local.cmd build src\Xamarin.Android.Build.Tasks\Xamarin.Android.Build.Tasks.csproj --no-restore -p:BuildProjectReferences=false -nr:false -v:minimal — passed after the OS fix, including the official analyzer; one existing duplicate-source warning.
  • dotnet-local.cmd build src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Xamarin.Android.Build.Tests.csproj --no-restore -p:BuildProjectReferences=false -nr:false -v:minimal — passed; no warnings or errors.
  • dotnet-local.cmd test bin\TestDebug\net10.0\Xamarin.Android.Build.Tests.dll --filter "FullyQualifiedName~ValidateJavaVersionTests|FullyQualifiedName~ResolveSdksTaskTests|FullyQualifiedName~MonoAndroidHelperTests" — 67 passed after the OS fix.
  • dotnet-local.cmd test tests\Xamarin.Android.Tools.AndroidSdk-Tests\Xamarin.Android.Tools.AndroidSdk-Tests.csproj --no-restore -p:BuildProjectReferences=false --filter FullyQualifiedName~AndroidSdkInfoTests -nr:false -v:minimal — 21 passed, 2 skipped.
  • dotnet-local.cmd test tests\Microsoft.Android.Build.BaseTasks-Tests\Microsoft.Android.Build.BaseTasks-Tests.csproj --filter FullyQualifiedName~MultithreadedAndroidTaskTests -v:minimal -nr:false — 7 passed, including file-lock diagnostics.
  • A fresh-process check confirmed that reading OS flags leaves ProgramFilesX86 uninitialized; first access returns the expected Windows folder and caches it.
  • Temporary two-project probes covered release-file lookup, real java/javac execution, and cache reuse in ordinary mode and with -m -mt -nr:false -warnaserror:MSB4286,MSB4287,MSB4288 — passed with no warnings or errors. The strict probe was repeated after the OS fix. binlogtool confirmed strict MT execution with no external task-host messages.

ValidateJavaVersion starts Java processes and reads JDK files, so it
cannot safely use the shared process directory and environment in MT
builds.  Use MultithreadedAndroidTask and TaskEnvironment for both.

Read stdout and stderr separately, and key cached versions by the tool
path, project directory, and Java options.  Keep the configured JDK
bounds and diagnostics.  Add focused path, environment, and cache tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 29, 2026 15:52

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 are reported for the multithreaded Java version validation changes.

No open issues 🎉

What changed in this PR

Updates ValidateJavaVersion to support in-process multithreaded MSBuild execution while preserving JDK version bounds and diagnostics.

Changes:

  • Uses MultithreadedAndroidTask and project-specific paths and process environments.
  • Reads stdout and stderr separately and scopes cached versions by tool path, project directory, and Java options.
  • Adds tests for relative paths, environment isolation, and normalized-path cache reuse.
File Description
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​Tasks/​ValidateJavaVersionTests.cs Adds project-context tests and extends cache reuse coverage.
src/​Xamarin.Android.Build.Tasks/​Tasks/​ValidateJavaVersion.cs Enables multithreaded execution with project-aware tool resolution, process launch, and caching.

Review effort: Balanced

@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Oct 29, 2026
@jonathanpeppers jonathanpeppers removed the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Oct 29, 2026
jonathanpeppers and others added 3 commits October 29, 2026 16:47
Add a TaskEnvironment overload to the existing process helper.  Keep
Java output collection in the original shared buffer, protect its
callbacks with a lock, and remove the project directory cache key.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Do not query special folders when initializing the OS flags.  Resolve
and cache ProgramFilesX86 only when it is requested, so MT tasks can
continue to use OS.IsWindows without environment-dependent setup.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers
jonathanpeppers merged commit 6da1226 into main Oct 30, 2026
41 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-mt-java-version-validation branch October 30, 2026 14:51
jonathanpeppers added a commit that referenced this pull request Oct 30, 2026
Stacked on #13322. Reuse its `MonoAndroidHelper.RunProcess(TaskEnvironment, …)` overload for the aapt2 version probe.

`ResolveAndroidTooling` still requires process-wide working-directory and environment handling under `-mt`. Use `MultithreadedAndroidTask` and declare `[MSBuildMultiThreadableTask]` so it can run in-process with other tasks.

Resolve SDK and tool paths through `TaskEnvironment`, use project-specific `PATHEXT`, and start aapt2 with the project environment. Keep the existing tool search order and diagnostics. Extend the existing cache test to cover distinct project directories, relative paths, child-process environment and working directory, and cache reuse.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants