Skip to content

Commit

Permalink
Removed deprecations, installed wart remover (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
KarelCemus authored Feb 2, 2024
1 parent c9cae12 commit 1b9cdda
Show file tree
Hide file tree
Showing 55 changed files with 638 additions and 566 deletions.
23 changes: 23 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,26 @@ enablePlugins(CustomReleasePlugin)
coverageExcludedFiles := ".*exceptions.*"

Test / test := (Test / testOnly).toTask(" * -- -l \"org.scalatest.Ignore\"").value

wartremoverWarnings ++= Warts.allBut(
Wart.Any,
Wart.AnyVal,
Wart.AsInstanceOf,
Wart.AutoUnboxing,
Wart.DefaultArguments,
Wart.GlobalExecutionContext,
Wart.ImplicitConversion,
Wart.ImplicitParameter,
Wart.IterableOps,
Wart.NonUnitStatements,
Wart.Nothing,
Wart.Null,
Wart.OptionPartial,
Wart.Overloading,
Wart.PlatformDefault,
Wart.StringPlusAny,
Wart.Throw,
Wart.ToString,
Wart.TryPartial,
Wart.Var,
)
16 changes: 8 additions & 8 deletions project/CustomReleasePlugin.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import com.github.sbt.git.{GitVersioning, SbtGit}
import sbt.*
import sbt.Keys.*
import sbtrelease.*
import sbt._
import sbt.Keys._
import sbtrelease._
import xerial.sbt.Sonatype

object CustomReleasePlugin extends AutoPlugin {

import ReleasePlugin.autoImport.*
import ReleaseStateTransformations.*
import ReleaseUtilities.*
import Sonatype.autoImport.*
import ReleasePlugin.autoImport._
import ReleaseStateTransformations._
import ReleaseUtilities._
import Sonatype.autoImport._

object autoImport {
val playVersion = settingKey[String]("Version of Play framework")
Expand All @@ -27,7 +27,7 @@ object CustomReleasePlugin extends AutoPlugin {
)
}

override def projectSettings = Seq[Setting[_]](
override def projectSettings: Seq[Setting[_]] = Seq[Setting[_]](
publishMavenStyle := true,
pomIncludeRepository := { _ => false },
// customized release process
Expand Down
1 change: 1 addition & 0 deletions project/ReleaseUtilities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import scala.sys.process.ProcessLogger

import sbt._
import sbtrelease._
import scala.language.implicitConversions

object ReleaseUtilities {

Expand Down
3 changes: 3 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ addSbtPlugin("com.github.sbt" % "sbt-git" % "2.0.1")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.21")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0")

// linters
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.1.6")
1 change: 0 additions & 1 deletion src/main/scala/play/api/cache/redis/CacheApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package play.api.cache.redis

import scala.concurrent.Future
import scala.concurrent.duration.Duration
import scala.language.higherKinds
import scala.reflect.ClassTag

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/play/api/cache/redis/Expiration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ private[redis] trait ExpirationImplicits {
class Expiration(val expireAt: Long) extends AnyVal {

/** returns now in milliseconds */
private def now = System.currentTimeMillis()
private def now: Long = System.currentTimeMillis()

/** converts given timestamp indication expiration date into duration from now */
def asExpiration = (expireAt - now).milliseconds
def asExpiration: FiniteDuration = (expireAt - now).milliseconds
}
37 changes: 19 additions & 18 deletions src/main/scala/play/api/cache/redis/RecoveryPolicy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,22 @@ trait RecoveryPolicy {
trait Reports extends RecoveryPolicy {

/** logger instance */
protected val log = Logger("play.api.cache.redis")

protected def message(failure: RedisException): String = failure match {
case TimeoutException(cause) => s"Command execution timed out."
case SerializationException(key, message, cause) => s"$message for key '$key'."
case ExecutionFailedException(Some(key), command, statement, cause) => s"Command $command for key '$key' failed."
case ExecutionFailedException(None, command, statement, cause) => s"Command $command failed."
case UnexpectedResponseException(Some(key), command) => s"Command $command for key '$key' returned unexpected response."
case UnexpectedResponseException(None, command) => s"Command $command returned unexpected response."
}
protected val log: Logger = Logger("play.api.cache.redis")

protected def message(failure: RedisException): String =
failure match {
case TimeoutException(_) => s"Command execution timed out."
case SerializationException(key, message, _) => s"$message for key '$key'."
case ExecutionFailedException(Some(key), command, _, _) => s"Command $command for key '$key' failed."
case ExecutionFailedException(None, command, _, _) => s"Command $command failed."
case UnexpectedResponseException(Some(key), command) => s"Command $command for key '$key' returned unexpected response."
case UnexpectedResponseException(None, command) => s"Command $command returned unexpected response."
}

protected def doLog(message: String, cause: Option[Throwable]): Unit

/** reports a failure into logs */
protected def report(failure: RedisException) = {
private def report(failure: RedisException): Unit = {
// create a failure report and report a failure
doLog(message(failure), Option(failure.getCause))
}
Expand Down Expand Up @@ -115,14 +116,14 @@ trait RecoverWithDefault extends RecoveryPolicy {
/**
* When the command fails, it logs the failure and fails the whole operation.
*/
private[redis] class LogAndFailPolicy @Inject() () extends FailThrough with DetailedReports
private[redis] class LogAndFailPolicy @Inject() extends FailThrough with DetailedReports

/**
* When the command fails, it logs the failure and returns default value
* to prevent application failure. The returned value is neutral to the
* operation and it should behave like there is no cache
*/
private[redis] class LogAndDefaultPolicy @Inject() () extends RecoverWithDefault with DetailedReports
private[redis] class LogAndDefaultPolicy @Inject() extends RecoverWithDefault with DetailedReports

/**
* When the command fails, it logs the failure and returns default value
Expand All @@ -132,15 +133,15 @@ private[redis] class LogAndDefaultPolicy @Inject() () extends RecoverWithDefault
* LogCondensed produces condensed messages without a stacktrace to avoid
* extensive logs
*/
private[redis] class LogCondensedAndDefaultPolicy @Inject() () extends RecoverWithDefault with CondensedReports
private[redis] class LogCondensedAndDefaultPolicy @Inject() extends RecoverWithDefault with CondensedReports

/**
* When the command fails, it logs the failure and fails the whole operation.
*
* LogCondensed produces condensed messages without a stacktrace to avoid
* extensive logs
*/
private[redis] class LogCondensedAndFailPolicy @Inject() () extends FailThrough with CondensedReports
private[redis] class LogCondensedAndFailPolicy @Inject() extends FailThrough with CondensedReports

/**
* This resolver represents an abstraction over translation
Expand All @@ -154,7 +155,7 @@ trait RecoveryPolicyResolver {
// $COVERAGE-OFF$

class RecoveryPolicyResolverImpl extends RecoveryPolicyResolver {
val resolve: PartialFunction[String, RecoveryPolicy] = {
override val resolve: PartialFunction[String, RecoveryPolicy] = {
case "log-and-fail" => new LogAndFailPolicy
case "log-and-default" => new LogAndDefaultPolicy
case "log-condensed-and-fail" => new LogCondensedAndFailPolicy
Expand All @@ -164,7 +165,7 @@ class RecoveryPolicyResolverImpl extends RecoveryPolicyResolver {

object RecoveryPolicyResolver {

def bindings = Seq(
def bindings: Seq[Binding[_]] = Seq(
bind[RecoveryPolicy].qualifiedWith("log-and-fail").to[LogAndFailPolicy],
bind[RecoveryPolicy].qualifiedWith("log-and-default").to[LogAndDefaultPolicy],
bind[RecoveryPolicy].qualifiedWith("log-condensed-and-fail").to[LogCondensedAndFailPolicy],
Expand All @@ -177,7 +178,7 @@ object RecoveryPolicyResolver {
/** resolves a policies with guice enabled */
class RecoveryPolicyResolverGuice @Inject() (injector: Injector) extends RecoveryPolicyResolver {

def resolve = {
override def resolve: PartialFunction[String, RecoveryPolicy] = {
case name => injector instanceOf bind[RecoveryPolicy].qualifiedWith(name)
}
}
Expand Down
23 changes: 11 additions & 12 deletions src/main/scala/play/api/cache/redis/RedisCacheModule.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package play.api.cache.redis

import javax.inject._

import scala.language.implicitConversions
import scala.reflect.ClassTag

import play.api.inject._
import play.cache._

Expand All @@ -15,7 +13,7 @@ import play.cache._
@Singleton
class RedisCacheModule extends Module {

override def bindings(environment: play.api.Environment, config: play.api.Configuration) = {
override def bindings(environment: play.api.Environment, config: play.api.Configuration): Seq[Binding[_]] = {
def bindDefault = config.get[Boolean]("play.cache.redis.bind-default")

// read the config and get the configuration of the redis
Expand Down Expand Up @@ -44,7 +42,7 @@ trait ProviderImplicits {
}

private[redis] class RichBindingKey[T](val key: BindingKey[T]) extends AnyVal {
@inline def named(name: String) = key.qualifiedWith(new NamedCacheImpl(name))
@inline def named(name: String): BindingKey[T] = key.qualifiedWith(new NamedCacheImpl(name))
}

trait GuiceProviderImplicits extends ProviderImplicits {
Expand All @@ -61,8 +59,8 @@ object GuiceProvider extends ProviderImplicits {

private def namedBinding[T: ClassTag](f: impl.RedisCaches => T) = new QualifiedBindingKey(bind[T], f)

def bindings(instance: RedisInstanceProvider) = {
implicit val name = new CacheName(instance.name)
def bindings(instance: RedisInstanceProvider): Seq[Binding[_]] = {
implicit val name: CacheName = new CacheName(instance.name)

Seq[Binding[_]](
// bind implementation of all caches
Expand All @@ -80,9 +78,9 @@ object GuiceProvider extends ProviderImplicits {
).map(_.toBindings)
}

def defaults(instance: RedisInstanceProvider) = {
implicit val name = new CacheName(instance.name)
@inline def defaultBinding[T: ClassTag](implicit cacheName: CacheName): Binding[T] = bind[T].to(bind[T].named(name))
def defaults(instance: RedisInstanceProvider): Seq[Binding[_]] = {
implicit val name: CacheName = new CacheName(instance.name)
@inline def defaultBinding[T: ClassTag]: Binding[T] = bind[T].to(bind[T].named(name))

Seq(
// bind implementation of all caches
Expand All @@ -105,7 +103,7 @@ object GuiceProvider extends ProviderImplicits {

class GuiceRedisCacheProvider(instance: RedisInstanceProvider) extends Provider[RedisCaches] with GuiceProviderImplicits {
@Inject() var injector: Injector = _
lazy val get: RedisCaches = new impl.RedisCachesProvider(
override lazy val get: RedisCaches = new impl.RedisCachesProvider(
instance = instance.resolved(bind[configuration.RedisInstanceResolver]),
serializer = bind[connector.AkkaSerializer],
environment = bind[play.api.Environment]
Expand All @@ -118,17 +116,18 @@ class GuiceRedisCacheProvider(instance: RedisInstanceProvider) extends Provider[

class NamedCacheInstanceProvider[T](f: RedisCaches => T)(implicit name: CacheName) extends Provider[T] with GuiceProviderImplicits {
@Inject() var injector: Injector = _
lazy val get = f(bind[RedisCaches].named(name))
override lazy val get: T = f(bind[RedisCaches].named(name))
}

class CacheName(val name: String) extends AnyVal

object CacheName {
implicit def name2string(name: CacheName): String = name.name
}

@Singleton
class GuiceRedisInstanceResolver @Inject() (val injector: Injector) extends configuration.RedisInstanceResolver with GuiceProviderImplicits {
def resolve = {
override def resolve: PartialFunction[String, RedisInstance] = {
case name => bind[RedisInstance].named(name)
}
}
2 changes: 0 additions & 2 deletions src/main/scala/play/api/cache/redis/RedisCollection.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package play.api.cache.redis

import scala.language.higherKinds

private[redis] trait RedisCollection[Collection, Result[_]] {

type This >: this.type
Expand Down
2 changes: 0 additions & 2 deletions src/main/scala/play/api/cache/redis/RedisList.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package play.api.cache.redis

import scala.language.higherKinds

/**
* Redis Lists are simply lists of strings, sorted by insertion order.
* It is possible to add elements to a Redis List pushing new elements
Expand Down
2 changes: 0 additions & 2 deletions src/main/scala/play/api/cache/redis/RedisMap.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package play.api.cache.redis

import scala.language.higherKinds

/**
* Redis Hashes are simply hash maps with strings as keys. It is possible to add
* elements to a Redis Hashes by adding new elements into the collection.
Expand Down
2 changes: 0 additions & 2 deletions src/main/scala/play/api/cache/redis/RedisSet.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package play.api.cache.redis

import scala.language.higherKinds

/**
* Redis Sets are simply unsorted sets of objects. It is possible to add
* elements to a Redis Set by adding new elements into the collection.
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/play/api/cache/redis/RedisSortedSet.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package play.api.cache.redis

import scala.collection.immutable.TreeSet
import scala.language.higherKinds

trait RedisSortedSet[Elem, Result[_]] extends RedisCollection[TreeSet[Elem], Result] {
override type This = RedisSortedSet[Elem, Result]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package play.api.cache.redis.configuration

import play.api.cache.redis._

private[configuration] object Equals {

// $COVERAGE-OFF$
@inline
def check[T](a: T, b: T)(property: (T => Any)*): Boolean = {
property.forall(property => property(a) == property(b))
property.forall(property => property(a) === property(b))
}
// $COVERAGE-ON$
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.net.InetAddress

object HostnameResolver {

implicit class HostNameResolver(val name: String) extends AnyVal {
def resolvedIpAddress = InetAddress.getByName(name).getHostAddress
implicit class HostNameResolver(private val name: String) extends AnyVal {
def resolvedIpAddress: String = InetAddress.getByName(name).getHostAddress
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package play.api.cache.redis.configuration

import com.typesafe.config.Config
import play.api.cache.redis._

/**
* Config loader helper, provides some useful methods
Expand All @@ -19,7 +20,7 @@ private[configuration] object RedisConfigLoader {
}

implicit class ConfigPath(val path: String) extends AnyVal {
def /(suffix: String): String = if (path == "") suffix else s"$path.$suffix"
def /(suffix: String): String = if (path === "") suffix else s"$path.$suffix"
}

def required(path: String) = throw new IllegalStateException(s"Configuration key '$path' is missing.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ trait RedisHost {
def password: Option[String]
// $COVERAGE-OFF$
/** trait-specific equals */
override def equals(obj: scala.Any) = equalsAsHost(obj)
override def equals(obj: scala.Any): Boolean = equalsAsHost(obj)
/** trait-specific equals, invokable from children */
protected def equalsAsHost(obj: scala.Any) = obj match {
protected def equalsAsHost(obj: scala.Any): Boolean = obj match {
case that: RedisHost => Equals.check(this, that)(_.host, _.port, _.username, _.database, _.password)
case _ => false
}
Expand All @@ -40,7 +40,7 @@ object RedisHost extends ConfigLoader[RedisHost] {
import RedisConfigLoader._

/** expected format of the environment variable */
private val ConnectionString = "redis://((?<username>[^:]+):(?<password>[^@]+)@)?(?<host>[^:]+):(?<port>[0-9]+)".r("auth", "username", "password", "host", "port")
private val ConnectionString = "redis://((?<username>[^:]+):(?<password>[^@]+)@)?(?<host>[^:]+):(?<port>[0-9]+)".r

def load(config: Config, path: String): RedisHost = apply(
host = config.getString(path / "host"),
Expand Down
Loading

0 comments on commit 1b9cdda

Please sign in to comment.