From f697407ba41256c33626b38669b3d1f05ff4deb4 Mon Sep 17 00:00:00 2001 From: Jacob Wang Date: Mon, 8 Jun 2020 16:49:48 +1200 Subject: [PATCH] Use sbt-tpolecat for setting strict scalac options --- .../mauth-authenticator-akka-http/README.adoc | 4 +- .../akka/http/MauthPublicKeyProvider.scala | 2 +- .../mauth/akka/http/MAuthDirectivesSpec.scala | 4 +- .../utils/RequestAuthenticatorSpec.scala | 2 +- .../mdsol/mauth/MAuthRequestSignerSpec.scala | 4 +- project/BuildSettings.scala | 97 ++----------------- project/plugins.sbt | 19 ++-- 7 files changed, 28 insertions(+), 104 deletions(-) diff --git a/modules/mauth-authenticator-akka-http/README.adoc b/modules/mauth-authenticator-akka-http/README.adoc index 07930541..5606e728 100644 --- a/modules/mauth-authenticator-akka-http/README.adoc +++ b/modules/mauth-authenticator-akka-http/README.adoc @@ -29,8 +29,8 @@ class MyController extends MAuthDirectives { implicit val system: ActorSystem = ActorSystem() implicit val publicKeyProvider: ClientPublicKeyProvider = new MauthPublicKeyProvider(authConfig, MAuthRequestSigner(singerConfiguration)) - implicit val timeout: FiniteDuration = 10 seconds - implicit val requestValidationTimeout: Duration = authConfig.getTimeToLive seconds + implicit val timeout: FiniteDuration = 10.seconds + implicit val requestValidationTimeout: Duration = authConfig.getTimeToLive.seconds implicit val authenticator: RequestAuthenticator = new RequestAuthenticator(publicKeyProvider, new CurrentEpochTimeProvider, authConfig.isV2OnlyAuthenticate) def getResource = authenticate.apply { diff --git a/modules/mauth-authenticator-akka-http/src/main/scala/com/mdsol/mauth/akka/http/MauthPublicKeyProvider.scala b/modules/mauth-authenticator-akka-http/src/main/scala/com/mdsol/mauth/akka/http/MauthPublicKeyProvider.scala index 1aa39932..5bdb5f0d 100644 --- a/modules/mauth-authenticator-akka-http/src/main/scala/com/mdsol/mauth/akka/http/MauthPublicKeyProvider.scala +++ b/modules/mauth-authenticator-akka-http/src/main/scala/com/mdsol/mauth/akka/http/MauthPublicKeyProvider.scala @@ -40,7 +40,7 @@ class MauthPublicKeyProvider(configuration: AuthenticatorConfiguration, signer: * @param appUUID , UUID of the application for which we want to retrieve its public key. * @return { @link PublicKey} registered in MAuth for the application with given appUUID. */ - override def getPublicKey(appUUID: UUID): Future[Option[PublicKey]] = memoizeF(Some(configuration.getTimeToLive seconds)) { + override def getPublicKey(appUUID: UUID): Future[Option[PublicKey]] = memoizeF(Some(configuration.getTimeToLive.seconds)) { val signedRequest = signer.signRequest(UnsignedRequest.noBody("GET", new URI(configuration.getBaseUrl + getRequestUrlPath(appUUID)), headers = Map.empty)) retrievePublicKey()(HttpClient.call(signedRequest.toAkkaHttpRequest)) } diff --git a/modules/mauth-authenticator-akka-http/src/test/scala/com/mdsol/mauth/akka/http/MAuthDirectivesSpec.scala b/modules/mauth-authenticator-akka-http/src/test/scala/com/mdsol/mauth/akka/http/MAuthDirectivesSpec.scala index bfb8cca3..98878db1 100644 --- a/modules/mauth-authenticator-akka-http/src/test/scala/com/mdsol/mauth/akka/http/MAuthDirectivesSpec.scala +++ b/modules/mauth-authenticator-akka-http/src/test/scala/com/mdsol/mauth/akka/http/MAuthDirectivesSpec.scala @@ -42,8 +42,8 @@ class MAuthDirectivesSpec extends AnyWordSpec with Matchers with ScalatestRouteT private val authPrefixV2: String = "MWSV2" private val authHeaderV2: String = s"$authPrefixV2 $appUuid:$signatureV2" - private implicit val timeout: FiniteDuration = 30 seconds - private implicit val requestValidationTimeout: Duration = 10 seconds + private implicit val timeout: FiniteDuration = 30.seconds + private implicit val requestValidationTimeout: Duration = 10.seconds private val client = mock[ClientPublicKeyProvider] private val mockEpochTimeProvider: EpochTimeProvider = mock[EpochTimeProvider] private val authenticator: RequestAuthenticator = new RequestAuthenticator(client, mockEpochTimeProvider) diff --git a/modules/mauth-authenticator-scala/src/test/scala/com/mdsol/mauth/scaladsl/utils/RequestAuthenticatorSpec.scala b/modules/mauth-authenticator-scala/src/test/scala/com/mdsol/mauth/scaladsl/utils/RequestAuthenticatorSpec.scala index 63603e3d..38dcb5a7 100644 --- a/modules/mauth-authenticator-scala/src/test/scala/com/mdsol/mauth/scaladsl/utils/RequestAuthenticatorSpec.scala +++ b/modules/mauth-authenticator-scala/src/test/scala/com/mdsol/mauth/scaladsl/utils/RequestAuthenticatorSpec.scala @@ -18,7 +18,7 @@ import scala.concurrent.duration._ class RequestAuthenticatorSpec extends AnyFlatSpec with RequestAuthenticatorBaseSpec with Matchers with ScalaFutures with MockFactory { - private implicit val requestValidationTimeout: Duration = 10 seconds + private implicit val requestValidationTimeout: Duration = 10.seconds behavior of "RequestAuthenticator Scala" diff --git a/modules/mauth-signer-akka-http/src/test/scala/com/mdsol/mauth/MAuthRequestSignerSpec.scala b/modules/mauth-signer-akka-http/src/test/scala/com/mdsol/mauth/MAuthRequestSignerSpec.scala index a21c3ff5..3923263c 100644 --- a/modules/mauth-signer-akka-http/src/test/scala/com/mdsol/mauth/MAuthRequestSignerSpec.scala +++ b/modules/mauth-signer-akka-http/src/test/scala/com/mdsol/mauth/MAuthRequestSignerSpec.scala @@ -167,7 +167,7 @@ class MAuthRequestSignerSpec extends AnyFlatSpec with Matchers with HttpClient w headers = Map("Content-Type" -> ContentTypes.`application/json`.toString()) ) - whenReady(HttpClient.call(signerV2.signRequest(simpleNewUnsignedRequest).toAkkaHttpRequest), timeout = Timeout(5 seconds)) { response => + whenReady(HttpClient.call(signerV2.signRequest(simpleNewUnsignedRequest).toAkkaHttpRequest), timeout = Timeout(5.seconds)) { response => response.status shouldBe StatusCodes.OK } } @@ -183,7 +183,7 @@ class MAuthRequestSignerSpec extends AnyFlatSpec with Matchers with HttpClient w NewUnsignedRequest .fromStringBodyUtf8(httpMethod = "POST", uri = new URI(s"${service.baseUrl()}/v1/test"), body = "", headers = Map()) - whenReady(HttpClient.call(signerV2.signRequest(simpleNewUnsignedRequest).toAkkaHttpRequest), timeout = Timeout(5 seconds)) { response => + whenReady(HttpClient.call(signerV2.signRequest(simpleNewUnsignedRequest).toAkkaHttpRequest), timeout = Timeout(5.seconds)) { response => response.status shouldBe StatusCodes.OK } } diff --git a/project/BuildSettings.scala b/project/BuildSettings.scala index 4c4f7141..2a72f1f5 100644 --- a/project/BuildSettings.scala +++ b/project/BuildSettings.scala @@ -1,7 +1,6 @@ import java.util import com.jsuereth.sbtpgp.SbtPgp.autoImport._ -import com.typesafe.tools.mima.plugin.MimaPlugin.autoImport._ import sbt.Keys._ import sbt.{url, _} import sbtassembly.AssemblyKeys._ @@ -11,13 +10,10 @@ import smartrelease.SmartReleasePlugin.ReleaseSteps import xerial.sbt.Sonatype.SonatypeKeys._ import xerial.sbt.Sonatype._ -import scala.sys.process.{Process, ProcessLogger} -import scala.util.Try - object BuildSettings { val env: util.Map[String, String] = System.getenv() - val scala212 = "2.12.10" - val scala213 = "2.13.1" + val scala212 = "2.12.11" + val scala213 = "2.13.2" lazy val basicSettings = Seq( homepage := Some(new URL("https://github.com/mdsol/mauth-jvm-clients")), @@ -32,12 +28,12 @@ object BuildSettings { // Avoid issues such as java.lang.IllegalAccessError: tried to access method org.bouncycastle.jcajce.provider.asymmetric.rsa.BCRSAPublicKey // By running tests in a separate JVM Test / fork := true, - scalacOptions ++= commonScalacOptions ++ silencerOptions ++ { - CrossVersion.partialVersion(scalaVersion.value) match { - case Some((2, 12)) => scalacOptionsFor212 - case Some((2, 13)) => scalacOptionsFor213 - case _ => Nil - } + scalacOptions ++= silencerOptions, + scalacOptions --= { + if (sys.env.contains("CI")) + Seq.empty + else + Seq("-Xfatal-warnings") }, credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", env.get("SONATYPE_USER"), env.get("SONATYPE_TOKEN")), publishTo := Some( @@ -59,78 +55,6 @@ object BuildSettings { "-P:silencer:pathFilters=target/.*" ) - private lazy val commonScalacOptions = Seq( - "-deprecation", - "-encoding", - "utf-8", - "-explaintypes", - "-feature", - "-language:existentials", - "-language:experimental.macros", - "-language:higherKinds", - "-language:implicitConversions", - "-language:postfixOps", - "-unchecked", - "-Xcheckinit", - "-Xlint:adapted-args", - "-Xlint:constant", - "-Xlint:delayedinit-select", - "-Xlint:doc-detached", - "-Xlint:inaccessible", - "-Xlint:infer-any", - "-Xlint:missing-interpolator", - "-Xlint:nullary-override", - "-Xlint:nullary-unit", - "-Xlint:option-implicit", - "-Xlint:package-object-classes", - "-Xlint:poly-implicit-overload", - "-Xlint:private-shadow", - "-Xlint:stars-align", - "-Xlint:type-parameter-shadow" - ) - - // See https://tpolecat.github.io/2017/04/25/scalac-flags.html - private lazy val scalacOptionsFor212 = Seq( - "-Xfatal-warnings", - "-Xfuture", - "-Xlint:by-name-right-associative", - "-Xlint:unsound-match", - "-Yno-adapted-args", - "-Ypartial-unification", - "-Ywarn-dead-code", - "-Ywarn-extra-implicit", - "-Ywarn-inaccessible", - "-Ywarn-infer-any", - "-Ywarn-nullary-override", - "-Ywarn-nullary-unit", - "-Ywarn-numeric-widen", - "-Ywarn-unused:implicits", - "-Ywarn-unused:imports", - "-Ywarn-unused:locals", - "-Ywarn-unused:params", - "-Ywarn-unused:patvars", - "-Ywarn-unused:privates", - "-Ywarn-value-discard" - ) - - // See https://nathankleyn.com/2019/05/13/recommended-scalac-flags-for-2-13 - private lazy val scalacOptionsFor213 = Seq( - "-language:reflectiveCalls", - "-Wextra-implicit", - "-Wnumeric-widen", - "-Woctal-literal", - "-Wunused:explicits", - "-Wunused:implicits", - "-Wunused:imports", - "-Wunused:locals", - "-Wunused:patvars", - "-Wunused:privates", - "-Wunused:privates", - "-Wunused:linted", - "-Wvalue-discard", - "-Werror" - ) - lazy val publishSettings = Seq( sonatypeProfileName := "com.mdsol", publishMavenStyle := true, @@ -150,9 +74,8 @@ object BuildSettings { releaseCommitMessage := s"Setting version to ${(version in ThisBuild).value} [ci skip]", releaseNextCommitMessage := s"Setting version to ${(version in ThisBuild).value} [ci skip]", releasePublishArtifactsAction := PgpKeys.publishSigned.value, - releaseVersionBump := sbtrelease.Version.Bump.Bugfix, releaseCrossBuild := false, // true if you cross-build the project for multiple Scala versions - releaseProcess := smartReleaseDefaultSteps, + releaseProcess := releaseSteps, credentials += Credentials( "GnuPG Key ID", "pgp", @@ -175,7 +98,7 @@ object BuildSettings { } ) - val smartReleaseDefaultSteps: Seq[ReleaseStep] = { + val releaseSteps: Seq[ReleaseStep] = { import sbtrelease.ReleaseStateTransformations._ Seq( checkSnapshotDependencies, diff --git a/project/plugins.sbt b/project/plugins.sbt index 5462200e..736ec485 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,9 +1,10 @@ -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10") -addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13") -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1") -addSbtPlugin("com.mdsol" % "sbt-smartrelease" % "0.3.2") -addSbtPlugin("com.mintbeans" % "sbt-ecr" % "0.15.0") -addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.1") -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8.1") -addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.5.0") +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10") +addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13") +addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1") +addSbtPlugin("com.mdsol" % "sbt-smartrelease" % "0.3.2") +addSbtPlugin("com.mintbeans" % "sbt-ecr" % "0.15.0") +addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.1") +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8.1") +addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.5.0") +addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.12")