diff --git a/eng/gradle/mirror-dependencies.ps1 b/eng/gradle/mirror-dependencies.ps1 index a1c43f1b547..c28bb0e20a0 100644 --- a/eng/gradle/mirror-dependencies.ps1 +++ b/eng/gradle/mirror-dependencies.ps1 @@ -35,7 +35,8 @@ Maven coordinates to mirror directly, for tests that do not use Gradle. Each value is group:artifact:version, which attempts the POM, JAR, AAR, and Gradle module metadata files. Append an exact filename as a fourth segment - when a test requests a nonstandard payload. + when a test requests a nonstandard payload. The command fails if no payload + can be mirrored for any requested coordinate. .PARAMETER GradleWrapper Optional path to the Gradle wrapper used by CI for this project, relative @@ -126,7 +127,12 @@ function Invoke-Mirror($logPath) { ForEach-Object { $_.Matches } | ForEach-Object { $_.Groups[1].Value } | Sort-Object -Unique - if ($urls.Count -eq 0) { return 0 } + if ($urls.Count -eq 0) { + return [pscustomobject]@{ + SuccessCount = 0 + FailureCount = 0 + } + } $token = Get-AzDevOpsToken $basicCredential = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$token")) $headers = @{ Authorization = "Basic $basicCredential" } @@ -141,7 +147,10 @@ function Invoke-Mirror($logPath) { } } Write-Host " -> mirrored OK=$ok, not-found=$fail (of $($urls.Count))" -ForegroundColor Cyan - return $urls.Count + return [pscustomobject]@{ + SuccessCount = $ok + FailureCount = $fail + } } function Get-MavenArtifactUrls($artifacts) { @@ -177,15 +186,26 @@ if ($PSCmdlet.ParameterSetName -eq 'MavenArtifact') { Write-Host "Mirroring Maven artifacts directly:" $MavenArtifact | ForEach-Object { Write-Host " $_" } $log = Join-Path ([IO.Path]::GetTempPath()) 'maven-artifact-mirror.log' + $failedArtifacts = @() try { - Get-MavenArtifactUrls $MavenArtifact | - ForEach-Object { "Could not GET '$_'" } | - Set-Content $log - Invoke-Mirror $log | Out-Null + foreach ($artifact in $MavenArtifact) { + Get-MavenArtifactUrls $artifact | + ForEach-Object { "Could not GET '$_'" } | + Set-Content $log + $result = Invoke-Mirror $log + if ($result.SuccessCount -eq 0) { + $failedArtifacts += $artifact + } + } } finally { Remove-Item $log -ErrorAction SilentlyContinue } + if ($failedArtifacts.Count -gt 0) { + Write-Host "`nNo payloads were mirrored for:" -ForegroundColor Red + $failedArtifacts | ForEach-Object { Write-Host " $_" -ForegroundColor Red } + exit 1 + } return } @@ -208,8 +228,8 @@ try { Write-Host "`nBUILD SUCCESSFUL after $i iteration(s). The feed now has the packages CI needs." -ForegroundColor Green return } - $count = Invoke-Mirror $log - if ($count -eq 0) { + $result = Invoke-Mirror $log + if (($result.SuccessCount + $result.FailureCount) -eq 0) { Write-Host "`nGradle failed but no 401s to mirror — see $log" -ForegroundColor Red Get-Content $log -Tail 30 exit 1 diff --git a/external/Java.Interop b/external/Java.Interop index 33992194b93..8e8291c9ef4 160000 --- a/external/Java.Interop +++ b/external/Java.Interop @@ -1 +1 @@ -Subproject commit 33992194b9373e9322244612c94ed9941b9bc2fd +Subproject commit 8e8291c9ef45b4bbc28b09456dc5888eb80af77b diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs b/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs index 3e9740609e7..92380901e3d 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/JavaDependencyVerification.cs @@ -272,7 +272,13 @@ public MSBuildLoggingPomResolver (TaskLoggingHelper logger) try { using (var file = File.OpenRead (filename)) { var project = Project.Load (file); - var registered_artifact = Artifact.Parse (project.VersionedArtifactString); + + // POMs may inherit GroupId/Version from a element, so fall back to + // the parent's values when the project itself doesn't declare them. (Without + // this, building an Artifact would fail validation with an empty coordinate.) + var groupId = project.GroupId.HasValue () ? project.GroupId : (project.Parent?.GroupId ?? ""); + var version = project.Version.HasValue () ? project.Version : (project.Parent?.Version ?? ""); + var registered_artifact = new Artifact (groupId, project.ArtifactId ?? "", version); // Return the registered artifact, preferring any overrides specified in the task item var final_artifact = new Artifact ( diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/JavaDependencyVerificationTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/JavaDependencyVerificationTests.cs index 4c59593ebf3..eb5774ed761 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/JavaDependencyVerificationTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/JavaDependencyVerificationTests.cs @@ -78,6 +78,27 @@ public void NoSpecifiedDependencies () Assert.AreEqual (0, engine.Errors.Count); } + [Test] + public void InheritedArtifactCoordinates () + { + using var parent_pom = new PomBuilder ("com.google.auto.value", "auto-value-parent", "1.10.4").BuildTemporary (); + using var pom = new PomBuilder ("", "auto-value-annotations", "") + .WithParent ("com.google.auto.value", "auto-value-parent", "1.10.4") + .BuildTemporary (); + + var engine = new MockBuildEngine (TestContext.Out, []); + var task = new JavaDependencyVerification { + BuildEngine = engine, + AndroidLibraries = [CreateAndroidLibraryTaskItem ("auto-value-annotations.jar", pom.FilePath)], + AdditionalManifests = [CreateAndroidAdditionManifestTaskItem (parent_pom.FilePath)], + }; + + var result = task.RunTask (); + + Assert.True (result); + Assert.AreEqual (0, engine.Errors.Count); + } + [Test] public void MissingSpecifiedDependency () {