1
1
package codacy .dockerApi
2
2
3
+ import akka .actor .ActorSystem
3
4
import codacy .dockerApi .DockerEnvironment ._
4
5
import play .api .libs .json .{Json , Writes }
5
6
6
- import scala .util .{Failure , Success }
7
+ import scala .concurrent .ExecutionContext
8
+ import scala .concurrent .duration ._
9
+ import scala .util .{Failure , Success , Try }
7
10
8
11
abstract class DockerEngine (Tool : Tool ) {
9
12
13
+ lazy val sys = ActorSystem (" timeoutSystem" )
14
+
15
+ def initTimeout (duration : FiniteDuration ) = {
16
+ implicit val ct : ExecutionContext = sys.dispatcher
17
+ sys.scheduler.scheduleOnce(duration){
18
+ Runtime .getRuntime().halt(2 )
19
+ }
20
+ }
21
+
22
+ lazy val timeout = Option (System .getProperty(" timeout" )).flatMap{ case rawDuration =>
23
+ Try (Duration (rawDuration)).toOption.collect{ case d: FiniteDuration => d }
24
+ }.getOrElse(30 .minutes)
25
+
26
+ lazy val isDebug = Option (System .getProperty(" debug" )).flatMap{ case rawDebug =>
27
+ Try (rawDebug.toBoolean).toOption
28
+ }.getOrElse(false )
29
+
30
+ def log (message: String ): Unit = if (isDebug){
31
+ Console .err.print(s " [DockerEngine] $message" )
32
+ }
33
+
10
34
def main (args : Array [String ]): Unit = {
35
+ initTimeout(timeout)
36
+
11
37
spec.flatMap { implicit spec =>
12
38
config.flatMap { case maybeConfig =>
13
39
// search for our config
@@ -19,6 +45,7 @@ abstract class DockerEngine(Tool: Tool) {
19
45
sourcePath.resolve(path.value)
20
46
}))
21
47
48
+ log(" tool started" )
22
49
Tool (
23
50
path = sourcePath,
24
51
conf = maybePatterns,
@@ -27,6 +54,7 @@ abstract class DockerEngine(Tool: Tool) {
27
54
}
28
55
} match {
29
56
case Success (results) =>
57
+ log(" receiving results" )
30
58
results.foreach {
31
59
case issue : Issue =>
32
60
val relativeIssue = issue.copy(filename = SourcePath (relativize(issue.filename.value)))
@@ -35,7 +63,7 @@ abstract class DockerEngine(Tool: Tool) {
35
63
val relativeIssue = error.copy(filename = SourcePath (relativize(error.filename.value)))
36
64
logResult(relativeIssue)
37
65
}
38
-
66
+ log( " tool finished " )
39
67
case Failure (error) =>
40
68
error.printStackTrace(Console .err)
41
69
System .exit(1 )
0 commit comments