Skip to content

Commit

Permalink
Allow sbt-scoverage to work on windows
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stevedlawrence committed Oct 18, 2022
1 parent 1e69c10 commit 5d6fa25
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ on:

jobs:
test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
java: [ '8', '17' ]
os: [ 'ubuntu-latest', 'windows-latest' ]

steps:
- name: checkout the repo
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/scoverage/ScoverageSbtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scoverage

import sbt.Keys._
import sbt._
import sbt.internal.util.Util.isWindows
import sbt.plugins.JvmPlugin
import scoverage.reporter.CoberturaXmlWriter
import scoverage.domain.Constants
Expand Down Expand Up @@ -147,7 +148,7 @@ object ScoverageSbtPlugin extends AutoPlugin {

Seq(
Some(
s"-Xplugin:${pluginPaths.mkString(":")}"
s"-Xplugin:${pluginPaths.mkString(java.io.File.pathSeparator)}"
),
Some(
s"-P:scoverage:dataDir:${coverageDataDir.value.getAbsolutePath}/scoverage-data"
Expand All @@ -160,6 +161,7 @@ object ScoverageSbtPlugin extends AutoPlugin {
.map(v => s"-P:scoverage:excludedPackages:$v"),
Option(coverageExcludedFiles.value.trim)
.filter(_.nonEmpty)
.map(v => if (isWindows) v.replace("/", "\\\\") else v) // replace unix file separators with escaped windows file separators
.map(v => s"-P:scoverage:excludedFiles:$v"),
Some("-P:scoverage:reportTestName"),
// rangepos is broken in some releases of scala so option to turn it off
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/scoverage/coverage-excluded-files/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ scalaVersion := "2.13.6"

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

coverageExcludedFiles := ".*\\/two\\/GoodCoverage"
coverageExcludedFiles := ".*/two/GoodCoverage"

resolvers ++= {
if (sys.props.get("plugin.version").exists(_.endsWith("-SNAPSHOT")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ scalaVersion := "3.2.0-RC1"

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

coverageExcludedFiles := ".*\\/two\\/GoodCoverage"
coverageExcludedFiles := ".*/two/GoodCoverage"

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

0 comments on commit 5d6fa25

Please sign in to comment.