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 <freddydk@users.noreply.github.com>
This commit is contained in:
Freddy Kristiansen 2024-01-08 06:43:49 +01:00 коммит произвёл GitHub
Родитель 05197a91d0
Коммит 93ef672576
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
12 изменённых файлов: 108 добавлений и 67 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -25,64 +25,40 @@ function Sort-AppFilesByDependencies {
[switch] $excludeRuntimePackages
)
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
if (!$appFiles) {
return @()
}
$sharedFolder = ""
if ($containerName) {
$sharedFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\$containerName\$([Guid]::NewGuid().ToString())"
New-Item $sharedFolder -ItemType Directory | Out-Null
}
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
if (!$appFiles) {
return @()
}
# 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)"
@ -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

Просмотреть файл

@ -99,7 +99,7 @@ try {
$appVersionNumber = ""
if ($appFile) {
$appJson = GetAppJsonFromAppFile -appFile $appFile
$appJson = Get-AppJsonFromAppFile -appFile $appFile
$appVersionNumber = [System.Version]$appJson.version
}

Просмотреть файл

@ -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',

Просмотреть файл

@ -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")

Просмотреть файл

@ -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'
@ -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"

Просмотреть файл

@ -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

Просмотреть файл

@ -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))"
}

Просмотреть файл

@ -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)

Просмотреть файл

@ -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) {