-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix scalapb-validate setup instructions by bumping sbt-protoc (#1264)
* move scalapb-validation sbt instructions to scripted * bump sbt-protoc for better integration with common-protos Fixes scripted 10-scalapb-validate, see * scalapb/ScalaPB#873 (comment) * scalapb/scalapb-validate#70 Other changes * cacheClassLoaders is now deprecated, see thesamet/sbt-protoc@2a730a4 * Forcing recompilation is no longer necessary as the cache gets invalidated if a sandbox genererator classpath is updated, see thesamet/sbt-protoc@80824b0 * The new classloader caching implementation resolves sandboxed generators artifacts earlier, even if they are no sources. That is the case for Test / protocGenerate, which was starting before codeGenProject / Compile / publishLocal, causing: > Error downloading com.lightbend.akka.grpc:akka-grpc-codegen_2.12: > 1.1.0-5-c5975cd5 * demonstrate usage of validate_at_construction Requires scalapb/scalapb-validate@8529a55
- Loading branch information
1 parent
b667ab9
commit 0288da3
Showing
10 changed files
with
98 additions
and
14 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
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
13 changes: 13 additions & 0 deletions
13
sbt-plugin/src/sbt-test/gen-scala-server/10-scalapb-validate/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,13 @@ | ||
resolvers += Resolver.sonatypeRepo("staging") | ||
resolvers += Resolver.bintrayRepo("akka", "snapshots") | ||
|
||
//#setup | ||
import scalapb.GeneratorOption._ | ||
|
||
enablePlugins(AkkaGrpcPlugin) | ||
|
||
libraryDependencies += | ||
"com.thesamet.scalapb" %% "scalapb-validate-core" % scalapb.validate.compiler.BuildInfo.version % "protobuf" | ||
Compile / PB.targets += | ||
scalapb.validate.gen(FlatPackage) -> (Compile / akkaGrpcCodeGeneratorSettings / target).value | ||
//#setup |
3 changes: 3 additions & 0 deletions
3
sbt-plugin/src/sbt-test/gen-scala-server/10-scalapb-validate/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,3 @@ | ||
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % sys.props("project.version")) | ||
|
||
libraryDependencies ++= Seq("com.thesamet.scalapb" %% "scalapb-validate-codegen" % "0.2.2") |
39 changes: 39 additions & 0 deletions
39
...ugin/src/sbt-test/gen-scala-server/10-scalapb-validate/src/main/protobuf/helloworld.proto
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,39 @@ | ||
syntax = "proto3"; | ||
|
||
option java_package = "example.myapp.helloworld.grpc"; | ||
|
||
package helloworld; | ||
|
||
import "validate/validate.proto"; | ||
import "scalapb/scalapb.proto"; | ||
import "scalapb/validate.proto"; | ||
|
||
option (scalapb.options) = { | ||
scope: FILE | ||
[scalapb.validate.file] { | ||
validate_at_construction: true | ||
insert_validator_instance: false | ||
} | ||
}; | ||
|
||
// The greeting service definition. | ||
service GreeterService { | ||
// Sends a greeting | ||
rpc SayHello (HelloRequest) returns (HelloReply) {} | ||
|
||
rpc ItKeepsTalking (stream HelloRequest) returns (HelloReply) {} | ||
|
||
rpc ItKeepsReplying (HelloRequest) returns (stream HelloReply) {} | ||
|
||
rpc StreamHellos (stream HelloRequest) returns (stream HelloReply) {} | ||
} | ||
|
||
// The request message containing the user's name. | ||
message HelloRequest { | ||
string name = 1 [(validate.rules).string.min_len = 3];; | ||
} | ||
|
||
// The response message containing the greetings | ||
message HelloReply { | ||
string message = 1; | ||
} |
20 changes: 20 additions & 0 deletions
20
...src/sbt-test/gen-scala-server/10-scalapb-validate/src/main/scala/example/myapp/Main.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,20 @@ | ||
package example.myapp | ||
|
||
import scala.util.{Failure, Success, Try} | ||
import scalapb.validate._ | ||
|
||
import example.myapp.helloworld.grpc.HelloRequest | ||
|
||
object Main extends App { | ||
|
||
Try(HelloRequest("valid")) match { | ||
case Success(_) => // expected | ||
case Failure(e) => throw new RuntimeException("unexpected violations for \"valid\"", e) | ||
} | ||
|
||
Try(HelloRequest("ko")) match { | ||
case Success(_) => throw new RuntimeException("unexpected success for \"ko\"") | ||
case Failure(e) => // expected | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...rver/10-scalapb-validate/src/main/scala/example/myapp/helloworld/GreeterServiceImpl.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,19 @@ | ||
package example.myapp.helloworld | ||
|
||
import scala.concurrent.Future | ||
|
||
import akka.NotUsed | ||
import akka.stream.scaladsl.Source | ||
|
||
import example.myapp.helloworld.grpc._ | ||
|
||
class GreeterServiceImpl extends GreeterService { | ||
override def sayHello(in: HelloRequest): Future[HelloReply] = ??? | ||
|
||
override def streamHellos(in: Source[HelloRequest, NotUsed]): Source[HelloReply, NotUsed] = ??? | ||
|
||
override def itKeepsTalking(in: Source[HelloRequest, NotUsed]): Future[HelloReply] = ??? | ||
|
||
override def itKeepsReplying(in: HelloRequest): Source[HelloReply, NotUsed] = ??? | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
sbt-plugin/src/sbt-test/gen-scala-server/10-scalapb-validate/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 @@ | ||
> run |