azure-sdk-for-cpp/eng/common/scripts/Helpers/Package-Helpers.ps1
Azure SDK Bot 164a2d6a9a
Sync eng/common directory with azure-sdk-tools for PR 3267 (#3655)
* Use seperate scripts

* address comments.

* do compare and update

* save on the service level readme

* have the helper for reuse function

* remove mgmt table

* changes

* fix

* no return on error

* return if no contents

* Address comments

* change the table

* address wes comments.

* address wes comments.

* address more comments.

Co-authored-by: sima-zhu <sizhu@microsoft.com>
2022-06-14 08:36:00 -07:00

38 lines
1.1 KiB
PowerShell

function GetPackageKey($pkg) {
$pkgKey = $pkg.Package
$groupId = $null
if ($pkg.PSObject.Members.Name -contains "GroupId") {
$groupId = $pkg.GroupId
}
if ($groupId) {
$pkgKey = "${groupId}:${pkgKey}"
}
return $pkgKey
}
# Different language needs a different way to index the package. Build a map in convienice to lookup the package.
# E.g. <groupId>:<packageName> is the package key in java.
function GetPackageLookup($packageList) {
$packageLookup = @{}
foreach ($pkg in $packageList) {
$pkgKey = GetPackageKey $pkg
# We want to prefer updating non-hidden packages but if there is only
# a hidden entry then we will return that
if (!$packageLookup.ContainsKey($pkgKey) -or $packageLookup[$pkgKey].Hide -eq "true") {
$packageLookup[$pkgKey] = $pkg
}
else {
# Warn if there are more then one non-hidden package
if ($pkg.Hide -ne "true") {
Write-Host "Found more than one package entry for $($pkg.Package) selecting the first non-hidden one."
}
}
}
return $packageLookup
}