mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 01:07:18 +03:00
Introduce //libs-scala/scala-utils (#6935)
* Moving `Statements.discard` from //ledger-server/http-json into //libs-scala/scala-utils changelog_begin changelog_end * Add new module to the published artifacts * `com.daml.scalautil` instead of `com.daml.scala.util` @S11001001: That's because if this is in classpath and you import com.daml._, you have a different scala in scope than the one you expect.
This commit is contained in:
parent
83031f3edf
commit
05d49b37c3
@ -41,6 +41,7 @@ da_scala_library(
|
||||
"//ledger/ledger-api-common",
|
||||
"//libs-scala/auth-utils",
|
||||
"//libs-scala/ports",
|
||||
"//libs-scala/scala-utils",
|
||||
"@maven//:com_chuusai_shapeless_2_12",
|
||||
"@maven//:com_github_scopt_scopt_2_12",
|
||||
"@maven//:com_lihaoyi_sourcecode_2_12",
|
||||
@ -84,6 +85,7 @@ da_scala_binary(
|
||||
"//ledger/ledger-api-common",
|
||||
"//libs-scala/auth-utils",
|
||||
"//libs-scala/ports",
|
||||
"//libs-scala/scala-utils",
|
||||
"@maven//:ch_qos_logback_logback_classic",
|
||||
"@maven//:com_chuusai_shapeless_2_12",
|
||||
"@maven//:com_github_scopt_scopt_2_12",
|
||||
@ -129,6 +131,7 @@ da_scala_test(
|
||||
"//ledger-service/db-backend",
|
||||
"//ledger-service/lf-value-json",
|
||||
"//ledger/ledger-api-common",
|
||||
"//libs-scala/scala-utils",
|
||||
"//libs-scala/scalatest-utils",
|
||||
"@maven//:com_chuusai_shapeless_2_12",
|
||||
"@maven//:com_lihaoyi_sourcecode_2_12",
|
||||
@ -184,6 +187,7 @@ da_scala_test(
|
||||
"//libs-scala/auth-utils",
|
||||
"//libs-scala/ports",
|
||||
"//libs-scala/postgresql-testing",
|
||||
"//libs-scala/scala-utils",
|
||||
"@maven//:ch_qos_logback_logback_classic",
|
||||
"@maven//:com_chuusai_shapeless_2_12",
|
||||
"@maven//:com_github_ghik_silencer_lib_2_12_11",
|
||||
|
@ -8,7 +8,7 @@ import java.nio.file.Files
|
||||
|
||||
import akka.http.scaladsl.Http
|
||||
import akka.http.scaladsl.model.{HttpMethods, HttpRequest, StatusCodes, Uri}
|
||||
import com.daml.http.Statement.discard
|
||||
import com.daml.scalautil.Statement.discard
|
||||
import com.daml.http.util.TestUtil.writeToFile
|
||||
import org.scalacheck.Gen
|
||||
import org.scalatest.{Assertion, BeforeAndAfterAll}
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
package com.daml.http
|
||||
|
||||
import com.daml.http.Statement.discard
|
||||
import com.daml.scalautil.Statement.discard
|
||||
import com.daml.testing.postgresql.PostgresAroundAll
|
||||
import spray.json.{JsString, JsValue}
|
||||
|
||||
|
@ -17,7 +17,7 @@ import akka.stream.scaladsl.{
|
||||
Source,
|
||||
}
|
||||
import akka.stream.{ClosedShape, FanOutShape2, FlowShape, Graph, Materializer}
|
||||
import com.daml.http.Statement.discard
|
||||
import com.daml.scalautil.Statement.discard
|
||||
import com.daml.http.dbbackend.ContractDao.StaleOffsetException
|
||||
import com.daml.http.dbbackend.{ContractDao, Queries}
|
||||
import com.daml.http.dbbackend.Queries.{DBContract, SurrogateTpId}
|
||||
|
@ -19,7 +19,7 @@ import akka.util.ByteString
|
||||
import com.daml.lf
|
||||
import com.daml.http.ContractsService.SearchResult
|
||||
import com.daml.http.EndpointsCompanion._
|
||||
import com.daml.http.Statement.discard
|
||||
import com.daml.scalautil.Statement.discard
|
||||
import com.daml.http.domain.JwtPayload
|
||||
import com.daml.http.json._
|
||||
import com.daml.http.util.Collections.toNonEmptySet
|
||||
|
@ -12,7 +12,7 @@ import akka.http.scaladsl.settings.ServerSettings
|
||||
import akka.stream.Materializer
|
||||
import com.daml.auth.TokenHolder
|
||||
import com.daml.grpc.adapter.ExecutionSequencerFactory
|
||||
import com.daml.http.Statement.discard
|
||||
import com.daml.scalautil.Statement.discard
|
||||
import com.daml.http.dbbackend.ContractDao
|
||||
import com.daml.http.json.{
|
||||
ApiValueToJsValueConverter,
|
||||
|
@ -10,7 +10,7 @@ import akka.actor.ActorSystem
|
||||
import akka.http.scaladsl.Http.ServerBinding
|
||||
import akka.stream.Materializer
|
||||
import com.daml.grpc.adapter.{AkkaExecutionSequencerPool, ExecutionSequencerFactory}
|
||||
import com.daml.http.Statement.discard
|
||||
import com.daml.scalautil.Statement.discard
|
||||
import com.daml.http.dbbackend.ContractDao
|
||||
import com.daml.ledger.api.tls.TlsConfigurationCli
|
||||
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
|
||||
|
@ -292,7 +292,7 @@ class WebSocketService(
|
||||
extends LazyLogging {
|
||||
|
||||
import WebSocketService._
|
||||
import Statement.discard
|
||||
import com.daml.scalautil.Statement.discard
|
||||
import util.ErrorOps._
|
||||
import com.daml.http.json.JsonProtocol._
|
||||
|
||||
|
@ -16,7 +16,7 @@ import com.daml.http.Generators.{
|
||||
genUnknownTemplateIds,
|
||||
genWarningsWrapper
|
||||
}
|
||||
import com.daml.http.Statement.discard
|
||||
import com.daml.scalautil.Statement.discard
|
||||
import com.daml.http.domain
|
||||
import org.scalacheck.Arbitrary.arbitrary
|
||||
import org.scalacheck.Gen.{identifier, listOf}
|
||||
|
36
libs-scala/scala-utils/BUILD.bazel
Normal file
36
libs-scala/scala-utils/BUILD.bazel
Normal file
@ -0,0 +1,36 @@
|
||||
# Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
load(
|
||||
"//bazel_tools:scala.bzl",
|
||||
"da_scala_library",
|
||||
"da_scala_test",
|
||||
"lf_scalacopts",
|
||||
)
|
||||
|
||||
scalacopts = lf_scalacopts + [
|
||||
"-P:wartremover:traverser:org.wartremover.warts.NonUnitStatements",
|
||||
]
|
||||
|
||||
da_scala_library(
|
||||
name = "scala-utils",
|
||||
srcs = glob(["src/main/scala/**/*.scala"]),
|
||||
scalacopts = scalacopts,
|
||||
tags = ["maven_coordinates=com.daml:scala-utils:__VERSION__"],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
deps = [
|
||||
],
|
||||
)
|
||||
|
||||
da_scala_test(
|
||||
name = "test",
|
||||
srcs = glob(["src/test/scala/**/*.scala"]),
|
||||
scalacopts = scalacopts,
|
||||
deps = [
|
||||
":scala-utils",
|
||||
"//libs-scala/scalatest-utils",
|
||||
"@maven//:org_scalaz_scalaz_core_2_12",
|
||||
],
|
||||
)
|
@ -1,9 +1,16 @@
|
||||
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package com.daml.http
|
||||
package com.daml.scalautil
|
||||
|
||||
object Statement {
|
||||
|
||||
/**
|
||||
* Suppresses `traverser:org.wartremover.warts.NonUnitStatements` warning on the expression level.
|
||||
*
|
||||
* @param evaluateForSideEffectOnly an expression with a side-effect that needs to be evaluated.
|
||||
* @tparam A return type of the expression that gets discarded.
|
||||
*/
|
||||
@specialized def discard[A](evaluateForSideEffectOnly: A): Unit = {
|
||||
val _: A = evaluateForSideEffectOnly
|
||||
() //Return unit to prevent warning due to discarding value
|
@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package com.daml.scalautil
|
||||
|
||||
import org.scalatest.{FlatSpec, Matchers}
|
||||
|
||||
class StatementSpec extends FlatSpec with Matchers {
|
||||
import com.daml.scalatest.Equalz._
|
||||
import scalaz.std.anyVal._
|
||||
|
||||
behavior of Statement.getClass.getSimpleName
|
||||
|
||||
it should "evaluate passed expression for side effects" in {
|
||||
var counter: Int = 0
|
||||
|
||||
def increment(): Int = {
|
||||
counter += 1
|
||||
counter
|
||||
}
|
||||
|
||||
Statement.discard(increment()): Unit
|
||||
|
||||
Statement.discard {
|
||||
counter += 1
|
||||
}: Unit
|
||||
|
||||
counter shouldx equalz(2)
|
||||
}
|
||||
|
||||
it should "not evaluate passed lambda expression" in {
|
||||
var counter: Int = 0
|
||||
|
||||
Statement.discard { () =>
|
||||
counter += 1
|
||||
}
|
||||
|
||||
counter shouldx equalz(0)
|
||||
}
|
||||
}
|
@ -149,3 +149,5 @@
|
||||
type: jar-scala
|
||||
- target: //libs-scala/build-info:build-info
|
||||
type: jar-scala
|
||||
- target: //libs-scala/scala-utils:scala-utils
|
||||
type: jar-scala
|
||||
|
Loading…
Reference in New Issue
Block a user