Skip to content

Commit

Permalink
Revenj.Scala v0.7.1
Browse files Browse the repository at this point in the history
Use mirror on typeOf[T] to avoid some Scala bugs with nested type tag resolutions.
  • Loading branch information
zapov committed May 11, 2018
1 parent 0d085b8 commit 3f236e9
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jdk:
- oraclejdk8

scala:
- 2.11.11
- 2.12.2
- 2.11.12
- 2.12.6

before_script: cd scala

Expand Down
6 changes: 3 additions & 3 deletions scala/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Revenj.Scala
============

[![Build Status](https://travis-ci.org/ngs-doo/revenj.svg?branch=travis)](https://travis-ci.org/ngs-doo/revenj)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.revenj/revenj-core_2.11/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.revenj/revenj-core_2.11)
[![Scaladoc](https://javadoc-badge.appspot.com/net.revenj/revenj-core_2.11.svg?label=scaladoc)](http://javadoc-badge.appspot.com/net.revenj/revenj-core_2.11)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.revenj/revenj-core_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.revenj/revenj-core_2.12)
[![Scaladoc](https://javadoc-badge.appspot.com/net.revenj/revenj-core_2.12.svg?label=scaladoc)](http://javadoc-badge.appspot.com/net.revenj/revenj-core_2.12)
[![License](https://img.shields.io/badge/license-BSD%203--Clause-brightgreen.svg)](https://opensource.org/licenses/BSD-3-Clause)

**revenj.scala** is available on OSSRH / Maven Central:

```scala
libraryDependencies += "net.revenj" %% "revenj-core" % "0.6.3"
libraryDependencies += "net.revenj" %% "revenj-core" % "0.7.1"
```
8 changes: 4 additions & 4 deletions scala/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ lazy val core = (project in file("revenj-core")
settings (commonSettings ++ publishSettings)
enablePlugins(SbtDslPlatformPlugin)
settings(
version := "0.7.0",
version := "0.7.1",
libraryDependencies ++= Seq(
"org.postgresql" % "postgresql" % "42.1.4",
"joda-time" % "joda-time" % "2.9.9", // TODO: will be removed
"org.joda" % "joda-convert" % "1.9.2", // TODO: will be removed
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"io.monix" %% "monix-reactive" % "2.3.2",
"org.scala-lang.modules" %% "scala-xml" % "1.0.6",
"com.dslplatform" %% "dsl-json-scala" % "1.7.3",
"com.dslplatform" %% "dsl-json-scala" % "1.7.4",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.9.4",
"com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.9.4",
"com.fasterxml.jackson.datatype" % "jackson-datatype-jdk8" % "2.9.4",
Expand All @@ -26,7 +26,7 @@ lazy val core = (project in file("revenj-core")
lazy val akka = (project in file("revenj-akka")
settings (commonSettings ++ publishSettings)
settings(
version := "0.7.0",
version := "0.7.1",
libraryDependencies ++= Seq(
"com.typesafe" % "config" % "1.3.2",
"com.typesafe.akka" %% "akka-http-core" % "10.0.13"
Expand Down Expand Up @@ -91,7 +91,7 @@ lazy val commonSettings = Defaults.coreDefaultSettings ++ Seq(
name := baseDirectory.value.getName,

scalaVersion := crossScalaVersions.value.head,
crossScalaVersions := Seq("2.11.12", "2.12.5"),
crossScalaVersions := Seq("2.11.12", "2.12.6"),
scalacOptions ++= Seq(
"-deprecation",
"-encoding", "UTF-8",
Expand Down
2 changes: 1 addition & 1 deletion scala/project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scalaVersion := "2.12.5"
scalaVersion := "2.12.6"

scalacOptions ++= Seq(
"-deprecation",
Expand Down
2 changes: 1 addition & 1 deletion scala/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
logLevel := Level.Warn

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1")
addSbtPlugin("com.dslplatform" % "sbt-dsl-platform" % "0.7.2")
addSbtPlugin("com.dslplatform" % "sbt-dsl-platform" % "0.7.3")
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ private[revenj] class RevenjSerialization(jackson: JacksonSerialization, loader:
}

override def deserialize[T: TypeTag](content: Array[Byte], length: Int, contentType: String): Try[T] = {
Utils.findType(typeOf[T], mirror) match {
Utils.findType(mirror.typeOf[T], mirror) match {
case Some(tpe) => deserialize(tpe, content, length, contentType).map(_.asInstanceOf[T])
case _ => Failure(new IllegalArgumentException("Unable to find Java type for: " + typeOf[T]))
case _ => Failure(new IllegalArgumentException(s"Unable to find Java type for: ${mirror.typeOf[T]}"))
}
}

override def deserialize[T: TypeTag](stream: InputStream, contentType: String): Try[T] = {
Utils.findType(typeOf[T], mirror) match {
Utils.findType(mirror.typeOf[T], mirror) match {
case Some(tpe) => deserialize(tpe, stream, contentType).map(_.asInstanceOf[T])
case _ => Failure(new IllegalArgumentException("Unable to find Java type for: " + typeOf[T]))
case _ => Failure(new IllegalArgumentException(s"Unable to find Java type for: ${mirror.typeOf[T]}"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ private[revenj] class LocatorDataContext(
}

private def findManifest[T: TypeTag]: Class[_] = {
typeOf[T] match {
mirror.typeOf[T] match {
case TypeRef(_, sym, _) => mirror.runtimeClass(sym.asClass)
case _ => throw new ReflectiveOperationException("Unable to find class type for " + typeOf[T])
case _ => throw new ReflectiveOperationException(s"Unable to find class type for ${mirror.typeOf[T]}")
}
}

Expand Down
23 changes: 13 additions & 10 deletions scala/revenj-core/src/main/scala/net/revenj/Revenj.scala
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,14 @@ If you wish to use custom jdbc driver provide custom data source instead of usin
}

def registerEvents[T <: DomainEvent : TypeTag](container: Container, plugins: PluginLoader, loader: ClassLoader): Unit = {
val javaClass = Utils.findType(typeOf[T], runtimeMirror(loader)) match {
val mirror = runtimeMirror(loader)
val javaClass = Utils.findType(mirror.typeOf[T], mirror) match {
case Some(p) =>
p match {
case cl: Class[_] => cl
case _ => throw new IllegalArgumentException(s"Only non-generic types supported. Found: ${typeOf[T]}")
case _ => throw new IllegalArgumentException(s"Only non-generic types supported. Found: ${mirror.typeOf[T]}")
}
case _ => throw new IllegalArgumentException(s"Unable to detect type: ${typeOf[T]}")
case _ => throw new IllegalArgumentException(s"Unable to detect type: ${mirror.typeOf[T]}")
}
def processHandlers[X: TypeTag](gt: ParameterizedType, eventHandlers: Seq[Class[DomainEventHandler[X]]]): Unit = {
eventHandlers foreach { h =>
Expand Down Expand Up @@ -220,21 +221,22 @@ If you wish to use custom jdbc driver provide custom data source instead of usin
}

def registerReports[R : TypeTag, T <: Report[R] : TypeTag](container: Container, plugins: PluginLoader, loader: ClassLoader): Unit = {
val resultClass = Utils.findType(typeOf[R], runtimeMirror(loader)) match {
val mirror = runtimeMirror(loader)
val resultClass = Utils.findType(mirror.typeOf[R], mirror) match {
case Some(p) =>
p match {
case cl: Class[_] => cl
case _ => throw new IllegalArgumentException(s"Only non-generic types supported. Found: ${typeOf[R]}")
}
case _ => throw new IllegalArgumentException(s"Unable to detect type: ${typeOf[R]}")
}
val reportClass = Utils.findType(typeOf[T], runtimeMirror(loader)) match {
val reportClass = Utils.findType(mirror.typeOf[T], mirror) match {
case Some(p) =>
p match {
case cl: Class[_] => cl
case _ => throw new IllegalArgumentException(s"Only non-generic types supported. Found: ${typeOf[T]}")
case _ => throw new IllegalArgumentException(s"Only non-generic types supported. Found: ${mirror.typeOf[T]}")
}
case _ => throw new IllegalArgumentException(s"Unable to detect type: ${typeOf[T]}")
case _ => throw new IllegalArgumentException(s"Unable to detect type: ${mirror.typeOf[T]}")
}
val gt = Utils.makeGenericType(classOf[ReportAspect[_, _]], resultClass, reportClass)
val aspects = plugins.find[ReportAspect[R, T]]
Expand All @@ -245,13 +247,14 @@ If you wish to use custom jdbc driver provide custom data source instead of usin
}

def registerAggregates[T <: AggregateRoot : TypeTag](container: Container, plugins: PluginLoader, loader: ClassLoader): Unit = {
val javaClass = Utils.findType(typeOf[T], runtimeMirror(loader)) match {
val mirror = runtimeMirror(loader)
val javaClass = Utils.findType(mirror.typeOf[T], mirror) match {
case Some(p) =>
p match {
case cl: Class[_] => cl
case _ => throw new IllegalArgumentException(s"Only non-generic types supported. Found: ${typeOf[T]}")
case _ => throw new IllegalArgumentException(s"Only non-generic types supported. Found: ${mirror.typeOf[T]}")
}
case _ => throw new IllegalArgumentException(s"Unable to detect type: ${typeOf[T]}")
case _ => throw new IllegalArgumentException(s"Unable to detect type: ${mirror.typeOf[T]}")
}
val gt = Utils.makeGenericType(classOf[PersistableRepositoryAspect[_]], javaClass)
val aspects = plugins.find[PersistableRepositoryAspect[T]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private[revenj] class SimpleContainer private(private val parent: Option[SimpleC
}

override def tryResolve[T: TypeTag]: Try[T] = {
Utils.findType(typeOf[T], mirror) match {
Utils.findType(mirror.typeOf[T], mirror) match {
case Some(tpe) => resolve(tpe).map(_.asInstanceOf[T])
case _ => Failure(new ReflectiveOperationException("Invalid type tag argument"))
}
Expand Down Expand Up @@ -472,17 +472,17 @@ If you wish to resolve types not registered in the container, specify revenj.res
if (handleClose && service.isInstanceOf[AutoCloseable]) {
closeables.add(service.asInstanceOf[AutoCloseable])
}
val paramType = Utils.findType(typeOf[T], mirror).getOrElse(throw new IllegalArgumentException(s"Unable to register ${typeOf[T]} to container"))
val paramType = Utils.findType(mirror.typeOf[T], mirror).getOrElse(throw new IllegalArgumentException(s"Unable to register ${mirror.typeOf[T]} to container"))
addToRegistry(new Registration[T](paramType, this, service, false))
}

override def registerFunc[T: TypeTag](factory: Container => T, lifetime: InstanceScope = Transient): this.type = {
val paramType = Utils.findType(typeOf[T], mirror).getOrElse(throw new IllegalArgumentException(s"Unable to register ${typeOf[T]} to container"))
val paramType = Utils.findType(mirror.typeOf[T], mirror).getOrElse(throw new IllegalArgumentException(s"Unable to register ${mirror.typeOf[T]} to container"))
addToRegistry(new Registration[T](paramType, this, factory, lifetime))
}

override def registerGenerics[T: TypeTag](factory: (Container, Array[JavaType]) => T, lifetime: InstanceScope = Transient): this.type = {
addToRegistry(new Registration[T](mirror.runtimeClass(typeOf[T]), this, factory, lifetime))
addToRegistry(new Registration[T](mirror.runtimeClass(mirror.typeOf[T]), this, factory, lifetime))
}

override def createScope(): Container = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class JacksonSerialization(
}

def serialize[T: TypeTag](value: T): Try[String] = {
Utils.findType(typeOf[T], mirror) match {
Utils.findType(mirror.typeOf[T], mirror) match {
case Some(tpe) => serializeRuntime(value, tpe)
case _ => Failure(new IllegalArgumentException("Unable to find Java type for: " + typeOf[T]))
case _ => Failure(new IllegalArgumentException(s"Unable to find Java type for: ${mirror.typeOf[T]}"))
}
}

Expand Down Expand Up @@ -87,9 +87,9 @@ class JacksonSerialization(
}

override def deserialize[T: TypeTag](input: String): Try[T] = {
Utils.findType(typeOf[T], mirror) match {
Utils.findType(mirror.typeOf[T], mirror) match {
case Some(tpe) => deserializeRuntime[T](input, tpe)
case _ => Failure(new IllegalArgumentException("Unable to find Java type for: " + typeOf[T]))
case _ => Failure(new IllegalArgumentException(s"Unable to find Java type for: ${mirror.typeOf[T]}"))
}
}
}
Expand Down

0 comments on commit 3f236e9

Please sign in to comment.