Skip to content

Commit 2b9575f

Browse files
committed
0.1.1
Fixes: - moved main script to src to be more testable
1 parent 8889f60 commit 2b9575f

File tree

2 files changed

+106
-51
lines changed

2 files changed

+106
-51
lines changed

constup-jacoco-xml-to-html.ps1

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ param (
33
[String]$config
44
)
55

6-
& .\src\main.ps1 -config $config
6+
. (Resolve-Path "$PSScriptRoot/src/main.ps1").Path
7+
8+
Run-Flow -config $config

src/main.ps1

+103-50
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,126 @@
1-
param (
2-
[Parameter(Mandatory=$true)]
3-
[String]$config
4-
)
5-
61
. (Resolve-Path "$PSScriptRoot\config.ps1").Path
72
. (Resolve-Path "$PSScriptRoot\assets.ps1").Path
83
. (Resolve-Path "$PSScriptRoot\render.ps1").Path
94
. (Resolve-Path "$PSScriptRoot\xml-reader.ps1").Path
105
. (Resolve-Path "$PSScriptRoot\templates\templates.ps1").Path
116

12-
$version = Get-Content -Raw -Path (Resolve-Path "$PSScriptRoot\version").Path
13-
Write-Host "constUP JaCoCo XML to HTML Code Coverage Report Generator $version"
14-
Write-Host "=========="
15-
Write-Host ""
7+
function Write-Version {
8+
$version = Get-Content -Raw -Path (Resolve-Path "$PSScriptRoot\..\version").Path
9+
Write-Host "constUP JaCoCo XML to HTML Code Coverage Report Generator $version"
10+
Write-Host "=========="
11+
Write-Host ""
12+
}
1613

17-
Write-Host " Loading configuration..."
18-
Load-Config -configFileLocation $config
19-
$xmlFile = $Global:jacocoxml2htmlConfig.xml_file
20-
$destinationDirectory = $Global:jacocoxml2htmlConfig.destination_directory
21-
$sourcesDirectory = $Global:jacocoxml2htmlConfig.sources_directory
22-
Write-Host " Configuration loaded."
14+
function Load-Configuration {
15+
param(
16+
[Parameter(Mandatory=$true)]
17+
[PSCustomObject]$config
18+
)
2319

24-
Write-Host ' Checking XML file...'
25-
if (-Not (Test-Path $xmlFile)) {
26-
Write-Error "XML file $xmlFile either does not exist or can not be read."
27-
exit 1
20+
Write-Host " Loading configuration..."
21+
Load-Config -configFileLocation $config
22+
Write-Host " Configuration loaded."
2823
}
29-
Write-Host ' XML file is present.'
3024

31-
Write-Host ' Checking destination directory...'
32-
if (-Not (Test-Path $destinationDirectory)) {
33-
try {
34-
New-Item -ItemType Directory -Path $destinationDirectory -Force > $null
35-
}
36-
catch
37-
{
38-
Write-Error "Invalid destination directory or directory can not be created."
25+
function Check-XmlFile {
26+
param(
27+
[Parameter(Mandatory=$true)]
28+
[String]$xmlFile
29+
)
30+
Write-Host ' Checking XML file...'
31+
if (-Not (Test-Path $xmlFile)) {
32+
Write-Error "XML file $xmlFile either does not exist or can not be read."
3933
exit 1
4034
}
41-
} else {
42-
if ((Get-ChildItem -Path $destinationDirectory | Measure-Object).Count -ne 0) {
43-
throw "Destination directory is not empty."
44-
exit 1
35+
Write-Host ' XML file is present.'
36+
}
37+
38+
function Check-DestinationDirectory {
39+
param(
40+
[Parameter(Mandatory=$true)]
41+
[String]$destinationDirectory
42+
)
43+
Write-Host ' Checking destination directory...'
44+
if (-Not (Test-Path $destinationDirectory)) {
45+
try {
46+
New-Item -ItemType Directory -Path $destinationDirectory -Force > $null
47+
}
48+
catch
49+
{
50+
Write-Error "Invalid destination directory or directory can not be created."
51+
exit 1
52+
}
53+
} else {
54+
if ((Get-ChildItem -Path $destinationDirectory | Measure-Object).Count -ne 0) {
55+
throw "Destination directory is not empty."
56+
exit 1
57+
}
4558
}
59+
Write-Host ' Destination directory is ready.'
4660
}
47-
Write-Host ' Destination directory is ready.'
4861

49-
Write-Host ' Creating base template assets...'
50-
try {
51-
Copy-Assets -destinationDirectory $destinationDirectory
52-
Set-Content -Path "$destinationDirectory/index.html" -Value ""
53-
} catch {
54-
Write-Error "There was a problem while trying to write base template files in: $destinationDirectory"
55-
exit 1
62+
function Create-BaseTemplates {
63+
param(
64+
[Parameter(Mandatory=$true)]
65+
[String]$destinationDirectory
66+
)
67+
68+
Write-Host ' Creating base template assets...'
69+
try {
70+
Copy-Assets -destinationDirectory $destinationDirectory
71+
Set-Content -Path "$destinationDirectory/index.html" -Value ""
72+
} catch {
73+
Write-Error "There was a problem while trying to write base template files in: $destinationDirectory"
74+
exit 1
75+
}
76+
Write-Host ' Base template assets are ready.'
5677
}
57-
Write-Host ' Base template assets are ready.'
5878

59-
Write-Host ' Preloading templates...'
60-
$preloadedTemplates = Preload-Templates
61-
Write-Host ' Templates are loaded.'
79+
function Render-AllFiles {
80+
param(
81+
[Parameter(Mandatory=$true)]
82+
[String]$xmlFile,
83+
[Parameter(Mandatory=$true)]
84+
[String]$destinationDirectory,
85+
[Parameter(Mandatory=$true)]
86+
[PSCustomObject]$xmlObject,
87+
[Parameter(Mandatory=$true)]
88+
[PSCustomObject]$preloadedTemplates,
89+
[Parameter(Mandatory=$true)]
90+
[String]$sourcesDirectory
91+
)
6292

63-
Write-Host ' Rendering files...'
64-
$xmlObject = Read-XML -filePath $xmlFile
65-
Render-Files `
93+
Write-Host ' Rendering files...'
94+
Render-Files `
6695
-destinationDirectory $destinationDirectory `
6796
-xmlObject $xmlObject `
6897
-preloadedTemplates $preloadedTemplates `
6998
-sourcesDirectory $sourcesDirectory
70-
Write-Host ' All files are rendered.'
71-
Write-Host ''
99+
Write-Host ' All files are rendered.'
100+
Write-Host ''
101+
}
72102

73-
Write-Host "HTML coverage report has been successfully generated."
103+
function Run-Flow {
104+
param(
105+
[Parameter(Mandatory=$true)]
106+
[PSCustomObject]$config
107+
)
108+
109+
Write-Version
110+
Load-Configuration -config $config
111+
$xmlFile = $Global:jacocoxml2htmlConfig.xml_file
112+
$destinationDirectory = $Global:jacocoxml2htmlConfig.destination_directory
113+
$sourcesDirectory = $Global:jacocoxml2htmlConfig.sources_directory
114+
Check-XmlFile -xmlFile $xmlFile
115+
Check-DestinationDirectory -destinationDirectory $destinationDirectory
116+
Create-BaseTemplates -destinationDirectory $destinationDirectory
117+
$preloadedTemplates = Preload-Templates
118+
$xmlObject = Read-XML -filePath $xmlFile
119+
Render-AllFiles `
120+
-xmlFile $xmlFile `
121+
-destinationDirectory $destinationDirectory `
122+
-xmlObject $xmlObject `
123+
-preloadedTemplates $preloadedTemplates `
124+
-sourcesDirectory $sourcesDirectory
125+
Write-Host "HTML coverage report has been successfully generated."
126+
}

0 commit comments

Comments
 (0)