From 76c5cd2135cf78e503f40cf9192d0302cd4cec90 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Sat, 24 Jun 2017 19:00:29 +0300 Subject: Filter common childs in dirs --- stage2/plugins/ExportBuildInformation.scala | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/stage2/plugins/ExportBuildInformation.scala b/stage2/plugins/ExportBuildInformation.scala index 6a22363..be61609 100644 --- a/stage2/plugins/ExportBuildInformation.scala +++ b/stage2/plugins/ExportBuildInformation.scala @@ -2,6 +2,7 @@ package cbt import cbt._ import java.io._ +import java.nio.file._ import scala.xml._ trait ExportBuildInformation { self: BaseBuild => @@ -100,10 +101,8 @@ object BuildInformation { val s = build.sources .filter(_.exists) .map(handleSource) - .filter(_.getName != "target") //Dirty hack for cbt's sources - .distinct if (s.nonEmpty) - s + commonParents(s) else Seq(build.projectDirectory) } @@ -122,6 +121,21 @@ object BuildInformation { ) } + private def commonParents(paths: Seq[File]): Seq[File] = { //Too slow O(n^2) + val buffer = scala.collection.mutable.ListBuffer.empty[Path] + val sorted = paths + .map(_.toPath.toAbsolutePath) + .sortWith(_.getNameCount < _.getNameCount) + for (x <- sorted) { + if (!buffer.exists(x.startsWith)) { + buffer += x + } + } + buffer + .toList + .map(_.toFile) + } + private def collectLazyBuilds(dependency: Dependency): Option[BaseBuild] = dependency match { case l: LazyDependency => -- cgit v1.2.3