Skip to content

Commit 5d6fa25

Browse files
Allow sbt-scoverage to work on windows
The -Xplugin option expects a classpath string with multiple paths separated by a semicolon or colon depending on this operating system. However, this currently always uses a colon, which doesn't work on windows. This means scalac cannot find the scoverage plugin jars and leads to errors about "bad options". This modifies the -Xplugin logic to use File.pathSeparator when building the Xplugin classpath, allowing it to work regardless of operating system. Also modifies excludedPackages when on windows to replace unix file separators with escaped windows file separators. Modifies tests to remove unnecessary escaping of unix separators. Closes #440
1 parent 1e69c10 commit 5d6fa25

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ on:
1111

1212
jobs:
1313
test:
14-
runs-on: ubuntu-latest
14+
runs-on: ${{ matrix.os }}
1515
strategy:
1616
matrix:
1717
java: [ '8', '17' ]
18+
os: [ 'ubuntu-latest', 'windows-latest' ]
1819

1920
steps:
2021
- name: checkout the repo

src/main/scala/scoverage/ScoverageSbtPlugin.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package scoverage
22

33
import sbt.Keys._
44
import sbt._
5+
import sbt.internal.util.Util.isWindows
56
import sbt.plugins.JvmPlugin
67
import scoverage.reporter.CoberturaXmlWriter
78
import scoverage.domain.Constants
@@ -147,7 +148,7 @@ object ScoverageSbtPlugin extends AutoPlugin {
147148

148149
Seq(
149150
Some(
150-
s"-Xplugin:${pluginPaths.mkString(":")}"
151+
s"-Xplugin:${pluginPaths.mkString(java.io.File.pathSeparator)}"
151152
),
152153
Some(
153154
s"-P:scoverage:dataDir:${coverageDataDir.value.getAbsolutePath}/scoverage-data"
@@ -160,6 +161,7 @@ object ScoverageSbtPlugin extends AutoPlugin {
160161
.map(v => s"-P:scoverage:excludedPackages:$v"),
161162
Option(coverageExcludedFiles.value.trim)
162163
.filter(_.nonEmpty)
164+
.map(v => if (isWindows) v.replace("/", "\\\\") else v) // replace unix file separators with escaped windows file separators
163165
.map(v => s"-P:scoverage:excludedFiles:$v"),
164166
Some("-P:scoverage:reportTestName"),
165167
// rangepos is broken in some releases of scala so option to turn it off

src/sbt-test/scoverage/coverage-excluded-files/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ scalaVersion := "2.13.6"
44

55
libraryDependencies += "org.scalameta" %% "munit" % "0.7.29" % Test
66

7-
coverageExcludedFiles := ".*\\/two\\/GoodCoverage"
7+
coverageExcludedFiles := ".*/two/GoodCoverage"
88

99
resolvers ++= {
1010
if (sys.props.get("plugin.version").exists(_.endsWith("-SNAPSHOT")))

src/sbt-test/scoverage/scala3-coverage-excluded-files/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ scalaVersion := "3.2.0-RC1"
44

55
libraryDependencies += "org.scalameta" %% "munit" % "0.7.29" % Test
66

7-
coverageExcludedFiles := ".*\\/two\\/GoodCoverage"
7+
coverageExcludedFiles := ".*/two/GoodCoverage"
88

99
resolvers ++= {
1010
if (sys.props.get("plugin.version").exists(_.endsWith("-SNAPSHOT")))

0 commit comments

Comments
 (0)