From 21bb43483025dd1d8f82c4554c011633740e00a4 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 12 Dec 2023 00:30:53 -0800 Subject: [PATCH 1/6] Bumping to guardrail 1.0.0-SNAPSHOT --- modules/core/build.sbt | 4 +- .../main/scala/AbstractCodegenPlugin.scala | 50 +++++++++---------- modules/core/src/main/scala/Keys.scala | 6 +-- modules/core/src/main/scala/Tasks.scala | 16 +++--- 4 files changed, 39 insertions(+), 37 deletions(-) diff --git a/modules/core/build.sbt b/modules/core/build.sbt index dd8578e..8518e95 100644 --- a/modules/core/build.sbt +++ b/modules/core/build.sbt @@ -7,7 +7,9 @@ description := "Core of sbt-guardrail plugin, for custom forks of guardrail" addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3") // Explicitly pinning this to a binding so we can grep for it -val guardrailCoreVersion = "0.75.3" +val guardrailCoreVersion = "1.0.0-SNAPSHOT" +resolvers += + "Sonatype OSS Snapshots" at "https://s01.oss.sonatype.org/content/repositories/snapshots" // Dependencies libraryDependencies ++= Seq( diff --git a/modules/core/src/main/scala/AbstractCodegenPlugin.scala b/modules/core/src/main/scala/AbstractCodegenPlugin.scala index 08f991c..1c71003 100644 --- a/modules/core/src/main/scala/AbstractCodegenPlugin.scala +++ b/modules/core/src/main/scala/AbstractCodegenPlugin.scala @@ -9,10 +9,12 @@ import dev.guardrail.{ Args => ArgsImpl, AuthImplementation, CodegenTarget => CodegenTargetImpl, - Context => ContextImpl + Context => ContextImpl, + TagsBehaviour } -trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin => +trait AbstractGuardrailPlugin { self: AutoPlugin => + val runner = new GuardrailRunner {} override def requires = JvmPlugin override def trigger = allRequirements @@ -29,7 +31,7 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin => encodeOptionalAs: Option[CodingConfig], decodeOptionalAs: Option[CodingConfig], customExtraction: Option[Boolean], - tagsBehaviour: Option[ContextImpl.TagsBehaviour], + tagsBehaviour: Option[TagsBehaviour], authImplementation: Option[AuthImplementation] ): ArgsImpl = { val propertyRequirement = (encodeOptionalAs, decodeOptionalAs) match { @@ -45,27 +47,25 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin => def kindaLens[A](member: Option[A])(proj: A => ContextImpl => ContextImpl): ContextImpl => ContextImpl = member.fold[ContextImpl => ContextImpl](identity _)(proj) val contextTransforms = Seq[ContextImpl => ContextImpl]( - kindaLens(authImplementation)(a => _.copy(authImplementation=a)), - kindaLens(customExtraction)(a => _.copy(customExtraction=a)), - kindaLens(tagsBehaviour)(a => _.copy(tagsBehaviour=a)), - kindaLens(tracing)(a => _.copy(tracing=a)) + kindaLens(authImplementation)(a => _.withAuthImplementation(a)), + kindaLens(customExtraction)(a => _.withCustomExtraction(a)), + kindaLens(tagsBehaviour)(a => _.withTagsBehaviour(a)), + kindaLens(tracing)(a => _.withTracing(a)) ) - ArgsImpl.empty.copy( - defaults=defaults, - kind=kind, - specPath=specPath.map(_.getPath), - packageName=packageName.map(_.split('.').toList), - dtoPackage=dtoPackage.toList.flatMap(_.split('.').filterNot(_.isEmpty).toList), - imports=imports, - context=contextTransforms.foldLeft( - ContextImpl.empty.copy( - framework=framework, - modules=modules, - propertyRequirement=propertyRequirement - ) - )({ case (acc, next) => next(acc) }) - ) + ArgsImpl.empty + .withDefaults(defaults) + .withKind(kind) + .withSpecPath(specPath.map(_.getPath)) + .withPackageName(packageName.map(_.split('.').toList)) + .withDtoPackage(dtoPackage.toList.flatMap(_.split('.').filterNot(_.isEmpty).toList)) + .withImports(imports) + .withContext(contextTransforms.foldLeft( + ContextImpl.empty + .withFramework(framework) + .withModules(modules) + .withPropertyRequirement(propertyRequirement) + )({ case (acc, next) => next(acc) })) } sealed trait ClientServer { @@ -83,7 +83,7 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin => encodeOptionalAs: Keys.GuardrailConfigValue[CodingConfig] = Keys.Default, decodeOptionalAs: Keys.GuardrailConfigValue[CodingConfig] = Keys.Default, customExtraction: Keys.GuardrailConfigValue[Boolean] = Keys.Default, - tagsBehaviour: Keys.GuardrailConfigValue[ContextImpl.TagsBehaviour] = Keys.Default, + tagsBehaviour: Keys.GuardrailConfigValue[TagsBehaviour] = Keys.Default, authImplementation: Keys.GuardrailConfigValue[AuthImplementation] = Keys.Default, ): Types.Args = (language, impl( kind = kind, @@ -112,7 +112,7 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin => encodeOptionalAs: Keys.GuardrailConfigValue[CodingConfig] = Keys.Default, decodeOptionalAs: Keys.GuardrailConfigValue[CodingConfig] = Keys.Default, customExtraction: Keys.GuardrailConfigValue[Boolean] = Keys.Default, - tagsBehaviour: Keys.GuardrailConfigValue[ContextImpl.TagsBehaviour] = Keys.Default, + tagsBehaviour: Keys.GuardrailConfigValue[TagsBehaviour] = Keys.Default, authImplementation: Keys.GuardrailConfigValue[AuthImplementation] = Keys.Default, // Deprecated parameters @@ -200,7 +200,7 @@ trait AbstractGuardrailPlugin extends GuardrailRunner { self: AutoPlugin => _ => GuardrailAnalysis( BuildInfo.version, - Tasks.guardrailTask(guardrailRunner)(tasks, sources.head) + Tasks.guardrailTask(runner.guardrailRunner)(tasks, sources.head) ).products } diff --git a/modules/core/src/main/scala/Keys.scala b/modules/core/src/main/scala/Keys.scala index 2e819bf..694dd01 100644 --- a/modules/core/src/main/scala/Keys.scala +++ b/modules/core/src/main/scala/Keys.scala @@ -6,7 +6,7 @@ import java.io.File import _root_.sbt.{ SettingKey, TaskKey } import scala.language.implicitConversions -import dev.guardrail.{AuthImplementation, Context} +import dev.guardrail.{AuthImplementation, Context, TagsBehaviour} import dev.guardrail.terms.protocol.PropertyRequirement sealed trait CodingConfig { @@ -44,8 +44,8 @@ object Keys { def codingOptional: CodingConfig = CodingConfig.Optional def codingOptionalLegacy: CodingConfig = CodingConfig.OptionalLegacy - def tagsAreIgnored: Context.TagsBehaviour = Context.TagsAreIgnored - def tagsAsPackage: Context.TagsBehaviour = Context.PackageFromTags + def tagsAreIgnored: TagsBehaviour = TagsBehaviour.TagsAreIgnored + def tagsAsPackage: TagsBehaviour = TagsBehaviour.PackageFromTags def authImplementationDisable: AuthImplementation = AuthImplementation.Disable def authImplementationNative: AuthImplementation = AuthImplementation.Native diff --git a/modules/core/src/main/scala/Tasks.scala b/modules/core/src/main/scala/Tasks.scala index a0d7a0a..b5883ae 100644 --- a/modules/core/src/main/scala/Tasks.scala +++ b/modules/core/src/main/scala/Tasks.scala @@ -2,7 +2,6 @@ package dev.guardrail package sbt import _root_.sbt.{FeedbackProvidedException, WatchSource} -import cats.data.NonEmptyList import cats.implicits._ import cats.~> import dev.guardrail.{Args => ArgsImpl} @@ -15,7 +14,7 @@ class CodegenFailedException extends FeedbackProvidedException object Tasks { def guardrailTask( - runner: Map[String,NonEmptyList[ArgsImpl]] => Target[List[Path]] + runner: (String, Array[ArgsImpl]) => Target[List[Path]] )(tasks: List[Types.Args], sourceDir: File): Set[File] = { // swagger-parser uses SPI to find extensions on the classpath (by default, only the OAPI2 -> OAPI3 converter) // See https://github.com/swagger-api/swagger-parser#extensions @@ -28,14 +27,15 @@ object Tasks { Thread.currentThread().setContextClassLoader(classOf[SwaggerParserExtension].getClassLoader) try { - val preppedTasks: Map[String, NonEmptyList[ArgsImpl]] = tasks.foldLeft(Map.empty[String, NonEmptyList[ArgsImpl]]) { case (acc, (language, args)) => - val prepped = args.copy(outputPath=Some(sourceDir.getPath)) - acc.updated(language, acc.get(language).fold(NonEmptyList.one(prepped))(_ :+ prepped)) + val preppedTasks: List[(String, Array[ArgsImpl])] = { + tasks.foldLeft(Map.empty[String, List[ArgsImpl]])({ case (acc, (language, args)) => + val prepped = args.withOutputPath(Some(sourceDir.getPath)) + acc.updated(language, (acc.get(language).getOrElse(List.empty[ArgsImpl]) :+ prepped)) + }).mapValues(_.toList.toArray).toList } val /*(logger,*/ paths/*)*/ = - runner - .apply(preppedTasks) + preppedTasks.toList.traverse(runner.tupled) .fold[List[java.nio.file.Path]]({ case MissingArg(args, Error.ArgName(arg)) => println(s"${AnsiColor.RED}Missing argument:${AnsiColor.RESET} ${AnsiColor.BOLD}${arg}${AnsiColor.RESET} (In block ${args})") @@ -83,7 +83,7 @@ object Tasks { case UnusedModules(unused) => println(s"${AnsiColor.RED}Unused modules specified:${AnsiColor.RESET} ${unused.toList.mkString(", ")}") throw new CodegenFailedException() - }, identity) + }, _.flatten.distinct) //.runEmpty paths.map(_.toFile).toSet From e2d30349777aca85f8dd408ba8a91e530b569b62 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Wed, 13 Dec 2023 21:10:29 -0800 Subject: [PATCH 2/6] Remove publishLegacy --- build.sbt | 2 -- modules/core/src/main/scala/AbstractCodegenPlugin.scala | 4 ---- 2 files changed, 6 deletions(-) diff --git a/build.sbt b/build.sbt index 4104038..64368dd 100644 --- a/build.sbt +++ b/build.sbt @@ -71,5 +71,3 @@ lazy val root = (project in file(".")) lazy val core = (project in file("modules/core")) .settings(commonSettings) - -addCommandAlias("publishLegacy", "set ThisBuild / organization := \"com.twilio\"; set publishTo := sonatypePublishToBundle.value; publishSigned") diff --git a/modules/core/src/main/scala/AbstractCodegenPlugin.scala b/modules/core/src/main/scala/AbstractCodegenPlugin.scala index 1c71003..bbf4a1a 100644 --- a/modules/core/src/main/scala/AbstractCodegenPlugin.scala +++ b/modules/core/src/main/scala/AbstractCodegenPlugin.scala @@ -188,10 +188,6 @@ trait AbstractGuardrailPlugin { self: AutoPlugin => } private def cachedGuardrailTask(projectName: String, scope: String, scalaBinaryVersion: String)(kind: String, streams: _root_.sbt.Keys.TaskStreams)(tasks: List[(String, Args)], sources: Seq[java.io.File]) = { - if (BuildInfo.organization == "com.twilio" && tasks.nonEmpty) { - streams.log.warn(s"""${projectName} / ${scope}: sbt-guardrail has changed organizations! Please change "com.twilio" to "dev.guardrail" to continue receiving updates""") - } - val inputFiles = tasks.flatMap(_._2.specPath).map(file(_)).toSet val cacheDir = streams.cacheDirectory / "guardrail" / scalaBinaryVersion / kind From 0875ba9b372f71a3df5379c6b7d69b476fb1f05a Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Sat, 23 Dec 2023 14:11:22 -0800 Subject: [PATCH 3/6] Correctly prefix "MissingDependency" messages --- modules/core/src/main/scala/Tasks.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/main/scala/Tasks.scala b/modules/core/src/main/scala/Tasks.scala index b5883ae..9c7d2cb 100644 --- a/modules/core/src/main/scala/Tasks.scala +++ b/modules/core/src/main/scala/Tasks.scala @@ -41,7 +41,7 @@ object Tasks { println(s"${AnsiColor.RED}Missing argument:${AnsiColor.RESET} ${AnsiColor.BOLD}${arg}${AnsiColor.RESET} (In block ${args})") throw new CodegenFailedException() case MissingDependency(name) => - println(s"""${AnsiColor.RED}Missing dependency:${AnsiColor.RESET} ${AnsiColor.BOLD}libraryDependencies += "dev.guardrail" %% "${name}" % ""${AnsiColor.RESET}""") + println(s"""${AnsiColor.RED}Missing dependency:${AnsiColor.RESET} ${AnsiColor.BOLD}libraryDependencies += "dev.guardrail" %% "guardrail-${name}" % ""${AnsiColor.RESET}""") throw new CodegenFailedException() case NoArgsSpecified => List.empty From d7e8e8a6f7fe81eef96412471ae75fa76a471ea9 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 26 Dec 2023 14:35:37 -0800 Subject: [PATCH 4/6] First milestone release --- modules/core/build.sbt | 2 +- .../java-codegen-app/project/plugins.sbt | 6 ++--- .../project/plugins.sbt | 4 ++-- .../guardrail/sbt/ContextParameterSpec.scala | 24 +++++++++++-------- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/modules/core/build.sbt b/modules/core/build.sbt index 8518e95..2ca5818 100644 --- a/modules/core/build.sbt +++ b/modules/core/build.sbt @@ -7,7 +7,7 @@ description := "Core of sbt-guardrail plugin, for custom forks of guardrail" addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3") // Explicitly pinning this to a binding so we can grep for it -val guardrailCoreVersion = "1.0.0-SNAPSHOT" +val guardrailCoreVersion = "1.0.0-M1" resolvers += "Sonatype OSS Snapshots" at "https://s01.oss.sonatype.org/content/repositories/snapshots" diff --git a/src/sbt-test/sbt-guardrail/java-codegen-app/project/plugins.sbt b/src/sbt-test/sbt-guardrail/java-codegen-app/project/plugins.sbt index 1a5276a..d3e43d9 100644 --- a/src/sbt-test/sbt-guardrail/java-codegen-app/project/plugins.sbt +++ b/src/sbt-test/sbt-guardrail/java-codegen-app/project/plugins.sbt @@ -6,6 +6,6 @@ else addSbtPlugin("dev.guardrail" % "sbt-guardrail" % pluginVersion) } -libraryDependencies += "dev.guardrail" %% "guardrail-java-support" % "0.73.1" -libraryDependencies += "dev.guardrail" %% "guardrail-java-async-http" % "0.72.0" -libraryDependencies += "dev.guardrail" %% "guardrail-java-dropwizard" % "0.72.0" +libraryDependencies += "dev.guardrail" %% "guardrail-java-support" % "1.0.0-M1" +libraryDependencies += "dev.guardrail" %% "guardrail-java-async-http" % "1.0.0-M1" +libraryDependencies += "dev.guardrail" %% "guardrail-java-dropwizard" % "1.0.0-M1" diff --git a/src/sbt-test/sbt-guardrail/scala-client-codegen-app/project/plugins.sbt b/src/sbt-test/sbt-guardrail/scala-client-codegen-app/project/plugins.sbt index 6858dff..83a2030 100644 --- a/src/sbt-test/sbt-guardrail/scala-client-codegen-app/project/plugins.sbt +++ b/src/sbt-test/sbt-guardrail/scala-client-codegen-app/project/plugins.sbt @@ -6,5 +6,5 @@ else addSbtPlugin("dev.guardrail" % "sbt-guardrail" % pluginVersion) } -libraryDependencies += "dev.guardrail" %% "guardrail-scala-support" % "0.75.3" -libraryDependencies += "dev.guardrail" %% "guardrail-scala-akka-http" % "0.76.0" +libraryDependencies += "dev.guardrail" %% "guardrail-scala-support" % "1.0.0-M1" +libraryDependencies += "dev.guardrail" %% "guardrail-scala-akka-http" % "1.0.0-M1" diff --git a/src/test/scala/dev/guardrail/sbt/ContextParameterSpec.scala b/src/test/scala/dev/guardrail/sbt/ContextParameterSpec.scala index bf1260c..fba3936 100644 --- a/src/test/scala/dev/guardrail/sbt/ContextParameterSpec.scala +++ b/src/test/scala/dev/guardrail/sbt/ContextParameterSpec.scala @@ -1,6 +1,6 @@ package dev.guardrail.sbt -import dev.guardrail.Context +import dev.guardrail.{ AuthImplementation, Context, TagsBehaviour } import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.should.Matchers @@ -8,14 +8,18 @@ import org.scalatest.matchers.should.Matchers class EscapeTreeSpec extends AnyFunSuite with Matchers { test("Ensure that all Context fields are accounted for") { - val Context( - framework, - customExtraction, - tracing, - modules, - propertyRequirement, - tagsBehaviour, - authImplementation - ) = Context.empty + val built = Context( + None, + customExtraction = false, + tracing = false, + modules = List.empty, + propertyRequirement = dev.guardrail.terms.protocol.PropertyRequirement.Configured( + dev.guardrail.terms.protocol.PropertyRequirement.OptionalLegacy, + dev.guardrail.terms.protocol.PropertyRequirement.OptionalLegacy + ), + tagsBehaviour = TagsBehaviour.TagsAreIgnored, + authImplementation = AuthImplementation.Disable + ) + built.toString() shouldBe (Context.empty.toString()) } } From e643a987ade71a5c53ee0cd79d0f7113ea2db756 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 26 Dec 2023 15:02:18 -0800 Subject: [PATCH 5/6] Versioning plugin in core as well --- modules/core/build.sbt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/core/build.sbt b/modules/core/build.sbt index 2ca5818..e6453f8 100644 --- a/modules/core/build.sbt +++ b/modules/core/build.sbt @@ -17,5 +17,18 @@ libraryDependencies ++= Seq( "org.snakeyaml" % "snakeyaml-engine" % "2.7" ) +// Versioning +enablePlugins(GitBranchPrompt) +enablePlugins(GitVersioning) +git.useGitDescribe := true + +git.gitDescribedVersion := git.gitDescribedVersion(v => { + import scala.sys.process._ + val nativeGitDescribeResult = ("git describe --tags --always HEAD" !!).trim + git.defaultTagByVersionStrategy(nativeGitDescribeResult) +}).value + +git.gitUncommittedChanges := git.gitCurrentTags.value.isEmpty + buildInfoKeys := Seq[BuildInfoKey](organization, version) buildInfoPackage := "dev.guardrail.sbt" From c51e47975eaca912fb335feeb9230d4c0c5fbc28 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 26 Dec 2023 15:14:54 -0800 Subject: [PATCH 6/6] Remove JDK8 support --- .github/workflows/ci.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c36cd1d..b50ae04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,17 +10,15 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [ '8', '11', '17' ] + java: [ '1.14', '1.17' ] scala: [ '2.12.18' ] steps: - uses: actions/checkout@v2 with: fetch-depth: 0 - - name: Set up JDK - uses: actions/setup-java@v3.4.1 + - uses: olafurpg/setup-scala@v14 with: - distribution: 'temurin' - java-version: ${{ matrix.java }} + java-version: zulu@${{ matrix.java }} - name: print Java version run: java -version - name: Coursier cache