Skip to content

Commit

Permalink
Make plugin run in a sandboxed classloader
Browse files Browse the repository at this point in the history
  • Loading branch information
thesamet committed Jun 20, 2020
1 parent 52d118c commit 7f23b43
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 16 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log
## [0.10.4 - Unreleased](https://github.com/scalapb/ScalaPB/tree/v0.10.4..HEAD)
## [0.10.5](https://github.com/scalapb/ScalaPB/tree/v0.10.4..v10.0.5)
- Updated protoc-bridge to 0.9.0-RC1.
- Minimum version of sbt-protoc required is 0.99.33
- ScalaPB compiler plugin is now compatible with SBT 1.4.0-M1
- Plugin is now e

## [0.10.3](https://github.com/scalapb/ScalaPB/tree/v0.10.3..v10.0.4)
- Updated protoc-bridge to 0.8.3
- Changed scalapb.Message to extend Any, instead of a type alias to Any (see #777)
Expand Down
8 changes: 6 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ lazy val compilerPlugin = project
crossScalaVersions := Seq(Scala212, Scala213),
libraryDependencies ++= Seq(
scalaCollectionCompat.value,
protocBridge,
protocGen,
"com.google.protobuf" % "protobuf-java" % protobufCompilerVersion % "protobuf",
scalaTest % "test",
protocJar % "test"
Expand All @@ -151,7 +151,11 @@ lazy val compilerPlugin = project
ProblemFilters.exclude[MissingClassProblem]("scalapb.GeneratorOption$Lenses$"),
ProblemFilters.exclude[MissingTypesProblem]("scalapb.compiler.GeneratorParams$"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scalapb.compiler.GeneratorParams.tupled"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scalapb.compiler.GeneratorParams.curried")
ProblemFilters
.exclude[DirectMissingMethodProblem]("scalapb.compiler.GeneratorParams.curried"),
ProblemFilters
.exclude[Problem]("scalapb.compiler.ProtobufGenerator.handleCodeGeneratorRequest"),
ProblemFilters.exclude[Problem]("scalapb.ScalaPbCodeGenerator*")
),
Compile / PB.protocVersion := "-v" + protobufCompilerVersion,
Compile / PB.targets := Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import scalapb.compiler.ProtobufGenerator
import scalapb.options.compiler.Scalapb
import com.google.protobuf.ExtensionRegistry
import protocbridge.Artifact
import protocbridge.codegen.CodeGenApp
import protocbridge.codegen.CodeGenRequest
import protocbridge.codegen.CodeGenResponse
import protocgen.CodeGenApp
import protocgen.CodeGenRequest
import protocgen.CodeGenResponse

object ScalaPbCodeGenerator extends CodeGenApp {
override def registerExtensions(registry: ExtensionRegistry): Unit =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import scalapb.options.compiler.Scalapb
import scalapb.options.compiler.Scalapb.FieldOptions
import scala.jdk.CollectionConverters._
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse
import protocbridge.codegen.CodeGenRequest
import protocbridge.codegen.CodeGenResponse
import protocgen.CodeGenRequest
import protocgen.CodeGenResponse

// Exceptions that are caught and passed upstreams as errors.
case class GeneratorException(message: String) extends Exception(message)
Expand Down
19 changes: 14 additions & 5 deletions compiler-plugin/src/main/scala/scalapb/gen.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package scalapb

import protocbridge.JvmGenerator
import protocbridge.{Artifact, SandboxedJvmGenerator}
import scalapb.GeneratorOption._

object gen {
def apply(options: Set[GeneratorOption]): (JvmGenerator, Seq[String]) =
def apply(options: Set[GeneratorOption]): (SandboxedJvmGenerator, Seq[String]) =
(
JvmGenerator("scala", ScalaPbCodeGenerator),
SandboxedJvmGenerator(
"scala",
Artifact(
"com.thesamet.scalapb",
"compilerplugin_2.12",
scalapb.compiler.Version.scalapbVersion
),
"scalapb.ScalaPbCodeGenerator$",
scalapb.ScalaPbCodeGenerator.suggestedDependencies
),
options.map(_.toString).toSeq
)

def apply(options: GeneratorOption*): (JvmGenerator, Seq[String]) = apply(options.toSet)
def apply(options: GeneratorOption*): (SandboxedJvmGenerator, Seq[String]) = apply(options.toSet)

def apply(
flatPackage: Boolean = false,
Expand All @@ -19,7 +28,7 @@ object gen {
singleLineToProtoString: Boolean = false,
asciiFormatToString: Boolean = false,
lenses: Boolean = true
): (JvmGenerator, Seq[String]) = {
): (SandboxedJvmGenerator, Seq[String]) = {
val optionsBuilder = Set.newBuilder[GeneratorOption]
if (flatPackage) {
optionsBuilder += FlatPackage
Expand Down
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object Dependencies {
val collectionCompat = "2.1.6"
val coursier = "2.0.0-RC6-21"
val mockito = "3.2.0"
val protocBridge = "0.8.3"
val protocGen = "0.9.0-RC1"
val protocJar = "3.11.4"
val protobufRuntimeScala = "0.8.6"
val commonsCodec = "1.14"
Expand Down Expand Up @@ -45,7 +45,7 @@ object Dependencies {

val protocJar = "com.github.os72" % "protoc-jar" % versions.protocJar
val coursier = "io.get-coursier" %% "coursier" % versions.coursier
val protocBridge = "com.thesamet.scalapb" %% "protoc-bridge" % versions.protocBridge
val protocGen = "com.thesamet.scalapb" %% "protoc-gen" % versions.protocGen
val protobufJavaUtil = "com.google.protobuf" % "protobuf-java-util" % versions.protobuf

// grpc
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package scalapb

import org.scalatest._
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
import org.apache.commons.codec.binary.Base64
import org.scalatest.matchers.should.Matchers
Expand Down

0 comments on commit 7f23b43

Please sign in to comment.