public/New-AutAsaprojXML.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<#
.SYNOPSIS
Controller script used to create a new XML asaproj file from a JSON one. If one already exists it will be overwritten.
 
.DESCRIPTION
The tool used to run tests in unittest_prun (sa.exe) requires a manifest file (.asaproj) that describes the content of the asa project.
At the moment, Visual Studio generates XML asaproj files, Visual Studio Code generates JSON asaproj files.
The XML ones are the one expected by sa.exe.
 
New-AUTAsaparoj will take a JSON asaproj file (generated previously by Visual Studio Code), and create the equivalent XML file.
If one already exists it will be overwritten.
Not every item will be ported, only those required during a test run will (asaql, jobconfig, local mock inputs).
 
See documentation for more information : https://github.com/Fleid/asa.unittest
 
.PARAMETER sourceAsaproj
PowerShell object converted from an asaproj.json. The easiest way to generate this is to use `(Get-Content asaproj.json | ConvertFrom-JSON)`
 
.EXAMPLE
(Get-Content asaproj.json | ConvertFrom-JSON) | New-AutAsaprojXML |Out-File ASAHelloWorld.asaproj
#>


function New-AutAsaprojXML{

    [CmdletBinding(
        SupportsShouldProcess=$true,
        ConfirmImpact="Low"
        )]
    param (
        [Parameter(ValueFromPipeline=$true)]
        [PSCustomObject]$sourceAsaproj
    )

    BEGIN {}

    PROCESS {
        if ($pscmdlet.ShouldProcess("Generating a XML file for $sourceAsaproj"))
            {

            ################################################################################################################################
            write-verbose "001 - Testing the input"

            if (($null -eq $sourceAsaproj.startFile) -or ($sourceAsaproj.startFile -eq "")) {
                Throw "Error : startFile (aka .asaql path) is missing or empty from input asaProj file"
            }

            if (-not ($sourceAsaproj.configurations | Where-Object {$_.subType -in "JobConfig"})) {
                Throw "Error : JobConfig path is missing or empty from input asaProj file"
            }

            ################################################################################################################################

            # Constants
            $newline = "`r`n"
            $header = "<Project ToolsVersion=`"4.0`" DefaultTargets=`"Build`" xmlns=`"http://schemas.microsoft.com/developer/msbuild/2003`">"
            $footer = "</Project>"
            $itemGroupStart = "<ItemGroup>"
            $itemGroupEnd = "</ItemGroup>"
            $itemFilter = @("InputMock","JobConfig")

            ################################################################################################################################
            write-verbose "101 - Generating the XML asaproj"

            # Header
            $targetAsaproj = $header + $newline

            # First ItemGroup for script file (asaql)
            $targetAsaproj += $itemGroupStart + $newline
            $targetAsaproj += "<Script Include=`"$($sourceAsaproj.startFile)`"/>" + $newline
            $targetAsaproj += $itemGroupEnd + $newline

            # Second ItemGroup for InputMock (local input config files) and JobConfig
            $targetAsaproj += $itemGroupStart + $newline

            $sourceAsaproj.configurations | `
                Where-Object {$_.subType -in $itemFilter} |
                Foreach-Object -process {
                    $targetAsaproj += "<Configure Include=`"$($_.filePath)`">" + $newline
                    $targetAsaproj += "<SubType>$($_.subType)</SubType>" + $newline
                    $targetAsaproj += "</Configure>" + $newline
                }

            $targetAsaproj += $itemGroupEnd + $newline

            # Footer
            $targetAsaproj += $footer + $newline

            ################################################################################################################################
            write-verbose "401 - Writing the content to ouptut pipeline"

            # Create new object
            $outputObject = $targetAsaproj

            $outputObject

        } #ShouldProcess
    } #PROCESS
    END {}
}