-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'series/0.18' into update-sbt
- Loading branch information
Showing
24 changed files
with
14,458 additions
and
1,084 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...src/sbt-test/codegen-plugin/multiple-artifacts-same-namespace/a/src/main/smithy/ns.smithy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace ns | ||
|
||
string Hello | ||
|
||
string GoodBye |
6 changes: 6 additions & 0 deletions
6
...src/sbt-test/codegen-plugin/multiple-artifacts-same-namespace/b/src/main/smithy/ns.smithy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace ns | ||
|
||
// no hello | ||
// string Hello | ||
// | ||
string GoodBye |
20 changes: 20 additions & 0 deletions
20
...es/codegen-plugin/src/sbt-test/codegen-plugin/multiple-artifacts-same-namespace/build.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ThisBuild / scalaVersion := "2.13.10" | ||
|
||
lazy val a = project | ||
.enablePlugins(Smithy4sCodegenPlugin) | ||
.settings( | ||
libraryDependencies += "com.disneystreaming.smithy4s" %% "smithy4s-core" % smithy4sVersion.value | ||
) | ||
lazy val b = project | ||
.enablePlugins(Smithy4sCodegenPlugin) | ||
.settings( | ||
libraryDependencies += "com.disneystreaming.smithy4s" %% "smithy4s-core" % smithy4sVersion.value | ||
) | ||
|
||
lazy val usage = project | ||
.enablePlugins(Smithy4sCodegenPlugin) | ||
.dependsOn(a, b) | ||
|
||
val root = project | ||
.in(file(".")) | ||
.aggregate(a, b, usage) |
1 change: 1 addition & 0 deletions
1
...in/src/sbt-test/codegen-plugin/multiple-artifacts-same-namespace/project/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.10.2 |
9 changes: 9 additions & 0 deletions
9
...-plugin/src/sbt-test/codegen-plugin/multiple-artifacts-same-namespace/project/plugins.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
sys.props.get("plugin.version") match { | ||
case Some(x) => | ||
addSbtPlugin("com.disneystreaming.smithy4s" % "smithy4s-sbt-codegen" % x) | ||
case _ => | ||
sys.error( | ||
"""|The system property 'plugin.version' is not defined. | ||
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin | ||
) | ||
} |
2 changes: 2 additions & 0 deletions
2
modules/codegen-plugin/src/sbt-test/codegen-plugin/multiple-artifacts-same-namespace/test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# smithy4s codegen should fail to compile; both a and b define the same namespace | ||
-> compile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
modules/codegen/test/src/smithy4s/codegen/internals/CodegenImplSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright 2021-2024 Disney Streaming | ||
* | ||
* Licensed under the Tomorrow Open Source Technology License, Version 1.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://disneystreaming.github.io/TOST-1.0.txt | ||
* | ||
* 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 smithy4s.codegen.internals | ||
|
||
import software.amazon.smithy.model.{Model, SourceLocation} | ||
import software.amazon.smithy.model.node.{ | ||
Node, | ||
ArrayNode, | ||
ObjectNode, | ||
StringNode | ||
} | ||
|
||
import scala.jdk.CollectionConverters._ | ||
|
||
final class CodegenImplSpec extends munit.FunSuite { | ||
|
||
test("namespace clash") { | ||
val aSmithy = | ||
"""namespace ns | ||
| | ||
|string Hello | ||
| | ||
|string GoodBye | ||
|""".stripMargin | ||
|
||
val bSmithy = | ||
"""namespace ns | ||
| | ||
|// no hello | ||
|// string Hello | ||
|// | ||
|string GoodBye | ||
|""".stripMargin | ||
|
||
val objectNodeMap = Map[StringNode, Node]( | ||
new StringNode( | ||
"namespaces", | ||
new SourceLocation("string node in test code") | ||
) -> new ArrayNode( | ||
List[Node]( | ||
new StringNode("ns", new SourceLocation("string node in test code")) | ||
).asJava, | ||
new SourceLocation("objectNodeMap in test code") | ||
) | ||
).asJava | ||
val repeatedNamespaceNode = new ObjectNode( | ||
objectNodeMap, | ||
new SourceLocation("repeatedNamespaceNode in test code") | ||
) | ||
val nodeList = | ||
List[Node](repeatedNamespaceNode, repeatedNamespaceNode).asJava | ||
val smithy4sMetadata = new ArrayNode( | ||
nodeList, | ||
new SourceLocation("smithy4sMetadata in test code") | ||
) | ||
|
||
val model = Model | ||
.assembler() | ||
.discoverModels() | ||
.addUnparsedModel("a.smithy", aSmithy) | ||
.addUnparsedModel("b.smithy", bSmithy) | ||
.putMetadata("smithy4sGenerated", smithy4sMetadata) | ||
.assemble() | ||
.unwrap() | ||
|
||
def generateScalaCode(model: Model): Map[String, String] = { | ||
CodegenImpl | ||
.generate(model, None, None) | ||
.map { case (_, result) => | ||
s"${result.namespace}.${result.name}" -> result.content | ||
} | ||
.toMap | ||
} | ||
|
||
val expectedDuplicates = Seq( | ||
( | ||
"ns", | ||
Seq( | ||
new SourceLocation("repeatedNamespaceNode in test code"), | ||
new SourceLocation("repeatedNamespaceNode in test code") | ||
) | ||
) | ||
) | ||
|
||
val caught: RepeatedNamespaceException = | ||
intercept[RepeatedNamespaceException] { | ||
generateScalaCode(model) | ||
} | ||
assertEquals(caught.duplicates, expectedDuplicates) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.