Skip to content

Commit 85b1748

Browse files
authored
Update smithy, remove hack (#5)
* Update smithy, remove hack * rename test * document
1 parent 9ab89a9 commit 85b1748

File tree

8 files changed

+10
-57
lines changed

8 files changed

+10
-57
lines changed

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ lazy val sbtPlugin = project
3838
commonSettings,
3939
scalaVersion := "2.12.20",
4040
libraryDependencies ++= Seq(
41-
"software.amazon.smithy" % "smithy-trait-codegen" % "1.60.2",
42-
"software.amazon.smithy" % "smithy-model" % "1.60.2",
41+
"software.amazon.smithy" % "smithy-trait-codegen" % "1.61.0",
42+
"software.amazon.smithy" % "smithy-model" % "1.61.0",
4343
) ++ Seq(
4444
"com.lihaoyi" %% "os-lib" % "0.10.7"
4545
),

sbtPlugin/src/main/scala/org/polyvariant/smithytraitcodegen/SmithyTraitCodegen.scala

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,6 @@ object SmithyTraitCodegen {
8888

8989
}
9090

91-
// Hack / workaround for https://github.com/smithy-lang/smithy/pull/2671
92-
private def namespaceHackRequired(ns: String) =
93-
ns.startsWith("smithy") && ns != "smithy" && !ns.startsWith("smithy.")
94-
95-
private def renameNamespaceForHack(ns: String) =
96-
if (namespaceHackRequired(ns))
97-
"hack" + ns
98-
else
99-
ns
100-
101-
private def replaceNamespaceRefsInFile(fileText: String, ns: String) =
102-
if (namespaceHackRequired(ns)) {
103-
fileText.replaceAll(s"hack$ns", ns)
104-
} else {
105-
fileText
106-
}
107-
10891
def generate(args: Args): Output = {
10992
val outputDir = args.targetDir / "smithy-trait-generator-output"
11093
val genDir = outputDir / "java"
@@ -114,37 +97,13 @@ object SmithyTraitCodegen {
11497

11598
val manifest = FileManifest.create(genDir.toNIO)
11699

117-
val model =
118-
args
119-
.dependencies
120-
.foldLeft(Model.assembler().addImport(args.smithySourcesDir.path.toNIO)) {
121-
case (acc, dep) => acc.addImport(dep.path.toNIO)
122-
}
123-
.assemble()
124-
.unwrap() match {
125-
case model =>
126-
if (namespaceHackRequired(args.smithyNamespace)) {
127-
println("Applying namespace workaround - `hack` prefix will be used")
128-
129-
val renames =
130-
model
131-
.shapes()
132-
.collect(Collectors.toList())
133-
.asScala
134-
.filter(_.getId().getNamespace() == args.smithyNamespace)
135-
.map { shp =>
136-
shp.getId() ->
137-
shp.getId().withNamespace(renameNamespaceForHack(shp.getId().getNamespace()))
138-
}
139-
.toMap
140-
.asJava
141-
142-
ModelTransformer
143-
.create()
144-
.renameShapes(model, renames)
145-
} else
146-
model
100+
val model = args
101+
.dependencies
102+
.foldLeft(Model.assembler().addImport(args.smithySourcesDir.path.toNIO)) { case (acc, dep) =>
103+
acc.addImport(dep.path.toNIO)
147104
}
105+
.assemble()
106+
.unwrap()
148107

149108
val context = PluginContext
150109
.builder()
@@ -155,7 +114,7 @@ object SmithyTraitCodegen {
155114
ObjectNode
156115
.builder()
157116
.withMember("package", args.javaPackage)
158-
.withMember("namespace", renameNamespaceForHack(args.smithyNamespace))
117+
.withMember("namespace", args.smithyNamespace)
159118
.withMember("header", ArrayNode.builder.build())
160119
.withMember("excludeTags", ArrayNode.builder.withValue("nocodegen").build())
161120
.build()
@@ -168,13 +127,6 @@ object SmithyTraitCodegen {
168127
if (os.exists(genDir / "META-INF"))
169128
os.move(genDir / "META-INF", metaDir / "META-INF")
170129

171-
os.walk(genDir)
172-
.filter(os.isFile)
173-
.filter(_.ext == "java")
174-
.foreach { f =>
175-
os.write.over(f, replaceNamespaceRefsInFile(os.read(f), args.smithyNamespace))
176-
}
177-
178130
os
179131
.walk(metaDir, includeTarget = true)
180132
.filter(os.isFile)

sbtPlugin/src/sbt-test/codegen/namespace-restriction-hack/build.sbt renamed to sbtPlugin/src/sbt-test/codegen/namespace-restriction/build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ val traits = project
44
smithyTraitCodegenDependencies := List(
55
"io.github.disneystreaming.alloy" % "alloy-core" % "0.3.23"
66
),
7+
// Prior to smithy 1.61.0, namespaces starting with "smithy" were forbidden and required a workaround
78
smithyTraitCodegenJavaPackage := "smithy4bazinga",
89
smithyTraitCodegenNamespace := "smithy4bazinga",
910
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)