Repository navigation
[release/11.0.1xx] [xabt] Replace <ValidateJavaVersion/> with MSBuild targets XML - #13870
Open
jonathanpeppers wants to merge 3 commits into
Open
jonathanpeppers wants to merge 3 commits into
jonathanpeppers wants to merge 3 commits into
Conversation
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>
Contributor
There was a problem hiding this comment.
🟢 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
_ValidateJavaVersionwith 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
844a7f3fe465e93c4b3221c2a58f94d43c3a3dce↑ 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.mdworkflow documentation, and in particular should include: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 bygit merge-base HEAD origin/release/11.0.1xx.Conflict resolutions
DesignTimeBuild/AndroidUseManagedDesignTimeResourceGeneratorcondition,_AndroidUseJavaExeVersiondefault 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.ResolveAndroidTooling,RuntimeIdentifierToAbi, and Google SDK checks unchanged.ReferenceAssemblyPathsis already present in the release XML and supported by its release task; this backport does not add or change it. NoGetCanonicalFormcode is added.ValidateJavaVersionTestsfixture instead.MonoAndroidHelper.RunProcess(TaskEnvironment, ...)overload and lazyOS.ProgramFilesX86change 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 twocherry-pick -xcommits retain source history, followed by a cleanup commit.d94c7d6bc0). No additional prerequisite is included. The XML keeps its four-component normalization, including21.0.13.0.2→21.0.13.0.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 aResolveAndroidToolingstub 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.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.Final release change: eight files, +241/-464. Product build, full NUnit suite, and device checks were not run, as requested.