Skip to content

Commit ca0e309

Browse files
Improve performance of Verify-Required-Maven-Artifacts (#45879)
* Improve performance of Verify-Required-Maven-Artifacts * Update eng/scripts/Verify-Required-Maven-Artifacts.ps1 Co-authored-by: Wes Haggard <[email protected]> --------- Co-authored-by: Wes Haggard <[email protected]>
1 parent 5c92be5 commit ca0e309

File tree

1 file changed

+40
-29
lines changed

1 file changed

+40
-29
lines changed

eng/scripts/Verify-Required-Maven-Artifacts.ps1

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ param(
1616

1717
Write-Host "BuildOutputDirectory=$($BuildOutputDirectory)"
1818
Write-Host "BuildOutputDirectory contents"
19-
Get-ChildItem -Path $BuildOutputDirectory -Recurse -Name
19+
# Capture the names of the files in the $BuildOutputDirectory
20+
$files = Get-ChildItem -Path $BuildOutputDirectory -Recurse -Name
21+
# Print the files to the console for debugging purposes
22+
$files | Out-Host
23+
# Filter the files to only include those that are relevant for Maven publishing
24+
# This file list will then be used further down to verify that all the required files
25+
# for either the passed $ArtifactsList or the PackageInfoDir are present.
26+
$files = $files | Where-Object { $_.EndsWith(".pom") -or $_.EndsWith(".jar") -or $_.EndsWith("-javadoc.jar") -or $_.EndsWith("-sources.jar") }
2027

2128
if (-not $ArtifactsList) {
2229
$ArtifactsList = @()
@@ -56,19 +63,19 @@ class Dependency {
5663
Dependency(
5764
[string]$inputString
5865
){
59-
$split = $inputString.Split(";")
60-
if (($split.Count -ne 3) -and ($split.Count -ne 2))
61-
{
62-
# throw and let the caller handle the error since it'll have access to the
63-
# filename of the file with the malformed line for reporting
64-
throw
65-
}
66-
$this.id = $split[0]
67-
$this.depVer = $split[1]
68-
if ($split.Count -eq 3)
69-
{
70-
$this.curVer = $split[2]
71-
}
66+
$split = $inputString.Split(";")
67+
if (($split.Count -ne 3) -and ($split.Count -ne 2))
68+
{
69+
# throw and let the caller handle the error since it'll have access to the
70+
# filename of the file with the malformed line for reporting
71+
throw
72+
}
73+
$this.id = $split[0]
74+
$this.depVer = $split[1]
75+
if ($split.Count -eq 3)
76+
{
77+
$this.curVer = $split[2]
78+
}
7279
}
7380
}
7481

@@ -78,22 +85,22 @@ function Build-Dependency-Hash-From-File {
7885
[string]$depFile)
7986
foreach($line in Get-Content $depFile)
8087
{
81-
if (!$line -or $line.Trim() -eq '' -or $line.StartsWith("#"))
88+
if (!$line -or $line.Trim() -eq '' -or $line.StartsWith("#"))
89+
{
90+
continue
91+
}
92+
try {
93+
[Dependency]$dep = [Dependency]::new($line)
94+
if ($depHash.ContainsKey($dep.id))
8295
{
83-
continue
84-
}
85-
try {
86-
[Dependency]$dep = [Dependency]::new($line)
87-
if ($depHash.ContainsKey($dep.id))
88-
{
89-
Write-Host "Error: Duplicate dependency encountered. '$($dep.id)' defined in '$($depFile)' already exists in the dependency list which means it is defined in multiple version_*.txt files."
90-
continue
91-
}
92-
$depHash.Add($dep.id, $dep)
93-
}
94-
catch {
95-
Write-Host "Invalid dependency line='$($line) in file=$($depFile)"
96+
Write-Host "Error: Duplicate dependency encountered. '$($dep.id)' defined in '$($depFile)' already exists in the dependency list which means it is defined in multiple version_*.txt files."
97+
continue
9698
}
99+
$depHash.Add($dep.id, $dep)
100+
}
101+
catch {
102+
Write-Host "Invalid dependency line='$($line) in file=$($depFile)"
103+
}
97104
}
98105
}
99106

@@ -112,7 +119,11 @@ foreach($artifact in $ArtifactsList) {
112119
$libHashKey = "$($artifact.groupId):$($artifact.name)"
113120
foreach ($fileType in $requiredFileTypes) {
114121
$fileName = "$($artifact.name)-$($libHash[$libHashKey].curVer)$($fileType)"
115-
$file = @(Get-ChildItem -Path $BuildOutputDirectory -Recurse -Name $fileName)
122+
# Only need to check for a file ending with the $fileName.
123+
# A previous version of this script used Get-ChildItem with a check for $fileName.
124+
# That was extremely inefficient as the $BuildOutputDirectory can contain thousands of files.
125+
# Using Where-Object to filter the files is much more efficient.
126+
$file = $files | Where-Object { $_.EndsWith($fileName) }
116127
if (!$file) {
117128
$foundError = $true
118129
LogError "Required file, $fileName, was not produced with the build."

0 commit comments

Comments
 (0)