Skip to content

Commit 24039a2

Browse files
committed
Added support for multiple source directories. Version changed from 1.0.4 to 1.0.5-SNAPSHOT.
1 parent adefc7f commit 24039a2

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

project/Scoverage.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import sbt._
44
object Scoverage extends Build {
55

66
val Org = "org.scoverage"
7-
val Version = "1.0.4"
7+
val Version = "1.0.5-SNAPSHOT"
88
val Scala = "2.11.4"
99
val MockitoVersion = "1.9.5"
1010
val ScalatestVersion = "2.2.2"

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import scoverage._
88
import scala.xml.Node
99

1010
/** @author Stephen Samuel */
11-
class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
11+
class ScoverageHtmlWriter(sourceDirectories: Seq[File], outputDir: File) {
12+
13+
def this (sourceDirectory: File, outputDir: File) {
14+
this(Seq(sourceDirectory), outputDir);
15+
}
1216

1317
def write(coverage: Coverage): Unit = {
1418
val indexFile = new File(outputDir.getAbsolutePath + "/index.html")
@@ -23,7 +27,18 @@ class ScoverageHtmlWriter(sourceDirectory: File, outputDir: File) {
2327
coverage.packages.foreach(writePackage)
2428
}
2529

26-
private def relativeSource(src: String): String = src.replace(sourceDirectory.getCanonicalPath + File.separator, "")
30+
private def isRelativeTo = (directory: File, file: File) => file.getCanonicalPath.startsWith(directory.getCanonicalPath)
31+
32+
private def relativeSource(src: String): String = {
33+
val absoluteSrcPath: String = new File(src).getCanonicalPath;
34+
val sourceRoot: Option[File] = sourceDirectories.find(
35+
sourceDirectory => isRelativeTo(sourceDirectory, new File(src))
36+
);
37+
sourceRoot match {
38+
case Some(dir: File) => return absoluteSrcPath.replace(dir.getCanonicalPath + File.separator, "");
39+
case _ => throw new RuntimeException(s"No source root found for '$src'");
40+
}
41+
}
2742

2843
private def writePackage(pkg: MeasuredPackage): Unit = {
2944
// package overview files are written out using a filename that respects the package name

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import _root_.scoverage._
77
import scala.xml.{Node, PrettyPrinter}
88

99
/** @author Stephen Samuel */
10-
class ScoverageXmlWriter(sourceDir: File, outputDir: File, debug: Boolean) {
10+
class ScoverageXmlWriter(sourceDirectories: Seq[File], outputDir: File, debug: Boolean) {
11+
12+
def this (sourceDir: File, outputDir: File, debug: Boolean) {
13+
this(Seq(sourceDir), outputDir, debug);
14+
}
1115

1216
def write(coverage: Coverage): Unit = {
1317
val file = IOUtils.reportFile(outputDir, debug)
@@ -72,9 +76,22 @@ class ScoverageXmlWriter(sourceDir: File, outputDir: File, debug: Boolean) {
7276
</method>
7377
}
7478

79+
private def isRelativeTo = (directory: File, file: File) => file.getCanonicalPath.startsWith(directory.getCanonicalPath)
80+
81+
private def relativeSource(src: String): String = {
82+
val absoluteSrcPath: String = new File(src).getCanonicalPath;
83+
val sourceRoot: Option[File] = sourceDirectories.find(
84+
sourceDirectory => isRelativeTo(sourceDirectory, new File(src))
85+
);
86+
sourceRoot match {
87+
case Some(dir: File) => return absoluteSrcPath.replace(dir.getCanonicalPath + File.separator, "");
88+
case _ => throw new RuntimeException(s"No source root found for '$src'");
89+
}
90+
}
91+
7592
private def klass(klass: MeasuredClass): Node = {
7693
<class name={klass.name}
77-
filename={klass.source.replace(sourceDir.getAbsolutePath, "")}
94+
filename={relativeSource(klass.source)/*klass.source.replace(sourceDir.getAbsolutePath, "")*/}
7895
statement-count={klass.statementCount.toString}
7996
statements-invoked={klass.invokedStatementCount.toString}
8097
statement-rate={klass.statementCoverageFormatted}

0 commit comments

Comments
 (0)