Skip to content

Various fixes for config and encoding. #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions scalac-scoverage-plugin/src/main/scala/scoverage/IOUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.io._

import scala.collection.Set
import scala.collection.mutable
import scala.io.Codec
import scala.io.Source

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

def writeToFile(file: File, str: String)(implicit encoding: String) = {
def writeToFile(
file: File,
str: String,
encoding: String = Codec.UTF8.name
) = {
val writer = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(file),
Expand Down Expand Up @@ -89,8 +94,9 @@ object IOUtils {

// loads all the invoked statement ids from the given files
def invoked(
files: Seq[File]
)(implicit encoding: String): Set[(Int, String)] = {
files: Seq[File],
encoding: String = Codec.UTF8.name
): Set[(Int, String)] = {
val acc = mutable.Set[(Int, String)]()
files.foreach { file =>
val reader =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,13 @@ object ScoverageOptions {
options = options.copy(excludedSymbols = parseExclusionOption(symbols))
case DataDir(dir) =>
options = options.copy(dataDir = dir)
case SourceRoot(root) =>
options.copy(sourceRoot = root)
case SourceRoot(root) => options = options.copy(sourceRoot = root)
// NOTE that both the extra phases are actually parsed out early on, so
// we just ignore them here
case ExtraAfterPhase(afterPhase) => ()
case ExtraBeforePhase(beforePhase) => ()
case "reportTestName" =>
options.copy(reportTestName = true)
options = options.copy(reportTestName = true)
case opt => errFn("Unknown option: " + opt)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ package scoverage.report

import java.io.File

import scala.io.Codec

class BaseReportWriter(
sourceDirectories: Seq[File],
outputDir: File,
sourceEncoding: Option[String]
) {

implicit val encoding = sourceEncoding.fold(Codec.UTF8.name)(identity)

// Source paths in canonical form WITH trailing file separator
private val formattedSourcePaths: Seq[String] =
sourceDirectories filter (_.isDirectory) map (_.getCanonicalPath + File.separator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ package scoverage.report

import java.io.File

import scala.io.Codec

import scoverage.Coverage
import scoverage.IOUtils
import scoverage.Serializer

object CoverageAggregator {

implicit val encoding: String = Codec.UTF8.name

// to be used by gradle-scoverage plugin
def aggregate(dataDirs: Array[File], sourceRoot: File): Option[Coverage] =
aggregate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ import java.io.File
import java.io.FileWriter
import java.util.UUID

import scala.io.Codec

import munit.FunSuite

/** @author Stephen Samuel */
class IOUtilsTest extends FunSuite {

implicit val encoding: String = Codec.UTF8.name

test("should parse measurement files") {
val file = File.createTempFile("scoveragemeasurementtest", "txt")
val writer = new FileWriter(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scoverage

import java.io.File

import scala.io.Codec
import scala.tools.nsc.Global
import scala.tools.nsc.plugins.PluginComponent
import scala.tools.nsc.transform.Transform
Expand All @@ -25,7 +24,7 @@ class LocationCompiler(

def writeCodeSnippetToTempFile(code: String): File = {
val file = File.createTempFile("code_snippet", ".scala")
IOUtils.writeToFile(file, code)(Codec.UTF8.name)
IOUtils.writeToFile(file, code)
file.deleteOnExit()
file
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import java.io.FileNotFoundException
import java.net.URL

import scala.collection.mutable.ListBuffer
import scala.io.Codec
import scala.tools.nsc.Global
import scala.tools.nsc.Settings
import scala.tools.nsc.plugins.PluginComponent
Expand Down Expand Up @@ -141,7 +140,7 @@ class ScoverageCompiler(

def writeCodeSnippetToTempFile(code: String): File = {
val file = File.createTempFile("scoverage_snippet", ".scala")
IOUtils.writeToFile(file, code)(Codec.UTF8.name)
IOUtils.writeToFile(file, code)
file.deleteOnExit()
file
}
Expand Down