-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstup-jacoco-xml-to-html.ps1
73 lines (64 loc) · 2.42 KB
/
constup-jacoco-xml-to-html.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
param (
[Parameter(Mandatory=$true)]
[String]$config
)
. (Resolve-Path "$PSScriptRoot\src\config.ps1").Path
. (Resolve-Path "$PSScriptRoot\src\assets.ps1").Path
. (Resolve-Path "$PSScriptRoot\src\render.ps1").Path
. (Resolve-Path "$PSScriptRoot\src\xml-reader.ps1").Path
. (Resolve-Path "$PSScriptRoot\src\templates\templates.ps1").Path
$version = Get-Content -Raw -Path (Resolve-Path "$PSScriptRoot\version").Path
Write-Host "constUP JaCoCo XML to HTML Code Coverage Report Generator $version"
Write-Host "=========="
Write-Host ""
Write-Host " Loading configuration..."
Load-Config -configFileLocation $config
$xmlFile = $Global:jacocoxml2htmlConfig.xml_file
$destinationDirectory = $Global:jacocoxml2htmlConfig.destination_directory
$sourcesDirectory = $Global:jacocoxml2htmlConfig.sources_directory
Write-Host " Configuration loaded."
Write-Host ' Checking XML file...'
if (-Not (Test-Path $xmlFile)) {
Write-Error "XML file $xmlFile either does not exist or can not be read."
exit 1
}
Write-Host ' XML file is present.'
Write-Host ' Checking destination directory...'
if (-Not (Test-Path $destinationDirectory)) {
try {
New-Item -ItemType Directory -Path $destinationDirectory -Force > $null
}
catch
{
Write-Error "Invalid destination directory or directory can not be created."
exit 1
}
} else {
if ((Get-ChildItem -Path $destinationDirectory | Measure-Object).Count -ne 0) {
throw "Destination directory is not empty."
exit 1
}
}
Write-Host ' Destination directory is ready.'
Write-Host ' Creating base template assets...'
try {
Copy-Assets -destinationDirectory $destinationDirectory
Set-Content -Path "$destinationDirectory/index.html" -Value ""
} catch {
Write-Error "There was a problem while trying to write base template files in: $destinationDirectory"
exit 1
}
Write-Host ' Base template assets are ready.'
Write-Host ' Preloading templates...'
$preloadedTemplates = Preload-Templates
Write-Host ' Templates are loaded.'
Write-Host ' Rendering files...'
$xmlObject = Read-XML -filePath $xmlFile
Render-Files `
-destinationDirectory $destinationDirectory `
-xmlObject $xmlObject `
-preloadedTemplates $preloadedTemplates `
-sourcesDirectory $sourcesDirectory
Write-Host ' All files are rendered.'
Write-Host ''
Write-Host "HTML coverage report has been successfully generated."