diff --git a/codegen/core/src/main/scala/com/lightbend/akkasls/codegen/Packaging.scala b/codegen/core/src/main/scala/com/lightbend/akkasls/codegen/Packaging.scala index ed5adb5d53..71b985c330 100644 --- a/codegen/core/src/main/scala/com/lightbend/akkasls/codegen/Packaging.scala +++ b/codegen/core/src/main/scala/com/lightbend/akkasls/codegen/Packaging.scala @@ -48,17 +48,14 @@ object FullyQualifiedName { } -/** - * The details of a package's naming, sufficient to construct fully qualified names in any target language - */ case class PackageNaming( protoFileName: String, name: String, - pkg: String, + protoPackage: String, javaPackageOption: Option[String], javaOuterClassnameOption: Option[String], javaMultipleFiles: Boolean) { - lazy val javaPackage: String = javaPackageOption.getOrElse(pkg) + lazy val javaPackage: String = javaPackageOption.getOrElse(protoPackage) def scalaPackage: String = javaPackage def javaOuterClassname: String = javaOuterClassnameOption.getOrElse(name) } diff --git a/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/ModelBuilderSuite.scala b/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/ModelBuilderSuite.scala index 15c4201d02..2c6e96b25f 100644 --- a/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/ModelBuilderSuite.scala +++ b/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/ModelBuilderSuite.scala @@ -170,7 +170,7 @@ class ModelBuilderSuite extends munit.FunSuite { Some("EmptyProto"), javaMultipleFiles = true) val entity = ModelBuilder.ValueEntity( - domainProto.pkg + "." + "ShoppingCart", + domainProto.protoPackage + "." + "ShoppingCart", FullyQualifiedName("ShoppingCart", domainProto), "shopping-cart", ModelBuilder.State(FullyQualifiedName("Cart", domainProto))) @@ -330,7 +330,7 @@ class ModelBuilderSuite extends munit.FunSuite { Some("EmptyProto"), javaMultipleFiles = true) val entity = ModelBuilder.ValueEntity( - domainProto.pkg + "." + "ShoppingCart", + domainProto.protoPackage + "." + "ShoppingCart", FullyQualifiedName("ShoppingCart", domainProto), "shopping-cart", ModelBuilder.State(FullyQualifiedName("Cart", domainProto))) diff --git a/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/TestData.scala b/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/TestData.scala index 016d96622b..700191bb88 100644 --- a/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/TestData.scala +++ b/codegen/core/src/test/scala/com/lightbend/akkasls/codegen/TestData.scala @@ -167,7 +167,7 @@ class TestData(packageNamingTemplate: PackageNaming) { valueEntity(domainProto(suffix), suffix) def valueEntity(parent: PackageNaming, suffix: String = ""): ModelBuilder.ValueEntity = ModelBuilder.ValueEntity( - parent.pkg + s"MyValueEntity$suffix", + parent.protoPackage + s".MyValueEntity$suffix", FullyQualifiedName(s"MyValueEntity$suffix", parent), s"MyValueEntity$suffix", ModelBuilder.State(FullyQualifiedName("MyState", parent))) diff --git a/codegen/java-gen/src/main/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntityTestKitGenerator.scala b/codegen/java-gen/src/main/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntityTestKitGenerator.scala index f54d811336..7f7afef27f 100644 --- a/codegen/java-gen/src/main/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntityTestKitGenerator.scala +++ b/codegen/java-gen/src/main/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntityTestKitGenerator.scala @@ -42,7 +42,7 @@ object EventSourcedEntityTestKitGenerator { val testFilePath = testSourceDirectory.resolve(packagePath.resolve(className + "Test.java")) if (!testFilePath.toFile.exists()) { testFilePath.getParent.toFile.mkdirs() - Files.write(testFilePath, generateTestSources(service, entity, packageName).getBytes(Charsets.UTF_8)) + Files.write(testFilePath, generateTestSources(service, entity).getBytes(Charsets.UTF_8)) generatedFiles :+= testFilePath } @@ -79,7 +79,7 @@ object EventSourcedEntityTestKitGenerator { val testkitClassName = s"${entityClassName}TestKit" s"""$managedComment - |package ${entity.fqn.parent.pkg}; + |package ${entity.fqn.parent.javaPackage}; | |$imports | @@ -198,10 +198,8 @@ object EventSourcedEntityTestKitGenerator { top + middle.mkString("\n") + bottom } - def generateTestSources( - service: ModelBuilder.EntityService, - entity: ModelBuilder.EventSourcedEntity, - packageName: String): String = { + def generateTestSources(service: ModelBuilder.EntityService, entity: ModelBuilder.EventSourcedEntity): String = { + val packageName = entity.fqn.parent.javaPackage val imports = generateCommandImports( service.commands, entity.state, @@ -231,7 +229,7 @@ object EventSourcedEntityTestKitGenerator { } s"""$unmanagedComment - |package ${entity.fqn.parent.pkg}; + |package $packageName; | |$imports | diff --git a/codegen/java-gen/src/main/scala/com/lightbend/akkasls/codegen/java/ValueEntityTestKitGenerator.scala b/codegen/java-gen/src/main/scala/com/lightbend/akkasls/codegen/java/ValueEntityTestKitGenerator.scala index 0cc4f52856..e220b02fa7 100644 --- a/codegen/java-gen/src/main/scala/com/lightbend/akkasls/codegen/java/ValueEntityTestKitGenerator.scala +++ b/codegen/java-gen/src/main/scala/com/lightbend/akkasls/codegen/java/ValueEntityTestKitGenerator.scala @@ -83,7 +83,7 @@ object ValueEntityTestKitGenerator { val testkitClassName = s"${entityClassName}TestKit" s"""$managedComment - |package ${entity.fqn.parent.pkg}; + |package ${entity.fqn.parent.javaPackage}; | |$imports | @@ -197,7 +197,7 @@ object ValueEntityTestKitGenerator { } s"""$unmanagedComment - |package ${entity.fqn.parent.pkg}; + |package ${entity.fqn.parent.javaPackage}; | |$imports | diff --git a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntityTestKitGeneratorSuite.scala b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntityTestKitGeneratorSuite.scala index a60623c058..7302365090 100644 --- a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntityTestKitGeneratorSuite.scala +++ b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/EventSourcedEntityTestKitGeneratorSuite.scala @@ -148,11 +148,10 @@ class EventSourcedEntityTestKitGeneratorSuite extends munit.FunSuite { test("it can generate an specific Test stub for the entity") { - val packageName = "com.example.shoppingcart" val entity = generateShoppingCartEntity val service = generateShoppingCartService(entity) - val sourceCode = EventSourcedEntityTestKitGenerator.generateTestSources(service, entity, packageName) + val sourceCode = EventSourcedEntityTestKitGenerator.generateTestSources(service, entity) val expected = """/* This code was generated by Akka Serverless tooling. @@ -164,7 +163,7 @@ class EventSourcedEntityTestKitGeneratorSuite extends munit.FunSuite { |import com.akkaserverless.javasdk.eventsourcedentity.EventSourcedEntity; |import com.akkaserverless.javasdk.eventsourcedentity.EventSourcedEntityContext; |import com.akkaserverless.javasdk.testkit.EventSourcedResult; - |import com.example.shoppingcart.domain.ShoppingCartDomain; + |import com.example.shoppingcart.ShoppingCartApi; |import com.google.protobuf.Empty; |import java.util.ArrayList; |import java.util.List; diff --git a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/MainSourceGeneratorSuite.scala b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/MainSourceGeneratorSuite.scala index c18e79da58..0da8dabaf5 100644 --- a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/MainSourceGeneratorSuite.scala +++ b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/MainSourceGeneratorSuite.scala @@ -83,8 +83,8 @@ class MainSourceGeneratorSuite extends munit.FunSuite { test("generated component registration source") { val service1Proto = testData.serviceProto("1") val service2Proto = testData.serviceProto("2") - val service3Proto = testData.serviceProto("3").copy(pkg = "com.example.service.something") - val service4Proto = testData.serviceProto("4").copy(pkg = "com.example.service.view") + val service3Proto = testData.serviceProto("3").copy(protoPackage = "com.example.service.something") + val service4Proto = testData.serviceProto("4").copy(protoPackage = "com.example.service.view") val service5Proto = testData.serviceProto("5") val service6Proto = testData.serviceProto("6") @@ -167,7 +167,7 @@ class MainSourceGeneratorSuite extends munit.FunSuite { } test("generated component registration source for a view without update handlers") { - val serviceProto = testData.serviceProto().copy(pkg = "com.example.service.view") + val serviceProto = testData.serviceProto().copy(protoPackage = "com.example.service.view") val services = Map("com.example.Service" -> testData.simpleViewService(serviceProto).copy(transformedUpdates = Nil)) diff --git a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/SourceGeneratorSuite.scala b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/SourceGeneratorSuite.scala index dc97b5a1b5..d16c8b4598 100644 --- a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/SourceGeneratorSuite.scala +++ b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/SourceGeneratorSuite.scala @@ -80,7 +80,7 @@ class SourceGeneratorSuite extends munit.FunSuite { val service1Proto = testData.serviceProto("1") val service2Proto = testData.serviceProto("2") val service3Proto = - testData.serviceProto("3").copy(pkg = "com.example.service.something") + testData.serviceProto("3").copy(protoPackage = "com.example.service.something") val service4Proto = testData.serviceProto("4") val service5Proto = testData.serviceProto("5") val service6Proto = testData.serviceProto("6") diff --git a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ValueEntityTestKitGeneratorSuite.scala b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ValueEntityTestKitGeneratorSuite.scala index d5a1c1a4b3..15ac2fee67 100644 --- a/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ValueEntityTestKitGeneratorSuite.scala +++ b/codegen/java-gen/src/test/scala/com/lightbend/akkasls/codegen/java/ValueEntityTestKitGeneratorSuite.scala @@ -212,7 +212,7 @@ class ValueEntityTestKitGeneratorSuite extends munit.FunSuite { javaMultipleFiles = false) ModelBuilder.ValueEntity( - domainProto.pkg + ".ShoppingCart", + domainProto.protoPackage + ".ShoppingCart", FullyQualifiedName("ShoppingCart", domainProto), "eventsourced-shopping-cart", ModelBuilder.State(FullyQualifiedName("Cart", domainProto))) diff --git a/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/MainSourceGeneratorSuite.scala b/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/MainSourceGeneratorSuite.scala index 2bd5421fab..b66de3d29b 100644 --- a/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/MainSourceGeneratorSuite.scala +++ b/codegen/scala-gen/src/test/scala/com/akkaserverless/codegen/scalasdk/MainSourceGeneratorSuite.scala @@ -78,8 +78,8 @@ class MainSourceGeneratorSuite extends munit.FunSuite { test("generated component registration source") { val service1Proto = testData.serviceProto("1") val service2Proto = testData.serviceProto("2") - val service3Proto = testData.serviceProto("3").copy(pkg = "com.example.service.something") - val service4Proto = testData.serviceProto("4").copy(pkg = "com.example.service.view") + val service3Proto = testData.serviceProto("3").copy(protoPackage = "com.example.service.something") + val service4Proto = testData.serviceProto("4").copy(protoPackage = "com.example.service.view") val service5Proto = testData.serviceProto("5") val service6Proto = testData.serviceProto("6") @@ -147,7 +147,7 @@ class MainSourceGeneratorSuite extends munit.FunSuite { } test("generated component registration source for a view without update handlers") { - val serviceProto = testData.serviceProto().copy(pkg = "com.example.service.view") + val serviceProto = testData.serviceProto().copy(protoPackage = "com.example.service.view") val services = Map("com.example.Service" -> testData.simpleViewService(serviceProto).copy(transformedUpdates = Nil))