diff --git a/build.sbt b/build.sbt index f32f77bc..89200258 100644 --- a/build.sbt +++ b/build.sbt @@ -14,17 +14,14 @@ lazy val core = project .settings(moduleName := "mu-srcgen-core") .settings( libraryDependencies ++= Seq( - "io.higherkindness" %% "mu-rpc-service" % muV, - "io.higherkindness" %% "skeuomorph" % "0.0.29", - "com.github.julien-truffaut" %% "monocle-core" % "2.1.0", - "com.julianpeeters" %% "avrohugger-core" % "1.0.0-RC24", - "io.circe" %% "circe-generic" % "0.14.1", - "org.http4s" %% "http4s-blaze-client" % "0.21.29", - "org.http4s" %% "http4s-circe" % "0.21.29", - "org.scalatest" %% "scalatest" % "3.2.10" % Test, - "org.scalacheck" %% "scalacheck" % "1.15.4" % Test, - "org.scalatestplus" %% "scalacheck-1-14" % "3.2.2.0" % Test, - "org.slf4j" % "slf4j-nop" % "1.7.32" % Test + "io.higherkindness" %% "mu-rpc-service" % muV, + "io.higherkindness" %% "skeuomorph" % "0.0.29", + "com.github.julien-truffaut" %% "monocle-core" % "2.1.0", + "com.julianpeeters" %% "avrohugger-core" % "1.0.0-RC24", + "org.scalatest" %% "scalatest" % "3.2.10" % Test, + "org.scalacheck" %% "scalacheck" % "1.15.4" % Test, + "org.scalatestplus" %% "scalacheck-1-14" % "3.2.2.0" % Test, + "org.slf4j" % "slf4j-nop" % "1.7.32" % Test ) ) diff --git a/core/src/main/scala/higherkindness/mu/rpc/srcgen/Model.scala b/core/src/main/scala/higherkindness/mu/rpc/srcgen/Model.scala index 527a6955..8fcb9392 100644 --- a/core/src/main/scala/higherkindness/mu/rpc/srcgen/Model.scala +++ b/core/src/main/scala/higherkindness/mu/rpc/srcgen/Model.scala @@ -18,12 +18,6 @@ package higherkindness.mu.rpc.srcgen object Model { - sealed trait ExecutionMode extends Product with Serializable - object ExecutionMode { - case object Compendium extends ExecutionMode - case object Local extends ExecutionMode - } - sealed trait IdlType extends Product with Serializable object IdlType { case object Proto extends IdlType diff --git a/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/CompendiumClient.scala b/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/CompendiumClient.scala deleted file mode 100644 index b5ac0859..00000000 --- a/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/CompendiumClient.scala +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2020-2021 47 Degrees - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package higherkindness.mu.rpc.srcgen.compendium - -import cats.effect.Sync -import org.http4s._ -import org.http4s.circe._ -import cats.implicits._ -import org.http4s.client.{Client, UnexpectedStatus} - -trait CompendiumClient[F[_]] { - - /** - * Retrieve a Protocol by its id - * - * @param identifier - * the protocol identifier - * @param version - * optional protocol version number - * @return - * a protocol - */ - def retrieveProtocol(identifier: String, version: Option[Int]): F[Option[RawProtocol]] - -} - -object CompendiumClient { - - def apply[F[_]: Sync]( - clientF: Client[F], - clientConfig: HttpConfig - ): CompendiumClient[F] = - new CompendiumClient[F] { - - override def retrieveProtocol( - identifier: String, - version: Option[Int] - ): F[Option[RawProtocol]] = { - val versionParam = version.fold("")(v => s"?version=${v.show}") - val connectionUrl = s"${clientConfig.serverUrl}/v0/protocol/$identifier$versionParam" - - implicit val rawEntityDecoder = jsonOf[F, RawProtocol] - - clientF.get(connectionUrl)(res => - res.status match { - case Status.Ok => res.as[RawProtocol].map(Option(_)) - case Status.NotFound => Sync[F].pure(None) - case s => Sync[F].raiseError(UnexpectedStatus(s)) - } - ) - } - } - -} diff --git a/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/CompendiumError.scala b/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/CompendiumError.scala deleted file mode 100644 index e8311069..00000000 --- a/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/CompendiumError.scala +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2020-2021 47 Degrees - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package higherkindness.mu.rpc.srcgen.compendium - -abstract class CompendiumError(error: String) extends Exception(error) - -final case class ProtocolNotFound(msg: String) extends CompendiumError(msg) -final case class SchemaError(msg: String) extends CompendiumError(msg) -final case class UnknownError(msg: String) extends CompendiumError(msg) diff --git a/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/CompendiumMode.scala b/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/CompendiumMode.scala deleted file mode 100644 index ea95ff1e..00000000 --- a/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/CompendiumMode.scala +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020-2021 47 Degrees - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package higherkindness.mu.rpc.srcgen.compendium - -import java.io.{File, PrintWriter} - -import cats.effect.{ConcurrentEffect, Resource} - -import scala.util.Try -import cats.implicits._ -import org.http4s.client.blaze._ - -import scala.concurrent.ExecutionContext.global - -final case class ProtocolAndVersion(name: String, version: Option[String]) -final case class FilePrintWriter(file: File, pw: PrintWriter) - -final case class CompendiumMode[F[_]: ConcurrentEffect]( - protocols: List[ProtocolAndVersion], - fileType: String, - httpConfig: HttpConfig, - path: String -) { - - val httpClient = BlazeClientBuilder[F](global).resource - - def run(): F[List[File]] = - protocols.traverse(protocolAndVersion => - httpClient.use(client => { - for { - protocol <- CompendiumClient(client, httpConfig) - .retrieveProtocol( - protocolAndVersion.name, - safeInt(protocolAndVersion.version) - ) - file <- protocol match { - case Some(raw) => - writeTempFile( - raw.raw, - extension = fileType, - identifier = protocolAndVersion.name, - path = path - ) - case None => - ProtocolNotFound(s"Protocol ${protocolAndVersion.name} not found in Compendium. ") - .raiseError[F, File] - } - } yield file - }) - ) - - private def safeInt(s: Option[String]): Option[Int] = s.flatMap(str => Try(str.toInt).toOption) - - private def writeTempFile( - msg: String, - extension: String, - identifier: String, - path: String - ): F[File] = - Resource - .make(ConcurrentEffect[F].delay { - if (!new File(path).exists()) new File(path).mkdirs() - val file = new File(path + s"/$identifier.$extension") - file.deleteOnExit() - FilePrintWriter(file, new PrintWriter(file)) - }) { fpw: FilePrintWriter => ConcurrentEffect[F].delay(fpw.pw.close()) } - .use((fpw: FilePrintWriter) => ConcurrentEffect[F].delay(fpw.pw.write(msg)).as(fpw)) - .map(_.file) - -} diff --git a/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/ErrorResponse.scala b/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/ErrorResponse.scala deleted file mode 100644 index 17a0bdb2..00000000 --- a/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/ErrorResponse.scala +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2020-2021 47 Degrees - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package higherkindness.mu.rpc.srcgen.compendium - -import io.circe.{Decoder, Encoder} -import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} - -final case class ErrorResponse(message: String) - -object ErrorResponse { - implicit val decoder: Decoder[ErrorResponse] = deriveDecoder[ErrorResponse] - implicit val encoder: Encoder[ErrorResponse] = deriveEncoder[ErrorResponse] -} diff --git a/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/HttpConfig.scala b/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/HttpConfig.scala deleted file mode 100644 index 7df91a1f..00000000 --- a/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/HttpConfig.scala +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2020-2021 47 Degrees - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package higherkindness.mu.rpc.srcgen.compendium - -final case class HttpConfig(serverUrl: String) diff --git a/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/RawProtocol.scala b/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/RawProtocol.scala deleted file mode 100644 index 8722c16d..00000000 --- a/core/src/main/scala/higherkindness/mu/rpc/srcgen/compendium/RawProtocol.scala +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020-2021 47 Degrees - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package higherkindness.mu.rpc.srcgen.compendium - -import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} -import io.circe.{Decoder, Encoder} - -final case class RawProtocol(raw: String) - -object RawProtocol { - implicit val decoder: Decoder[RawProtocol] = deriveDecoder[RawProtocol] - implicit val encoder: Encoder[RawProtocol] = deriveEncoder[RawProtocol] - -} diff --git a/plugin/src/main/scala/higherkindness/mu/rpc/srcgen/SrcGenPlugin.scala b/plugin/src/main/scala/higherkindness/mu/rpc/srcgen/SrcGenPlugin.scala index 009e1a5e..6a568acb 100644 --- a/plugin/src/main/scala/higherkindness/mu/rpc/srcgen/SrcGenPlugin.scala +++ b/plugin/src/main/scala/higherkindness/mu/rpc/srcgen/SrcGenPlugin.scala @@ -18,17 +18,12 @@ package higherkindness.mu.rpc.srcgen import java.io.File -import cats.effect.{ContextShift, IO => IOCats} -import higherkindness.mu.rpc.srcgen.Model.ExecutionMode._ import sbt.Keys._ import sbt.{settingKey, Def, _} import sbt.io.{Path, PathFinder} import higherkindness.mu.rpc.srcgen.Model._ -import higherkindness.mu.rpc.srcgen.compendium.{CompendiumMode, HttpConfig, ProtocolAndVersion} import higherkindness.mu.rpc.srcgen.openapi.OpenApiSrcGenerator.HttpImpl -import scala.concurrent.ExecutionContext.global - object SrcGenPlugin extends AutoPlugin { override def trigger: PluginTrigger = noTrigger @@ -109,18 +104,6 @@ object SrcGenPlugin extends AutoPlugin { "By default, the streaming implementation is FS2 Stream." ) - lazy val muSrcGenExecutionMode = settingKey[ExecutionMode]( - "Execution mode of the plugin. If Compendium, it's required a compendium instance where IDL files are saved. `Local` by default." - ) - - lazy val muSrcGenCompendiumProtocolIdentifiers: SettingKey[Seq[ProtocolAndVersion]] = - settingKey[Seq[ProtocolAndVersion]]( - "Protocol identifiers (and version) to be retrieved from compendium server. By default is an empty list." - ) - - lazy val muSrcGenCompendiumServerUrl: SettingKey[String] = - settingKey[String]("Url of the compendium server. By default, `http://localhost:8080`.") - lazy val muSrcGenAvroGeneratorType: SettingKey[AvroGeneratorTypeGen] = settingKey[AvroGeneratorTypeGen]( "Specifies the Avro generation type: `SkeumorphGen` or `AvrohuggerGen`. `SkeumorphGen` by default." @@ -159,14 +142,11 @@ object SrcGenPlugin extends AutoPlugin { Nil } }, - muSrcGenCompressionType := NoCompressionGen, - muSrcGenIdiomaticEndpoints := true, - muSrcGenOpenApiHttpImpl := HttpImpl.Http4sV20, - muSrcGenStreamingImplementation := Fs2Stream, - muSrcGenExecutionMode := Local, - muSrcGenCompendiumProtocolIdentifiers := Nil, - muSrcGenCompendiumServerUrl := "http://localhost:8080", - muSrcGenAvroGeneratorType := SkeumorphGen + muSrcGenCompressionType := NoCompressionGen, + muSrcGenIdiomaticEndpoints := true, + muSrcGenOpenApiHttpImpl := HttpImpl.Http4sV20, + muSrcGenStreamingImplementation := Fs2Stream, + muSrcGenAvroGeneratorType := SkeumorphGen ) lazy val taskSettings: Seq[Def.Setting[_]] = { @@ -184,30 +164,17 @@ object SrcGenPlugin extends AutoPlugin { ) }, Def.task { - muSrcGenExecutionMode.value match { - case Compendium => - implicit val cs: ContextShift[IOCats] = IOCats.contextShift(global) - CompendiumMode[IOCats]( - muSrcGenCompendiumProtocolIdentifiers.value.toList, - muSrcGenIdlExtension.value, - HttpConfig( - muSrcGenCompendiumServerUrl.value - ), - muSrcGenIdlTargetDir.value.getAbsolutePath - ).run() - .unsafeRunSync() - case Local => - muSrcGenSourceDirs.value.toSet.foreach { f: File => - IO.copyDirectory( - f, - muSrcGenIdlTargetDir.value, - CopyOptions( - overwrite = true, - preserveLastModified = true, - preserveExecutable = true - ) - ) - } + + muSrcGenSourceDirs.value.toSet.foreach { f: File => + IO.copyDirectory( + f, + muSrcGenIdlTargetDir.value, + CopyOptions( + overwrite = true, + preserveLastModified = true, + preserveExecutable = true + ) + ) } }, Def.task { diff --git a/plugin/src/sbt-test/sbt-mu-srcgen/compendium/build.sbt b/plugin/src/sbt-test/sbt-mu-srcgen/compendium/build.sbt deleted file mode 100644 index 2970e3af..00000000 --- a/plugin/src/sbt-test/sbt-mu-srcgen/compendium/build.sbt +++ /dev/null @@ -1,7 +0,0 @@ -version := sys.props("version") - -enablePlugins(SrcGenPlugin) - -libraryDependencies ++= Seq( - "io.higherkindness" %% "mu-rpc-server" % sys.props("mu") -) diff --git a/plugin/src/sbt-test/sbt-mu-srcgen/compendium/project/plugins.sbt b/plugin/src/sbt-test/sbt-mu-srcgen/compendium/project/plugins.sbt deleted file mode 100644 index 2e452245..00000000 --- a/plugin/src/sbt-test/sbt-mu-srcgen/compendium/project/plugins.sbt +++ /dev/null @@ -1 +0,0 @@ -addSbtPlugin("io.higherkindness" %% "sbt-mu-srcgen" % sys.props("version")) diff --git a/plugin/src/sbt-test/sbt-mu-srcgen/compendium/test b/plugin/src/sbt-test/sbt-mu-srcgen/compendium/test deleted file mode 100644 index ecdf572c..00000000 --- a/plugin/src/sbt-test/sbt-mu-srcgen/compendium/test +++ /dev/null @@ -1,7 +0,0 @@ -> 'set muSrcGenExecutionMode := higherkindness.mu.rpc.srcgen.Model.ExecutionMode.Compendium' -> 'set muSrcGenIdlType := higherkindness.mu.rpc.srcgen.Model.IdlType.Proto' -> 'set muSrcGenCompendiumProtocolIdentifiers := Seq(higherkindness.mu.rpc.srcgen.compendium.ProtocolAndVersion.apply("shop",None))' -> 'set muSrcGenCompendiumServerUrl := "http://localhost:8080"' -# > compile -# $ exists target/scala-2.12/resource_managed/main/proto/shop.proto -