Skip to content

Commit 4fe478c

Browse files
authored
Various fixes for config and encoding. (#400)
After playing around with this a bit in the sbt plugin I realized I made some mistakes and also made things in a way that were a bit of a pain to actually use from the plugins. So I got rid of the implicits in favor of explicits, and fixed the config parsing
1 parent 212b395 commit 4fe478c

File tree

7 files changed

+13
-22
lines changed

7 files changed

+13
-22
lines changed

scalac-scoverage-plugin/src/main/scala/scoverage/IOUtils.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.io._
44

55
import scala.collection.Set
66
import scala.collection.mutable
7+
import scala.io.Codec
78
import scala.io.Source
89

910
/** @author Stephen Samuel */
@@ -36,7 +37,11 @@ object IOUtils {
3637
findMeasurementFiles(dataDir).foreach(_.delete)
3738
def clean(dataDir: String): Unit = clean(new File(dataDir))
3839

39-
def writeToFile(file: File, str: String)(implicit encoding: String) = {
40+
def writeToFile(
41+
file: File,
42+
str: String,
43+
encoding: String = Codec.UTF8.name
44+
) = {
4045
val writer = new BufferedWriter(
4146
new OutputStreamWriter(
4247
new FileOutputStream(file),
@@ -89,8 +94,9 @@ object IOUtils {
8994

9095
// loads all the invoked statement ids from the given files
9196
def invoked(
92-
files: Seq[File]
93-
)(implicit encoding: String): Set[(Int, String)] = {
97+
files: Seq[File],
98+
encoding: String = Codec.UTF8.name
99+
): Set[(Int, String)] = {
94100
val acc = mutable.Set[(Int, String)]()
95101
files.foreach { file =>
96102
val reader =

scalac-scoverage-plugin/src/main/scala/scoverage/ScoverageOptions.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,13 @@ object ScoverageOptions {
9999
options = options.copy(excludedSymbols = parseExclusionOption(symbols))
100100
case DataDir(dir) =>
101101
options = options.copy(dataDir = dir)
102-
case SourceRoot(root) =>
103-
options.copy(sourceRoot = root)
102+
case SourceRoot(root) => options = options.copy(sourceRoot = root)
104103
// NOTE that both the extra phases are actually parsed out early on, so
105104
// we just ignore them here
106105
case ExtraAfterPhase(afterPhase) => ()
107106
case ExtraBeforePhase(beforePhase) => ()
108107
case "reportTestName" =>
109-
options.copy(reportTestName = true)
108+
options = options.copy(reportTestName = true)
110109
case opt => errFn("Unknown option: " + opt)
111110
}
112111

scalac-scoverage-plugin/src/main/scala/scoverage/report/BaseReportWriter.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ package scoverage.report
22

33
import java.io.File
44

5-
import scala.io.Codec
6-
75
class BaseReportWriter(
86
sourceDirectories: Seq[File],
97
outputDir: File,
108
sourceEncoding: Option[String]
119
) {
1210

13-
implicit val encoding = sourceEncoding.fold(Codec.UTF8.name)(identity)
14-
1511
// Source paths in canonical form WITH trailing file separator
1612
private val formattedSourcePaths: Seq[String] =
1713
sourceDirectories filter (_.isDirectory) map (_.getCanonicalPath + File.separator)

scalac-scoverage-plugin/src/main/scala/scoverage/report/CoverageAggregator.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ package scoverage.report
22

33
import java.io.File
44

5-
import scala.io.Codec
6-
75
import scoverage.Coverage
86
import scoverage.IOUtils
97
import scoverage.Serializer
108

119
object CoverageAggregator {
1210

13-
implicit val encoding: String = Codec.UTF8.name
14-
1511
// to be used by gradle-scoverage plugin
1612
def aggregate(dataDirs: Array[File], sourceRoot: File): Option[Coverage] =
1713
aggregate(

scalac-scoverage-plugin/src/test/scala/scoverage/IOUtilsTest.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ import java.io.File
44
import java.io.FileWriter
55
import java.util.UUID
66

7-
import scala.io.Codec
8-
97
import munit.FunSuite
108

119
/** @author Stephen Samuel */
1210
class IOUtilsTest extends FunSuite {
1311

14-
implicit val encoding: String = Codec.UTF8.name
15-
1612
test("should parse measurement files") {
1713
val file = File.createTempFile("scoveragemeasurementtest", "txt")
1814
val writer = new FileWriter(file)

scalac-scoverage-plugin/src/test/scala/scoverage/LocationCompiler.scala

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

33
import java.io.File
44

5-
import scala.io.Codec
65
import scala.tools.nsc.Global
76
import scala.tools.nsc.plugins.PluginComponent
87
import scala.tools.nsc.transform.Transform
@@ -25,7 +24,7 @@ class LocationCompiler(
2524

2625
def writeCodeSnippetToTempFile(code: String): File = {
2726
val file = File.createTempFile("code_snippet", ".scala")
28-
IOUtils.writeToFile(file, code)(Codec.UTF8.name)
27+
IOUtils.writeToFile(file, code)
2928
file.deleteOnExit()
3029
file
3130
}

scalac-scoverage-plugin/src/test/scala/scoverage/ScoverageCompiler.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import java.io.FileNotFoundException
55
import java.net.URL
66

77
import scala.collection.mutable.ListBuffer
8-
import scala.io.Codec
98
import scala.tools.nsc.Global
109
import scala.tools.nsc.Settings
1110
import scala.tools.nsc.plugins.PluginComponent
@@ -141,7 +140,7 @@ class ScoverageCompiler(
141140

142141
def writeCodeSnippetToTempFile(code: String): File = {
143142
val file = File.createTempFile("scoverage_snippet", ".scala")
144-
IOUtils.writeToFile(file, code)(Codec.UTF8.name)
143+
IOUtils.writeToFile(file, code)
145144
file.deleteOnExit()
146145
file
147146
}

0 commit comments

Comments
 (0)