Skip to content

Commit

Permalink
Merge pull request #136 from daddykotex/dfrancoeur/config
Browse files Browse the repository at this point in the history
Add a smithy4s config to import codegen dependencies
  • Loading branch information
Baccata authored Mar 11, 2022
2 parents d93982e + 1511310 commit ce45b6a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ lazy val root = (project in file("."))
scalaVersion := "2.13.6",
smithy4sInputDir in Compile := (baseDirectory in ThisBuild).value / "smithy_input",
smithy4sOutputDir in Compile := (baseDirectory in ThisBuild).value / "smithy_output",
smithy4sCodegenDependencies in Compile := List(
"software.amazon.smithy:smithy-aws-iam-traits:1.14.1"
),
Compile / smithy4sAllowedNamespaces := List(
"aws.iam",
"smithy4s.example"
),
libraryDependencies += "com.disneystreaming.smithy4s" %% "smithy4s-core" % smithy4sVersion.value
libraryDependencies += "com.disneystreaming.smithy4s" %% "smithy4s-core" % smithy4sVersion.value,
libraryDependencies += "software.amazon.smithy" % "smithy-aws-iam-traits" % "1.14.1" % "smithy4s"
)
19 changes: 16 additions & 3 deletions modules/codegen-plugin/src/smithy4s/codegen/CodegenPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ object Smithy4sCodegenPlugin extends AutoPlugin {
"Allow-list of namespaces that should be processed by the generator. If unset, considers all namespaces but stdlib ones"
)

@deprecated("2022-03-01", """use `libraryDependencies += "org.acme" % "artifact" % "version" % Smithy4s`""")
val smithy4sCodegenDependencies =
settingKey[List[String]](
"List of dependencies containing smithy files to include in codegen task"
)

val Smithy4s = config("smithy4s").describedAs("Dependencies for Smithy code.")

val smithy4sModelTransformers =
settingKey[List[String]](
"List of transformer names that should be applied to the model prior to codegen"
Expand All @@ -64,13 +67,15 @@ object Smithy4sCodegenPlugin extends AutoPlugin {
smithy4sVersion := BuildInfo.version
)

override def projectConfigurations: Seq[Configuration] = Seq(Smithy4s)

override lazy val projectSettings =
Seq(
Compile / smithy4sInputDir := (Compile / sourceDirectory).value / "smithy",
Compile / smithy4sOutputDir := (Compile / sourceManaged).value,
Compile / smithy4sOpenapiDir := (Compile / resourceManaged).value,
Compile / smithy4sCodegen := cachedSmithyCodegen(Compile).value,
Compile / smithy4sCodegenDependencies := List.empty,
Compile / smithy4sCodegenDependencies := List.empty: @annotation.nowarn,
Compile / sourceGenerators += (Compile / smithy4sCodegen).map(
_.filter(_.ext == "scala")
),
Expand All @@ -89,15 +94,23 @@ object Smithy4sCodegenPlugin extends AutoPlugin {
List[String]
)

private def prepareSmithy4sDeps(deps: Seq[ModuleID]): List[String] =
deps
.filter { _.configurations.contains(Smithy4s.name) }
.map { m =>
if (CrossVersion.disabled == m.crossVersion) s"${m.organization}:${m.name}:${m.revision}"
else s"${m.organization}::${m.name}:${m.revision}"
}
.toList

def cachedSmithyCodegen(conf: Configuration) = Def.task {
val inputFiles =
Option((conf / smithy4sInputDir).value.listFiles()).getOrElse(Array.empty)
val outputPath = (conf / smithy4sOutputDir).value.getAbsolutePath()
val openApiOutputPath = (conf / smithy4sOpenapiDir).value.getAbsolutePath()
val allowedNamespaces =
(conf / smithy4sAllowedNamespaces).?.value.map(_.toSet)
val dependencies =
(conf / smithy4sCodegenDependencies).value
val dependencies = prepareSmithy4sDeps(libraryDependencies.value)
val res =
(conf / resolvers).value.toList.collect { case m: MavenRepository =>
m.root
Expand Down

0 comments on commit ce45b6a

Please sign in to comment.