Skip to content

Commit 3f81603

Browse files
committed
Fix target missing scala directory path
1 parent 46a4414 commit 3f81603

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/main/scala/codacy/dockerApi/traits/Builder.scala

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ package codacy.dockerApi.traits
33
import java.io.File
44
import java.nio.file.Path
55

6-
import scala.util.{Success, Failure, Try}
7-
86
import codacy.dockerApi.utils.CommandRunner
97

8+
import scala.util.{Failure, Success, Try}
9+
1010
sealed trait Builder {
11+
1112
val command: List[String]
1213
val pathComponents: Seq[String]
14+
1315
def supported(path: Path): Boolean
16+
1417
def targetOfDirectory(path: File): Option[String]
1518

1619
private def buildWithCommand(command: List[String], path: Path): Try[Boolean] = {
@@ -43,6 +46,7 @@ object MavenBuilder extends Builder {
4346
}
4447

4548
object SBTBuilder extends Builder {
49+
4650
val command = List("sbt", "compile")
4751
val pathComponents = Seq("src", "main", "scala")
4852

@@ -51,15 +55,16 @@ object SBTBuilder extends Builder {
5155
}
5256

5357
def targetOfDirectory(path: File): Option[String] = {
54-
val target = new File(Seq(path.getAbsolutePath, "target").mkString(File.separator))
55-
target.exists match {
58+
val target = new File(path.getAbsolutePath, "target")
59+
Option(target.exists).flatMap {
5660
case true =>
57-
val potentialScalaDir = target.list.filter { case filepath => filepath.startsWith("scala-")}
58-
// TODO: Cleaner way to do this?
59-
val scalaDirectory = potentialScalaDir.headOption.fold("") { case target => target}
60-
Some(Seq(target.getAbsolutePath, scalaDirectory, "classes").mkString(File.separator))
61+
val potentialScalaDir = target.list.find { case filepath => filepath.startsWith("scala-") }
62+
potentialScalaDir.map { case scalaDirectory =>
63+
target.toPath.resolve(scalaDirectory).resolve("classes").toString
64+
}
6165
case false =>
6266
Option.empty
6367
}
6468
}
69+
6570
}

0 commit comments

Comments
 (0)