Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(virtualbox) Add missing dependency for 7.0 stream #2041

Merged
Merged
11 changes: 11 additions & 0 deletions automatic/virtualbox/update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ function GetLatest {
}
}

function global:au_AfterUpdate {
$nuspecPath = ".\$($Latest.PackageName).nuspec"

Clear-DependenciesList $nuspecPath
Add-Dependency $nuspecPath 'chocolatey-core.extension' '1.3.3'

if ([Version] $Latest.Stream -ge '7.0') {
Add-Dependency $nuspecPath 'vcredist140' '14.20.27508.1'
}
}

function global:au_SearchReplace {
@{
".\tools\chocolateyInstall.ps1" = @{
Expand Down
43 changes: 43 additions & 0 deletions scripts/Add-Dependency.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function Add-Dependency([string]$Path, [string]$id, [string]$version) {
$nu = Import-Nuspec $Path
$dependencies = Get-DependenciesElement $nu
if (!$dependencies) {
$dependencies = $nu.CreateElement('dependencies')
$nu.package.metadata.AppendChild($dependencies) | Out-Null
}

if (!(Test-HasDependency -dependenciesElement $dependencies -id $id)) {
$dependency = $nu.CreateElement('dependency')
$dependency.SetAttribute('id', $id) | Out-Null
if ($version) {
$dependency.SetAttribute('version', $version) | Out-Null
}
$dependencies.AppendChild($dependency) | Out-Null

Export-Nuspec $Path $nu
}
}

function Import-Nuspec([string]$Path) {
$Path = Resolve-Path $Path
$nu = New-Object xml
$nu.PSBase.PreserveWhitespace = $true
$nu.Load($Path)
return $nu
}

function Get-DependenciesElement([xml]$nu) {
return $nu.package.metadata.GetElementsByTagName('dependencies') | Select-Object -First 1
}

function Test-HasDependency([System.Xml.XmlElement] $dependenciesElement, $id) {
$childElements = $dependenciesElement.GetElementsByTagName('dependency') | ? { $_.id -eq $id }
return $null -ne $childElements
}

function Export-Nuspec([string]$Path, [xml]$nu) {
$Path = Resolve-Path $Path
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
$xml = $nu.InnerXml
[System.IO.File]::WriteAllText($Path, $xml, $utf8NoBom)
}
28 changes: 28 additions & 0 deletions scripts/Clear-DependenciesList.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function Clear-DependenciesList([string]$Path) {
$nu = Import-Nuspec $Path
$dependencies = Get-DependenciesElement $nu
if ($dependencies -and $dependencies.HasChildNodes) {
$dependencies.RemoveAll() | Out-Null

Export-Nuspec $Path $nu
}
}

function Import-Nuspec([string]$Path) {
$Path = Resolve-Path $Path
$nu = New-Object xml
$nu.PSBase.PreserveWhitespace = $true
$nu.Load($Path)
return $nu
}

function Get-DependenciesElement([xml]$nu) {
return $nu.package.metadata.GetElementsByTagName('dependencies') | Select-Object -First 1
}

function Export-Nuspec([string]$Path, [xml]$nu) {
$Path = Resolve-Path $Path
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
$xml = $nu.InnerXml
[System.IO.File]::WriteAllText($Path, $xml, $utf8NoBom)
}
2 changes: 2 additions & 0 deletions scripts/au_extensions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# but the file containing the functions is expected
# to be named using the same name.
$funcs = @(
'Add-Dependency'
'Clear-DependenciesList'
'Get-GitHubRelease'
'Set-DescriptionFromReadme'
'Update-ChangelogVersion'
Expand Down