Skip to content

Commit b37bf17

Browse files
authored
Drop akka dependency (#9)
Drop akka dependency
1 parent 3415f3e commit b37bf17

File tree

5 files changed

+68
-15
lines changed

5 files changed

+68
-15
lines changed

build.sbt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name := """codacy-engine-scala-seed"""
66

77
organization := "com.codacy"
88

9-
version := "2.7.0"
9+
version := "2.7.1"
1010

1111
scalaVersion := "2.11.8"
1212

@@ -19,7 +19,6 @@ resolvers += "Bintray Typesafe Repo" at "http://dl.bintray.com/typesafe/maven-re
1919
libraryDependencies ++= Seq(
2020
"com.typesafe.play" %% "play-json" % "2.4.8",
2121
"org.scalatest" %% "scalatest" % "2.2.4" % "test",
22-
"com.typesafe.akka" %% "akka-actor" % "2.3.14",
2322
"com.codacy" %% "codacy-plugins-api" % "0.1.2" withSources(),
2423
"com.github.pathikrit" %% "better-files" % "2.14.0" withSources()
2524
)

circle.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ machine:
22
java:
33
version: oraclejdk8
44

5+
dependencies:
6+
pre:
7+
- wget -q https://dl.bintray.com/sbt/debian/sbt-0.13.12.deb
8+
- sudo dpkg -i sbt-0.13.12.deb
9+
cache_directories:
10+
- "~/.ivy2"
11+
- "~/.sbt"
12+
513
test:
614
override:
715
- sbt clean coverage test
816
- sbt coverageReport
917
- sbt coverageAggregate
10-
- sbt codacyCoverage
18+
- sbt codacyCoverage

src/main/scala/codacy/dockerApi/DockerEngine.scala

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,27 @@ package codacy.dockerApi
22

33
import java.nio.file.Paths
44

5-
import akka.actor.ActorSystem
65
import codacy.docker.api.{Source, Result => NewResult}
76
import codacy.dockerApi.DockerEnvironment._
7+
import codacy.dockerApi.utils.Delayed
88
import play.api.libs.json.{Json, Writes}
99

10-
import scala.concurrent.ExecutionContext
1110
import scala.concurrent.duration._
1211
import scala.util.{Failure, Success, Try}
1312

14-
abstract class DockerEngine(Tool: codacy.docker.api.Tool) {
15-
16-
lazy val sys = ActorSystem("timeoutSystem")
13+
abstract class DockerEngine(Tool: codacy.docker.api.Tool) extends Delayed {
1714

1815
def initTimeout(duration: FiniteDuration) = {
19-
implicit val ct: ExecutionContext = sys.dispatcher
20-
sys.scheduler.scheduleOnce(duration) {
16+
delay(duration) {
2117
Runtime.getRuntime.halt(2)
2218
}
2319
}
2420

25-
lazy val timeout = Option(System.getProperty("timeout")).flatMap { case rawDuration =>
21+
lazy val timeout = Option(System.getProperty("timeout")).flatMap { rawDuration =>
2622
Try(Duration(rawDuration)).toOption.collect { case d: FiniteDuration => d }
2723
}.getOrElse(10.minutes)
2824

29-
lazy val isDebug = Option(System.getProperty("debug")).flatMap { case rawDebug =>
25+
lazy val isDebug = Option(System.getProperty("debug")).flatMap { rawDebug =>
3026
Try(rawDebug.toBoolean).toOption
3127
}.getOrElse(false)
3228

@@ -57,13 +53,13 @@ abstract class DockerEngine(Tool: codacy.docker.api.Tool) {
5753
files <- config.files
5854
} yield {
5955
//TODO: i see a problem with the .toString here, also convert it to better-files ops please!
60-
files.map { case file => file.copy(path = sourcePath.path.resolve(Paths.get(file.path)).toString) }
56+
files.map { file => file.copy(path = sourcePath.path.resolve(Paths.get(file.path)).toString) }
6157
}
6258

6359
log("tool started")
6460
// We need to catch Throwable here to avoid JVM crashes
6561
// Crashes can lead to docker not exiting properly
66-
val res = (try {
62+
val res = try {
6763
Tool.apply(
6864
source = Source.Directory(sourcePath.toString()),
6965
configuration = patternsOpt,
@@ -72,7 +68,7 @@ abstract class DockerEngine(Tool: codacy.docker.api.Tool) {
7268
} catch {
7369
case t: Throwable =>
7470
Failure(t)
75-
})
71+
}
7672

7773
res match {
7874
case Success(results) =>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package codacy.dockerApi.utils
2+
3+
import java.util.{Timer, TimerTask}
4+
5+
import scala.concurrent.{Future, Promise}
6+
import scala.concurrent.duration.Duration
7+
import scala.util.Try
8+
9+
trait Delayed {
10+
11+
def delay[T](delay: Duration)(block: => T): Future[T] = {
12+
val promise = Promise[T]()
13+
val t = new Timer()
14+
t.schedule(new TimerTask {
15+
override def run(): Unit = {
16+
promise.complete(Try(block))
17+
}
18+
}, delay.toMillis)
19+
promise.future
20+
}
21+
22+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package codacy.dockerApi.utils
2+
3+
import org.scalatest._
4+
5+
import scala.concurrent.duration._
6+
import scala.concurrent.{Await, TimeoutException}
7+
8+
class DelayedTest extends FlatSpec with Matchers with Delayed {
9+
10+
"DelayedTest" should "should throw exception" in {
11+
an[TimeoutException] should be thrownBy {
12+
val f = delay(1.seconds) {
13+
throw new TimeoutException("Execution timeout")
14+
}
15+
16+
Await.result(f, Duration.Inf)
17+
}
18+
}
19+
20+
it should "shouldn't throw exception" in {
21+
delay(2.seconds) {
22+
fail("That expression shouldn't have thrown a MyExceptionType exception")
23+
}
24+
}
25+
26+
}
27+
28+

0 commit comments

Comments
 (0)