Skip to content

Commit c46c6ee

Browse files
committed
Split 'compile' and 'test' configurations
1 parent a6affe5 commit c46c6ee

10 files changed

Lines changed: 194 additions & 23 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ jobs:
134134
- restore_deps_cache
135135
- run:
136136
name: Run tests
137-
command: sbt test akkaserverless-codegen-scala/publishLocal scripted
137+
command: sbt test codegenCore/publishLocal akkaserverless-codegen-scala/publishLocal scripted
138138
- save_deps_cache
139139

140140
integration-tests:

codegen/scala-gen/src/main/scala/com/akkaserverless/codegen/scalasdk/AkkaserverlessGenerator.scala

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,17 @@ object AkkaserverlessGenerator extends CodeGenApp {
3232

3333
override def process(request: CodeGenRequest): CodeGenResponse = {
3434
val debugEnabled = request.parameter.contains(enableDebug)
35-
val model = ModelBuilder.introspectProtobufClasses(request.filesToGenerate)(new Log {
36-
override def debug(message: String): Unit =
37-
if (debugEnabled) println(s"[DEBUG] $message")
38-
override def info(message: String): Unit =
39-
if (debugEnabled) println(s"[INFO] $message")
40-
override def warning(message: String): Unit =
41-
throw new IllegalStateException(message)
42-
override def error(message: String): Unit =
43-
throw new IllegalStateException(message)
44-
})
35+
val model = ModelBuilder.introspectProtobufClasses(request.filesToGenerate)(FatalWarningsLog(debugEnabled))
4536
try {
4637
CodeGenResponse.succeed(
47-
Seq(
48-
CodeGeneratorResponse.File
49-
.newBuilder()
50-
.setName("foo/bar/Baz.scala")
51-
.setContent("package foo.bar\n\ntrait Baz")
52-
.build()))
38+
SourceGenerator
39+
.generateManaged(model)
40+
.map(file =>
41+
CodeGeneratorResponse.File
42+
.newBuilder()
43+
.setName(file.name)
44+
.setContent(file.content)
45+
.build()))
5346
} catch {
5447
case t: Throwable =>
5548
t.printStackTrace()
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2021 Lightbend Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.akkaserverless.codegen.scalasdk
18+
19+
import com.google.protobuf.ExtensionRegistry
20+
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse
21+
import com.lightbend.akkasls.codegen.ModelBuilder
22+
import protocbridge.Artifact
23+
import protocgen.{ CodeGenApp, CodeGenRequest, CodeGenResponse }
24+
25+
object AkkaserverlessTestGenerator extends CodeGenApp {
26+
val enableDebug = "enableDebug"
27+
28+
override def registerExtensions(registry: ExtensionRegistry): Unit = {
29+
registry.add(com.akkaserverless.Annotations.service)
30+
registry.add(com.akkaserverless.Annotations.file)
31+
}
32+
33+
override def process(request: CodeGenRequest): CodeGenResponse = {
34+
val debugEnabled = request.parameter.contains(enableDebug)
35+
val model = ModelBuilder.introspectProtobufClasses(request.filesToGenerate)(FatalWarningsLog(debugEnabled))
36+
try {
37+
CodeGenResponse.succeed(
38+
SourceGenerator
39+
.generateManagedTest(model)
40+
.map(file =>
41+
CodeGeneratorResponse.File
42+
.newBuilder()
43+
.setName(file.name)
44+
.setContent(file.content)
45+
.build()))
46+
} catch {
47+
case t: Throwable =>
48+
t.printStackTrace()
49+
CodeGenResponse.fail(t.getMessage)
50+
}
51+
}
52+
53+
// FIXME #382 add reference to the runtime lib here
54+
override def suggestedDependencies: Seq[Artifact] = Nil
55+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2021 Lightbend Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.akkaserverless.codegen.scalasdk
18+
19+
case class File(name: String, content: String)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2021 Lightbend Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.akkaserverless.codegen.scalasdk
18+
19+
import com.lightbend.akkasls.codegen.Log
20+
21+
case class FatalWarningsLog(debugEnabled: Boolean) extends Log {
22+
override def debug(message: String): Unit =
23+
if (debugEnabled) println(s"[DEBUG] $message")
24+
override def info(message: String): Unit =
25+
if (debugEnabled) println(s"[INFO] $message")
26+
override def warning(message: String): Unit =
27+
throw new IllegalStateException(message)
28+
override def error(message: String): Unit =
29+
throw new IllegalStateException(message)
30+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2021 Lightbend Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.akkaserverless.codegen.scalasdk
18+
19+
import com.lightbend.akkasls.codegen.ModelBuilder
20+
import protocgen.CodeGenResponse
21+
22+
object SourceGenerator {
23+
24+
/**
25+
* Generate the 'managed' code for this model: code that will be regenerated regularly in the 'compile' configuratio
26+
*/
27+
def generateManaged(model: ModelBuilder.Model): Seq[File] =
28+
Seq(File("foo/bar/Baz.scala", "package foo.bar\n\ntrait Baz"))
29+
30+
/**
31+
* Generate the 'managed' code for this model: code that will be regenerated regularly in the 'compile' configuratio
32+
*/
33+
def generateManagedTest(model: ModelBuilder.Model): Seq[File] =
34+
Seq(File("foo/bar/BazSpec.scala", "package foo.bar\n\ntrait BazSpec"))
35+
36+
/**
37+
* Generate the 'unmanaged' code for this model: code that is generated once on demand and then maintained by the
38+
* user.
39+
*/
40+
def generateUnmanaged(model: ModelBuilder.Model): Seq[File] =
41+
Seq.empty
42+
}

codegen/scala-gen/src/main/scala/com/akkaserverless/codegen/scalasdk/gen.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ import protocbridge.{ Artifact, SandboxedJvmGenerator }
2020
import scalapb.GeneratorOption
2121

2222
object gen {
23-
def apply(options: Seq[String] = Seq.empty): (SandboxedJvmGenerator, Seq[String]) =
23+
def apply(
24+
options: Seq[String] = Seq.empty,
25+
generatorClass: String = "com.akkaserverless.codegen.scalasdk.AkkaserverlessGenerator$")
26+
: (SandboxedJvmGenerator, Seq[String]) =
2427
(
2528
SandboxedJvmGenerator.forModule(
2629
"scala",
2730
Artifact(
2831
com.akkaserverless.codegen.scalasdk.BuildInfo.organization,
2932
"akkaserverless-codegen-scala_2.12",
3033
com.akkaserverless.codegen.scalasdk.BuildInfo.version),
31-
"com.akkaserverless.codegen.scalasdk.AkkaserverlessGenerator$",
34+
generatorClass,
3235
AkkaserverlessGenerator.suggestedDependencies),
3336
options)
3437

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2021 Lightbend Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.akkaserverless.codegen.scalasdk
18+
19+
import protocbridge.{ Artifact, SandboxedJvmGenerator }
20+
21+
object genTests {
22+
def apply(options: Seq[String] = Seq.empty): (SandboxedJvmGenerator, Seq[String]) =
23+
gen(options, "com.akkaserverless.codegen.scalasdk.AkkaserverlessTestGenerator$")
24+
}

sbt-plugin/src/main/scala/com/akkaserverless/sbt/AkkaserverlessPlugin.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package com.akkaserverless.sbt
1818

19-
import com.akkaserverless.codegen.scalasdk.{ gen, AkkaserverlessGenerator }
20-
import sbt._
19+
import com.akkaserverless.codegen.scalasdk.{ gen, genTests, AkkaserverlessGenerator }
20+
import sbt.{ Compile, _ }
2121
import sbt.Keys._
2222
import sbtprotoc.ProtocPlugin
2323
import sbtprotoc.ProtocPlugin.autoImport.PB
@@ -32,7 +32,9 @@ object AkkaserverlessPlugin extends AutoPlugin {
3232
"com.akkaserverless" % "akkaserverless-sdk-protocol" % "0.7.0-beta.18" % "protobuf",
3333
"com.google.protobuf" % "protobuf-java" % "3.17.3" % "protobuf"),
3434
Compile / PB.targets +=
35-
gen(Seq(AkkaserverlessGenerator.enableDebug)) -> (Compile / sourceManaged).value / "akkaserverless"
36-
)
35+
gen(Seq(AkkaserverlessGenerator.enableDebug)) -> (Compile / sourceManaged).value / "akkaserverless",
36+
Test / PB.protoSources ++= (Compile / PB.protoSources).value,
37+
Test / PB.targets +=
38+
genTests(Seq(AkkaserverlessGenerator.enableDebug)) -> (Test / sourceManaged).value / "akkaserverless")
3739

3840
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
> compile
22
$ exists target/scala-2.12/src_managed/main/akkaserverless/foo/bar/Baz.scala
3+
> Test/compile
4+
$ exists target/scala-2.12/src_managed/test/akkaserverless/foo/bar/BazSpec.scala
5+
$ absent target/scala-2.12/src_managed/test/akkaserverless/foo/bar/Baz.scala

0 commit comments

Comments
 (0)