Skip to content

Commit

Permalink
Merge pull request #125 from mdsol/use_sbt_tpolecat
Browse files Browse the repository at this point in the history
Use sbt-tpolecat for setting strict scalac options
  • Loading branch information
austek authored Jun 8, 2020
2 parents cf53825 + f697407 commit 4f3a07e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 104 deletions.
4 changes: 2 additions & 2 deletions modules/mauth-authenticator-akka-http/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand Down
97 changes: 10 additions & 87 deletions project/BuildSettings.scala
Original file line number Diff line number Diff line change
@@ -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._
Expand All @@ -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")),
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -175,7 +98,7 @@ object BuildSettings {
}
)

val smartReleaseDefaultSteps: Seq[ReleaseStep] = {
val releaseSteps: Seq[ReleaseStep] = {
import sbtrelease.ReleaseStateTransformations._
Seq(
checkSnapshotDependencies,
Expand Down
19 changes: 10 additions & 9 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 4f3a07e

Please sign in to comment.