Skip to content

Commit 8dca978

Browse files
committed
fix: write normalized JaCoCo without BOM
1 parent 8893be8 commit 8dca978

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

scripts/build/ci/Repair-CodeSceneJaCoCoCoverage.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,17 @@ function Repair-CodeSceneJaCoCoCoverageFile {
4343
$changed = (Repair-CodeSceneJaCoCoNodePathAttribute -Nodes $document.SelectNodes('//sourcefile[@name]') -AttributeName 'name') -or $changed
4444

4545
if ($changed) {
46-
$document.Save($Path)
46+
$settings = New-Object System.Xml.XmlWriterSettings
47+
$settings.Encoding = New-Object System.Text.UTF8Encoding($false)
48+
$settings.Indent = $false
49+
$settings.NewLineHandling = [System.Xml.NewLineHandling]::None
50+
$writer = [System.Xml.XmlWriter]::Create($Path, $settings)
51+
try {
52+
$document.Save($writer)
53+
} finally {
54+
$writer.Dispose()
55+
}
56+
4757
Write-Host "Normalized JaCoCo sourcefile paths in '$Path' so package + sourcefile resolve to repo files."
4858
}
4959
}

tests/Repair-CodeSceneJaCoCoCoverage.Tests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Describe 'Repair-CodeSceneJaCoCoCoverage' {
5151
[xml]$rewritten = Get-Content -LiteralPath $coveragePath -Raw
5252
$rewritten.SelectSingleNode('//class[@sourcefilename]').GetAttribute('sourcefilename') | Should -Be 'Foo.ps1'
5353
$rewritten.SelectSingleNode('//sourcefile[@name]').GetAttribute('name') | Should -Be 'Foo.ps1'
54+
[byte[]]$bytes = [System.IO.File]::ReadAllBytes($coveragePath)
55+
$bytes[0] | Should -Be 60
5456
}
5557

5658
It 'leaves already normalized filenames unchanged' {

0 commit comments

Comments
 (0)