Skip to content

Commit

Permalink
NuGet changes (#3289)
Browse files Browse the repository at this point in the history
Expose Copy-AppFilesToFolder and Get-AppJsonFromAppFile to public
Make Sort-AppFilesByDependencies use Get-AppJsonFromAppFile instead of a
container
Fix bug in NormalizeVersionStr
New function Create-SymbolsFileFromAppFile

---------

Co-authored-by: freddydk <[email protected]>
  • Loading branch information
freddydk and freddydk authored Jan 8, 2024
1 parent 05197a9 commit 93ef672
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 66 deletions.
20 changes: 20 additions & 0 deletions AppHandling/Copy-AppFilesToFolder.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<#
.Synopsis
Copy App Files to Folder (supporting urls, .zip files and .app files)
.Description
.Parameter appFiles
Can be an array of appfiles, urls or zip files
.Parameter folder
Folder to copy the app files to
.Example
Copy-AppFilesToFolder -appFiles @("c:\temp\apps.zip", "c:\temp\app2.app", "https://github.com/org/repo/releases/download/2.0.200/project-branch-Apps-1.0.0.0.zip") -folder "c:\temp\appfiles"
#>
function Copy-AppFilesToFolder {
Param(
$appFiles,
[string] $folder
)

CopyAppFilesToFolder -appFiles $appFiles -folder $folder
}
Export-ModuleMember -Function Copy-AppFilesToFolder
21 changes: 21 additions & 0 deletions AppHandling/Create-SymbolsFileFromAppFile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<#
.Synopsis
Create a Symbols only .app file from an .app file
.Description
.Parameter AppFile
Path of the application file which should be converted to symbols
.Parameter symbolsFile
Path of the symbols file which should be created
.Example
Create-SymbolsFileFromAppFile -appFile c:\temp\baseapp.app -symbolsFile c:\temp\baseapp.symbols.app
#>
function Create-SymbolsFileFromAppFile {
Param(
[Parameter(Mandatory=$true)]
[string] $appFile,
[Parameter(Mandatory=$true)]
[string] $symbolsFile
)
RunAlTool -arguments @('CreateSymbolPackage', """$appFile""", """$symbolsFile""")
}
Export-ModuleMember -Function Create-SymbolsFileFromAppFile
20 changes: 20 additions & 0 deletions AppHandling/Get-AppJsonFromAppFile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<#
.Synopsis
Extract the app.json file from an app (also from runtime packages)
.Description
.Parameter AppFile
Path of the application file from which to extract the app.json
.Example
Get-AppJsonFromAppFile -appFile c:\temp\baseapp.app
#>
function Get-AppJsonFromAppFile {
Param(
[Parameter(Mandatory=$true)]
[string] $appFile
)
$appJson = RunAlTool -arguments @('GetPackageManifest', """$appFile""")
if (!($appJson.PSObject.Properties.Name -eq "description")) { Add-Member -InputObject $appJson -MemberType NoteProperty -Name "description" -Value "" }
if (!($appJson.PSObject.Properties.Name -eq "dependencies")) { Add-Member -InputObject $appJson -MemberType NoteProperty -Name "dependencies" -Value @() }
return $appJson
}
Export-ModuleMember -Function Get-AppJsonFromAppFile
80 changes: 25 additions & 55 deletions AppHandling/Sort-AppFilesByDependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,64 +25,40 @@ function Sort-AppFilesByDependencies {
[switch] $excludeRuntimePackages
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

if (!$appFiles) {
return @()
}
if (!$appFiles) {
return @()
}

$sharedFolder = ""
if ($containerName) {
$sharedFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\$containerName\$([Guid]::NewGuid().ToString())"
New-Item $sharedFolder -ItemType Directory | Out-Null
}
try {
# Read all app.json objects, populate $apps
$apps = $()
$files = @{}
$appFiles | ForEach-Object {
$appFile = $_
$includeIt = $true
if ($excludeRuntimePackages -or !(Test-BcContainer -containerName $containerName)) {
$tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
try {
Extract-AppFileToFolder -appFilename $appFile -appFolder $tmpFolder -generateAppJson 6> $null
$appJsonFile = Join-Path $tmpFolder "app.json"
$appJson = [System.IO.File]::ReadAllLines($appJsonFile) | ConvertFrom-Json
}
catch {
if ($_.exception.message -eq "You cannot extract a runtime package") {
if ($excludeRuntimePackages) {
$includeIt = $false
}
else {
throw "AppFile $appFile is a runtime package. You will have to specify a running container in containerName in order to analyze dependencies between runtime packages"
}
$tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
try {
Extract-AppFileToFolder -appFilename $appFile -appFolder $tmpFolder -generateAppJson 6> $null
$appJsonFile = Join-Path $tmpFolder "app.json"
$appJson = [System.IO.File]::ReadAllLines($appJsonFile) | ConvertFrom-Json
}
catch {
if ($_.exception.message -eq "You cannot extract a runtime package") {
if ($excludeRuntimePackages) {
$includeIt = $false
}
else {
throw "Unable to extract and analyze appFile $appFile"
$appJson = Get-AppJsonFromAppFile -appFile $appFile
}
}
finally {
Remove-Item $tmpFolder -Recurse -Force -ErrorAction SilentlyContinue
else {
throw "Unable to extract and analyze appFile $appFile"
}
}
else {
$destFile = Join-Path $sharedFolder ([System.IO.Path]::GetFileName($appFile))
Copy-Item -Path $appFile -Destination $destFile
$appJson = Invoke-ScriptInBcContainer -containerName $containerName -scriptblock { Param($appFile)
Get-NavAppInfo -Path $appFile | ConvertTo-Json -Depth 99
} -argumentList (Get-BcContainerPath -containerName $containerName -path $destFile) | ConvertFrom-Json
Remove-Item -Path $destFile
$appJson.Version = "$($appJson.Version.Major).$($appJson.Version.Minor).$($appJson.Version.Build).$($appJson.Version.Revision)"
$appJson | Add-Member -NotePropertyName 'Id' -NotePropertyValue $appJson.AppId.Value
if ($appJson.Dependencies) {
$appJson.Dependencies | ForEach-Object { if ($_) {
$_ | Add-Member -NotePropertyName 'Id' -NotePropertyValue $_.AppId
$_ | Add-Member -NotePropertyName 'Version' -NotePropertyValue "$($_.MinVersion.Major).$($_.MinVersion.Minor).$($_.MinVersion.Build).$($_.MinVersion.Revision)"
} }
}
finally {
Remove-Item $tmpFolder -Recurse -Force -ErrorAction SilentlyContinue
}
if ($includeIt) {
$key = "$($appJson.Id):$($appJson.Version)"
Expand Down Expand Up @@ -191,18 +167,12 @@ try {
} })
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
if ($sharedFolder) {
Remove-Item $sharedFolder -Recurse -Force
}
TrackTrace -telemetryScope $telemetryScope
}
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
throw
}
finally {
TrackTrace -telemetryScope $telemetryScope
}
}
Export-ModuleMember -Function Sort-AppFilesByDependencies
2 changes: 1 addition & 1 deletion AppSource/New-AppSourceSubmission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ try {

$appVersionNumber = ""
if ($appFile) {
$appJson = GetAppJsonFromAppFile -appFile $appFile
$appJson = Get-AppJsonFromAppFile -appFile $appFile
$appVersionNumber = [System.Version]$appJson.version
}

Expand Down
5 changes: 3 additions & 2 deletions BcContainerHelper.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ FunctionsToExport = 'Add-FontsToBcContainer', 'Add-GitToAlProjectFolder',
'Create-MyOriginalFolder', 'Download-Artifacts', 'Download-File',
'Enter-BcContainer', 'Export-BcContainerDatabasesAsBacpac',
'Export-ModifiedObjectsAsDeltas', 'Export-NavContainerObjects',
'Extract-AppFileToFolder', 'Extract-FilesFromBcContainerImage',
'Extract-AppFileToFolder', 'Get-AppJsonFromAppFile',
'Copy-AppFilesToFolder', 'Extract-FilesFromBcContainerImage',
'Extract-FilesFromStoppedBcContainer', 'Flush-ContainerHelperCache',
'Generate-SymbolsInNavContainer',
'Generate-SymbolsInNavContainer', 'Create-SymbolsFileFromAppFile',
'Get-AlLanguageExtensionFromArtifacts', 'Get-AlpacaBcContainer',
'Get-AlpacaBcContainerEventLog', 'Get-AppSourceProduct',
'Get-AppSourceSubmission', 'Get-AzureFeedWildcardVersion',
Expand Down
3 changes: 3 additions & 0 deletions BcContainerHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ if ($isWindows) {
. (Join-Path $PSScriptRoot "AppHandling\Convert-BcAppsToRuntimePackages.ps1")
. (Join-Path $PSScriptRoot "AppHandling\Get-NavContainerApp.ps1")
. (Join-Path $PSScriptRoot "AppHandling\Extract-AppFileToFolder.ps1")
. (Join-Path $PSScriptRoot "AppHandling\Get-AppJsonFromAppFile.ps1")
. (Join-Path $PSScriptRoot "AppHandling\Create-SymbolsFileFromAppFile.ps1")
. (Join-Path $PSScriptRoot "AppHandling\Copy-AppFilesToFolder.ps1")
. (Join-Path $PSScriptRoot "AppHandling\Replace-DependenciesInAppFile.ps1")
. (Join-Path $PSScriptRoot "AppHandling\Run-TestsInNavContainer.ps1")
. (Join-Path $PSScriptRoot "AppHandling\Run-BCPTTestsInBcContainer.ps1")
Expand Down
13 changes: 8 additions & 5 deletions HelperFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,8 @@ function GetAppInfo {
if ($isLinux) {
$alcPath = Join-Path $binPath 'linux'
$alToolExe = Join-Path $alcPath 'altool'
Write-Host "Setting execute permissions on altool"
& /usr/bin/env sudo pwsh -command "& chmod +x $alToolExe"
}
else {
$alcPath = Join-Path $binPath 'win32'
Expand Down Expand Up @@ -1326,25 +1328,26 @@ function DownloadLatestAlLanguageExtension {
}
}

function GetAppJsonFromAppFile {
function RunAlTool {
Param(
[string] $appFile
[string[]] $arguments
)
# ALTOOL is at the moment only available in prerelease
$path = DownloadLatestAlLanguageExtension -allowPrerelease
if ($isLinux) {
$alToolExe = Join-Path $path 'extension/bin/linux/altool'
Write-Host "Setting execute permissions on altool"
& /usr/bin/env sudo pwsh -command "& chmod +x $alToolExe"
}
else {
$alToolExe = Join-Path $path 'extension/bin/win32/altool.exe'
}
$appJson = CmdDo -Command $alToolExe -arguments @('GetPackageManifest', """$appFile""") -returnValue -silent | ConvertFrom-Json
return $appJson
return CmdDo -Command $alToolExe -arguments $arguments -returnValue -silent | ConvertFrom-Json
}

function GetApplicationDependency( [string] $appFile, [string] $minVersion = "0.0" ) {
try {
$appJson = GetAppJsonFromAppFile -appFile $appFile
$appJson = Get-AppJsonFromAppFile -appFile $appFile
}
catch {
Write-Host -ForegroundColor Red "Unable to read app $([System.IO.Path]::GetFileName($appFile)), ignoring application dependency check"
Expand Down
2 changes: 1 addition & 1 deletion NuGet/New-BcNuGetPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Function New-BcNuGetPackage {
}
}
}
$appJson = GetAppJsonFromAppFile -appFile $appFile
$appJson = Get-AppJsonFromAppFile -appFile $appFile
$packageId = $packageId.replace('{id}',$appJson.id).replace('{name}',[nuGetFeed]::Normalize($appJson.name)).replace('{publisher}',[nuGetFeed]::Normalize($appJson.publisher)).replace('{version}',$appJson.version.replace('.','-'))
if ($null -eq $packageVersion) {
$packageVersion = [System.Version]$appJson.version
Expand Down
2 changes: 1 addition & 1 deletion NuGet/NuGetFeedClass.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ class NuGetFeed {
static [string] NormalizeVersionStr([string] $versionStr) {
$idx = $versionStr.IndexOf('-')
$version = [System.version]($versionStr.Split('-')[0])
if ($version.Build -eq -1) { $version = [System.Version]::new($version.Major, $version.Minor, 0, 0) }
if ($version.Revision -eq -1) { $version = [System.Version]::new($version.Major, $version.Minor, $version.Build, 0) }
if ($version.Build -eq -1) { $version = [System.Version]::new($version.Major, $version.Minor, 0, $version.Revision) }
if ($idx -gt 0) {
return "$version$($versionStr.Substring($idx))"
}
Expand Down
3 changes: 3 additions & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Support searching for Earliest, Latest, Exact or Any NuGet package (default is L
Reset startcount when using Restart-BcContainer
Issue 3277 Run-ALCops uses wrong CodeAnalysis dll path
Add support for useDevEndpoint in Run-AlPipeline when importing test toolkit
New function Get-AppJsonFromAppFile to extract the app.json file from an app (also from a runtime package)
New function Copy-AppFilesToFolder to copy or download and unpack all apps from an array of .zip or .app files and place them in a folder
New function Create-SymbolsFileFromAppFile to create a symbols only app file from an app file

6.0.3
Just-In-Time install dotnet 8.0.0 for Business Central version 24 or above (needed by alc.exe)
Expand Down
2 changes: 1 addition & 1 deletion Saas/Publish-PerTenantExtensionApps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ try {
try {
Sort-AppFilesByDependencies -appFiles $appFiles -excludeRuntimePackages | ForEach-Object {
Write-Host -NoNewline "$([System.IO.Path]::GetFileName($_)) - "
$appJson = GetAppJsonFromAppFile -appFile $_
$appJson = Get-AppJsonFromAppFile -appFile $_

$existingApp = $extensions | Where-Object { $_.id -eq $appJson.id -and $_.isInstalled }
if ($existingApp) {
Expand Down

0 comments on commit 93ef672

Please sign in to comment.