-
Notifications
You must be signed in to change notification settings - Fork 126
Support multiple source roots in report generators (issue #104) #109
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
Changes from 5 commits
87d5bb6
d8bbb35
f3a6489
82c8118
88c35e2
9af6fce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,15 @@ import _root_.scoverage._ | |
import scala.xml.{Node, PrettyPrinter} | ||
|
||
/** @author Stephen Samuel */ | ||
class ScoverageXmlWriter(sourceDir: File, outputDir: File, debug: Boolean) { | ||
class ScoverageXmlWriter(sourceDirectories: Seq[File], outputDir: File, debug: Boolean) { | ||
|
||
def this (sourceDir: File, outputDir: File, debug: Boolean) { | ||
this(Seq(sourceDir), outputDir, debug); | ||
} | ||
|
||
// Source paths in canonical form WITH trailing file separator | ||
val formattedSourcePaths: Seq[String] = sourceDirectories filter ( _.isDirectory ) map ( _.getCanonicalPath + File.separator ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is duplicated in 3 different writers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to make as small changes as possible required. This can be refactored of course. |
||
|
||
def write(coverage: Coverage): Unit = { | ||
val file = IOUtils.reportFile(outputDir, debug) | ||
IOUtils.writeToFile(file, new PrettyPrinter(120, 4).format(xml(coverage))) | ||
|
@@ -74,7 +81,7 @@ class ScoverageXmlWriter(sourceDir: File, outputDir: File, debug: Boolean) { | |
|
||
private def klass(klass: MeasuredClass): Node = { | ||
<class name={klass.name} | ||
filename={klass.source.replace(sourceDir.getAbsolutePath, "")} | ||
filename={relativeSource(klass.source)} | ||
statement-count={klass.statementCount.toString} | ||
statements-invoked={klass.invokedStatementCount.toString} | ||
statement-rate={klass.statementCoverageFormatted} | ||
|
@@ -96,5 +103,7 @@ class ScoverageXmlWriter(sourceDir: File, outputDir: File, debug: Boolean) { | |
</package> | ||
} | ||
|
||
private def relativeSource(src: String): String = IOUtils.relativeSource(src, formattedSourcePaths) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or use something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be refactored. |
||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO
!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't want to decide what exception will be the best :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
IllegalArgumentException
? Method contract statessrc
must have at least one source root in givensourcePaths
.