Skip to content

Commit

Permalink
Update Get-OracleJava8.ps1
Browse files Browse the repository at this point in the history
Add file type to output
  • Loading branch information
aaronparker committed Sep 17, 2023
1 parent 9b7993a commit 23789ae
Showing 1 changed file with 30 additions and 37 deletions.
67 changes: 30 additions & 37 deletions Evergreen/Apps/Get-OracleJava8.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,43 @@
Twitter: @stealthpuppy
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $False)]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $False, Position = 0)]
[ValidateNotNull()]
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSObject]
$res = (Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1])
)

# Read the update RSS feed
$params = @{
Uri = $res.Get.Update.Uri
}
$UpdateFeed = Invoke-RestMethodWrapper @params

If ($Null -ne $UpdateFeed) {

# Latest version is the last item in the feed
# Can't cast $_.version to [System.Version] because underscore character is in the string
$Count = $UpdateFeed.'java-update-map'.mapping.Count
Write-Verbose -Message "$($MyInvocation.MyCommand): Filter $Count items in feed for latest update."
$latestUpdate = $UpdateFeed.'java-update-map'.mapping | Where-Object { $_.url -notlike "*-cb.xml" } | Select-Object -Last 1

# Read the XML listed in the most recent update
$params = @{
Uri = $latestUpdate.url
}
$Feed = Invoke-RestMethodWrapper @params

If ($Null -ne $Feed) {

# Select the update info
Write-Verbose -Message "$($MyInvocation.MyCommand): Select item in feed for $($res.Get.Update.Filter)."
$Update = $Feed.'java-update'.information | Where-Object { $_.lang -eq $res.Get.Update.Filter } | Select-Object -First 1

# Construct the output; Return the custom object to the pipeline
ForEach ($item in $res.Get.Update.FileStrings.GetEnumerator()) {
Write-Verbose -Message "$($MyInvocation.MyCommand): Build object for $($item.Name)."
$PSObject = [PSCustomObject] @{
Version = $($Update.version | Select-Object -Last 1)
Architecture = $item.Name
URI = $Update.url -replace $res.Get.Update.ReplaceText, $res.Get.Update.FileStrings[$item.Key]
}
Write-Output -InputObject $PSObject
$UpdateFeed = Invoke-RestMethodWrapper -Uri $res.Get.Update.Uri

# Latest version is the last item in the feed
# Can't cast $_.version to [System.Version] because underscore character is in the string
$Count = $UpdateFeed.'java-update-map'.mapping.Count
Write-Verbose -Message "$($MyInvocation.MyCommand): Filter $Count items in feed for latest update."
$latestUpdate = $UpdateFeed.'java-update-map'.mapping | `
Where-Object { $_.url -notlike "*-cb.xml" } | `
Select-Object -Last 1

# Read the XML listed in the most recent update
$Feed = Invoke-RestMethodWrapper -Uri $latestUpdate.url
if ($null -ne $Feed) {

# Select the update info
Write-Verbose -Message "$($MyInvocation.MyCommand): Select item in feed for $($res.Get.Update.Filter)."
$Update = $Feed.'java-update'.information | Where-Object { $_.lang -eq $res.Get.Update.Filter } | Select-Object -First 1

# Construct the output; Return the custom object to the pipeline
foreach ($item in $res.Get.Update.FileStrings.GetEnumerator()) {
Write-Verbose -Message "$($MyInvocation.MyCommand): Build object for $($item.Name)."
$PSObject = [PSCustomObject] @{
Version = $($Update.version | Select-Object -Last 1)
Architecture = $item.Name
Type = Get-FileType -File $($Update.url -replace $res.Get.Update.ReplaceText, $res.Get.Update.FileStrings[$item.Key])
URI = $Update.url -replace $res.Get.Update.ReplaceText, $res.Get.Update.FileStrings[$item.Key]
}
Write-Output -InputObject $PSObject
}
}
}

0 comments on commit 23789ae

Please sign in to comment.