From 268a2b80af82dc8e772d7d89ade57b5eccbe695f Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Sat, 14 Sep 2024 11:14:10 +0200 Subject: [PATCH] Fix windows support --- .github/workflows/ci.yml | 11 ++++- build.sbt | 21 ++++++--- .../CoberturaMultiSourceReader.scala | 6 +-- .../coveralls/CoverallPayloadWriter.scala | 3 +- src/test/resources/generate.sh | 4 -- .../test_cobertura.xml.windows.template | 43 +++++++++++++++++++ ...t_cobertura_corrupted.xml.windows.template | 1 + .../test_cobertura_dtd.xml.windows.template | 43 +++++++++++++++++++ ...cobertura_multisource.xml.windows.template | 41 ++++++++++++++++++ .../coveralls/CoverallPayloadWriterTest.scala | 3 +- 10 files changed, 159 insertions(+), 17 deletions(-) delete mode 100755 src/test/resources/generate.sh create mode 100644 src/test/resources/test_cobertura.xml.windows.template create mode 100644 src/test/resources/test_cobertura_corrupted.xml.windows.template create mode 100644 src/test/resources/test_cobertura_dtd.xml.windows.template create mode 100644 src/test/resources/test_cobertura_multisource.xml.windows.template diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a7654a..51c998f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,12 +10,21 @@ on: jobs: scala: - runs-on: ubuntu-latest strategy: + fail-fast: false # remove when PR is finished, just to make sure we don't make regression matrix: JDK: [ 8, 17 ] + os: + - ubuntu-latest + - windows-latest + runs-on: ${{ matrix.os }} steps: + - name: Ignore line ending differences in git + if: contains(runner.os, 'windows') + shell: bash + run: git config --global core.autocrlf false + - name: checkout the repo uses: actions/checkout@v4 with: diff --git a/build.sbt b/build.sbt index af4c1ef..80bbb7e 100644 --- a/build.sbt +++ b/build.sbt @@ -1,17 +1,28 @@ name := "sbt-coveralls" import sbt.ScriptedPlugin.autoImport.scriptedLaunchOpts - import scala.sys.process._ + lazy val generateXMLFiles = taskKey[Unit]("Generate XML files (for test)") generateXMLFiles := { - val log = streams.value.log - s"./src/test/resources/generate.sh" ! log + val dir = (Test / resourceDirectory).value + val pwd = (run / baseDirectory).value.absolutePath + + val template = if (System.getProperty("os.name").startsWith("Windows")) + ".xml.windows.template" + else + ".xml.template" + + dir.listFiles { (_, name) => name.endsWith(template) }.foreach { + templateFile => + val newFile = dir / templateFile.getName.replace(template, ".xml") + val content = IO.read(templateFile) + IO.write(newFile, content.replace("{{PWD}}", pwd)) + } } -lazy val prepareScripted = - taskKey[Unit]("Update .git files to make scripted work") +lazy val prepareScripted = taskKey[Unit]("Update .git files to make scripted work") prepareScripted := { val log = streams.value.log s"./src/sbt-test/prepare.sh" ! log diff --git a/src/main/scala/org/scoverage/coveralls/CoberturaMultiSourceReader.scala b/src/main/scala/org/scoverage/coveralls/CoberturaMultiSourceReader.scala index 084871b..aec5f57 100644 --- a/src/main/scala/org/scoverage/coveralls/CoberturaMultiSourceReader.scala +++ b/src/main/scala/org/scoverage/coveralls/CoberturaMultiSourceReader.scala @@ -114,7 +114,7 @@ class CoberturaMultiSourceReader( protected def lineCoverage(sourceFile: String) = { val filenamePath = - splitPath(new File(sourceFile))._2.replace(File.separator, "/") + splitPath(new File(sourceFile))._2 lineCoverageMap(filenamePath) } @@ -130,9 +130,7 @@ class CoberturaMultiSourceReader( val lineHitMap = lineCoverage(source) val fullLineHit = (0 until lineCount).map(i => lineHitMap.get(i + 1)) - val sourceNormalized = source.replace(File.separator, "/") - - SourceFileReport(sourceNormalized, fullLineHit.toList) + SourceFileReport(source, fullLineHit.toList) } } diff --git a/src/main/scala/org/scoverage/coveralls/CoverallPayloadWriter.scala b/src/main/scala/org/scoverage/coveralls/CoverallPayloadWriter.scala index afc1518..d20b941 100644 --- a/src/main/scala/org/scoverage/coveralls/CoverallPayloadWriter.scala +++ b/src/main/scala/org/scoverage/coveralls/CoverallPayloadWriter.scala @@ -95,8 +95,7 @@ class CoverallPayloadWriter( } def addSourceFile(report: SourceFileReport) = { - val repoRootDirStr = - repoRootDir.getCanonicalPath.replace(File.separator, "/") + "/" + val repoRootDirStr = repoRootDir.getCanonicalPath + "/" // create a name relative to the project root (rather than the module root) // this is needed so that coveralls can find the file in git. diff --git a/src/test/resources/generate.sh b/src/test/resources/generate.sh deleted file mode 100755 index ac1bf4a..0000000 --- a/src/test/resources/generate.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -resources=src/test/resources -for f in ${resources}/*.template; do cat ${f} | sed "s|{{PWD}}|${PWD}|" > ${resources}/$(basename ${f} .template); done diff --git a/src/test/resources/test_cobertura.xml.windows.template b/src/test/resources/test_cobertura.xml.windows.template new file mode 100644 index 0000000..e2f5947 --- /dev/null +++ b/src/test/resources/test_cobertura.xml.windows.template @@ -0,0 +1,43 @@ + + + + + --source + {{PWD}}\src\test\resources\projectA\arc\main\scala + {{PWD}}\src\test\resources\projectA\arc\main\scala-2.12 + {{PWD}}\src\test\resources\projectB\arc\main\scala + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/test_cobertura_corrupted.xml.windows.template b/src/test/resources/test_cobertura_corrupted.xml.windows.template new file mode 100644 index 0000000..7b19abc --- /dev/null +++ b/src/test/resources/test_cobertura_corrupted.xml.windows.template @@ -0,0 +1 @@ +corrupted file content diff --git a/src/test/resources/test_cobertura_dtd.xml.windows.template b/src/test/resources/test_cobertura_dtd.xml.windows.template new file mode 100644 index 0000000..72350ee --- /dev/null +++ b/src/test/resources/test_cobertura_dtd.xml.windows.template @@ -0,0 +1,43 @@ + + + + + --source + {{PWD}}\src\test\resources\projectA\src\main\scala + {{PWD}}\src\test\resources\projectA\src\main\scala-2.12 + {{PWD}}\src\test\resources\projectB\src\main\scala + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/resources/test_cobertura_multisource.xml.windows.template b/src/test/resources/test_cobertura_multisource.xml.windows.template new file mode 100644 index 0000000..2a0365c --- /dev/null +++ b/src/test/resources/test_cobertura_multisource.xml.windows.template @@ -0,0 +1,41 @@ + + + --source + {{PWD}}\src\test\resources\projectA\src\main\scala + {{PWD}}\src\test\resources\projectA\src\main\scala-2.12 + {{PWD}}\src\test\resources\projectB\src\main\scala + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/scala/org/scoverage/coveralls/CoverallPayloadWriterTest.scala b/src/test/scala/org/scoverage/coveralls/CoverallPayloadWriterTest.scala index 24798a5..254d5d5 100644 --- a/src/test/scala/org/scoverage/coveralls/CoverallPayloadWriterTest.scala +++ b/src/test/scala/org/scoverage/coveralls/CoverallPayloadWriterTest.scala @@ -153,8 +153,9 @@ class CoverallPayloadWriterTest ) payloadWriter.flush() + val name = List(".","src","test","resources","projectA","src","main","scala","bar","foo","TestSourceFile.scala").mkString(File.separator) writer.toString should equal( - """{"name":"./src/test/resources/projectA/src/main/scala/bar/foo/TestSourceFile.scala","source_digest":"B77361233B09D69968F8C62491A5085F","coverage":[1,null,2]}""" + s"""{"name":"$name","source_digest":"B77361233B09D69968F8C62491A5085F","coverage":[1,null,2]}""" ) }