Skip to content

Commit

Permalink
Support extension extends base impl
Browse files Browse the repository at this point in the history
  • Loading branch information
aiyanbo committed May 25, 2020
1 parent ea1c8b1 commit d230e5e
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 13 deletions.
17 changes: 9 additions & 8 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ object Dependencies extends AutoPlugin {

object Versions {
val config = "1.4.0"
val grpcCore = "1.26.0"
val grpcStub = "1.26.0"
val grpcCore = "1.29.0"
val grpcStub = "1.29.0"
val guava = "23.0"
val guice = "4.2.2"
val protobufJava = "3.11.1"
val scala = "2.13.1"
val guice = "4.2.3"
val guiceMultibindings = "4.2.3"
val protobufJava = "3.12.1"
val scala = "2.13.2"
val scala212 = "2.12.10"
val scalaI18n = "1.0.7"
val scalaLogging = "3.9.2"
val scalatest = "3.1.0"
val scalikejdbc = "3.4.0"
val undertow = "2.0.29.Final"
val scalatest = "3.1.2"
val scalikejdbc = "3.4.2"
val undertow = "2.1.1.Final"
}

object Compiles {
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.3.8
sbt.version=1.3.10
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")

addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.7")

addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.12")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")

addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3")

addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")

addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")

addSbtPlugin("org.jmotor.sbt" % "sbt-dependency-updates" % "1.2.1")
addSbtPlugin("org.jmotor.sbt" % "sbt-dependency-updates" % "1.2.2")
9 changes: 7 additions & 2 deletions src/main/scala/org/jmotor/guice/AbstractModuleSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import com.typesafe.config.Config
import com.typesafe.scalalogging.LazyLogging
import org.jmotor.config.ConfigConversions._

import scala.jdk.CollectionConverters._
import scala.collection.mutable
import scala.jdk.CollectionConverters._

/**
* Component:
Expand Down Expand Up @@ -60,7 +60,12 @@ abstract class AbstractModuleSupport extends AbstractModule with LazyLogging {

def bindComponent(classInfo: ClassPath.ClassInfo): Unit = {
val clazz = classInfo.load()
val interfaces = clazz.getInterfaces
val clazzInterfaces = clazz.getInterfaces
val interfaces = if (clazzInterfaces.nonEmpty) {
clazzInterfaces
} else {
clazz.getSuperclass.getInterfaces
}
val interfaceOpt = interfaces.find { irfe
clazz.getSimpleName.contains(irfe.getSimpleName) && clazz.getPackage.getName.contains(irfe.getPackage.getName)
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/scala/org/jmotor/guice/ModuleSupportSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.google.inject.TypeLiteral
import com.typesafe.config.ConfigFactory
import org.jmotor.guice.service.Conf
import org.jmotor.guice.service.ConfigService
import org.jmotor.guice.service.FooService
import org.jmotor.guice.service.MultiConfigService
import org.jmotor.guice.service.MultiPingService
import org.jmotor.guice.service.PingService
Expand Down Expand Up @@ -65,4 +66,14 @@ class ModuleSupportSpec extends AnyFunSuite {
assert(impls.exists(_.isInstanceOf[LongConfigService]))
}

test("Test extends extension") {
val config = ConfigFactory.parseString("extension.enabled = true")
val injector = Guice.createInjector(new AbstractModuleSupport {
override def configure(): Unit = bindExtendableComponents("org.jmotor.guice.service.impl", config)
})
val service = injector.getInstance(classOf[FooService])
assert("run" == service.run())
assert("invoke" == service.call())
}

}
14 changes: 14 additions & 0 deletions src/test/scala/org/jmotor/guice/service/FooService.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.jmotor.guice.service

/**
*
* @author AI
* 2020/5/25
*/
trait FooService {

def run(): String

def call(): String

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.jmotor.guice.service.extension

import org.jmotor.guice.service.FooService

/**
*
* @author AI
* 2020/5/25
*/
class FooServiceImpl extends org.jmotor.guice.service.impl.FooServiceImpl with FooService {

override def call(): String = "invoke"

}
16 changes: 16 additions & 0 deletions src/test/scala/org/jmotor/guice/service/impl/FooServiceImpl.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.jmotor.guice.service.impl

import org.jmotor.guice.service.FooService

/**
*
* @author AI
* 2020/5/25
*/
class FooServiceImpl extends FooService {

override def run(): String = "run"

override def call(): String = "call"

}

0 comments on commit d230e5e

Please sign in to comment.