@@ -3,14 +3,17 @@ package codacy.dockerApi.traits
3
3
import java .io .File
4
4
import java .nio .file .Path
5
5
6
- import scala .util .{Success , Failure , Try }
7
-
8
6
import codacy .dockerApi .utils .CommandRunner
9
7
8
+ import scala .util .{Failure , Success , Try }
9
+
10
10
sealed trait Builder {
11
+
11
12
val command : List [String ]
12
13
val pathComponents : Seq [String ]
14
+
13
15
def supported (path : Path ): Boolean
16
+
14
17
def targetOfDirectory (path : File ): Option [String ]
15
18
16
19
private def buildWithCommand (command : List [String ], path : Path ): Try [Boolean ] = {
@@ -43,6 +46,7 @@ object MavenBuilder extends Builder {
43
46
}
44
47
45
48
object SBTBuilder extends Builder {
49
+
46
50
val command = List (" sbt" , " compile" )
47
51
val pathComponents = Seq (" src" , " main" , " scala" )
48
52
@@ -51,15 +55,16 @@ object SBTBuilder extends Builder {
51
55
}
52
56
53
57
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 {
56
60
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
+ }
61
65
case false =>
62
66
Option .empty
63
67
}
64
68
}
69
+
65
70
}
0 commit comments