From b859f5f642ac5a06c7b07956c4ffc96a37ac1b2e Mon Sep 17 00:00:00 2001 From: Daniel Sobral Date: Thu, 9 Feb 2017 01:23:10 -0700 Subject: [PATCH] Improve error message --- .../BruteForceSequenceMatcher.scala | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/plugin/src/main/scala/com/buransky/plugins/scoverage/pathcleaner/BruteForceSequenceMatcher.scala b/plugin/src/main/scala/com/buransky/plugins/scoverage/pathcleaner/BruteForceSequenceMatcher.scala index 5acd4f7..db291c0 100644 --- a/plugin/src/main/scala/com/buransky/plugins/scoverage/pathcleaner/BruteForceSequenceMatcher.scala +++ b/plugin/src/main/scala/com/buransky/plugins/scoverage/pathcleaner/BruteForceSequenceMatcher.scala @@ -37,29 +37,29 @@ object BruteForceSequenceMatcher { /** * Helper that allows to convert a report path into a source folder relative path by testing it against * the tree of source files. - * + * * Assumes that all report paths of a given report have a common root. Dependent of the scoverage * report this root is either something outside the actual project (absolute path), the base dir of the project * (report path relative to base dir) or some sub folder of the project. - * + * * By reverse mapping a report path against the tree of all file children of the source folder the correct filesystem file - * can be found and the report path can be converted into a source dir relative path. * - * + * can be found and the report path can be converted into a source dir relative path. * + * * @author Michael Zinsmaier */ class BruteForceSequenceMatcher(baseDir: File, sourcePath: String) extends PathSanitizer { private val sourceDir = initSourceDir() - require(sourceDir.isAbsolute) - require(sourceDir.isDirectory) + require(sourceDir.isAbsolute, s"$sourceDir is not absolute") + require(sourceDir.isDirectory, s"$sourceDir is not a directory") private val log = Loggers.get(classOf[BruteForceSequenceMatcher]) - private val sourcePathLength = PathUtil.splitPath(sourceDir.getAbsolutePath).size + private val sourcePathLength = PathUtil.splitPath(sourceDir.getAbsolutePath).size private val filesMap = initFilesMap() - - + + def getSourceRelativePath(reportPath: PathSeq): Option[PathSeq] = { - // match with file system map of files + // match with file system map of files val relPathOption = for { absPathCandidates <- filesMap.get(reportPath.last) path <- absPathCandidates.find(absPath => absPath.endsWith(reportPath)) @@ -67,14 +67,14 @@ class BruteForceSequenceMatcher(baseDir: File, sourcePath: String) extends PathS relPathOption } - + // mock able helpers that allow us to remove the dependency to the real file system during tests - + private[pathcleaner] def initSourceDir(): File = { val sourceDir = new File(baseDir, sourcePath) sourceDir } - + private[pathcleaner] def initFilesMap(): Map[String, Seq[PathSeq]] = { val srcFiles = FileUtils.iterateFiles(sourceDir, extensions, true) val paths = srcFiles.map(file => PathUtil.splitPath(file.getAbsolutePath)).toSeq @@ -83,4 +83,4 @@ class BruteForceSequenceMatcher(baseDir: File, sourcePath: String) extends PathS paths.groupBy(path => path.last) } -} \ No newline at end of file +}