Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions eng/gradle/mirror-dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" }
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <parent> 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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
{
Expand Down