-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from gslowikowski/reporting-base-class
#109 introduced...
- Loading branch information
Showing
5 changed files
with
34 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
scalac-scoverage-plugin/src/main/scala/scoverage/report/BaseReportWriter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package scoverage.report | ||
|
||
import java.io.File | ||
|
||
class BaseReportWriter(sourceDirectories: Seq[File], outputDir: File) { | ||
|
||
// Source paths in canonical form WITH trailing file separator | ||
private val formattedSourcePaths: Seq[String] = sourceDirectories filter ( _.isDirectory ) map ( _.getCanonicalPath + File.separator ) | ||
|
||
/** | ||
* Converts absolute path to relative one if any of the source directories is it's parent. | ||
* If there is no parent directory, the path is returned unchanged (absolute). | ||
* | ||
* @param src absolute file path in canonical form | ||
*/ | ||
def relativeSource(src: String): String = relativeSource(src, formattedSourcePaths) | ||
|
||
private def relativeSource(src: String, sourcePaths: Seq[String]): String = { | ||
val sourceRoot: Option[String] = sourcePaths.find( | ||
sourcePath => src.startsWith(sourcePath) | ||
) | ||
sourceRoot match { | ||
case Some(path: String) => src.replace(path, "") | ||
case _ => | ||
val fmtSourcePaths: String = sourcePaths.mkString("'", "', '", "'") | ||
throw new RuntimeException(s"No source root found for '$src' (source roots: $fmtSourcePaths)"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters