├── .gitignore ├── README.md ├── build.sbt ├── project ├── Build.scala ├── build.properties └── plugins.sbt └── src ├── main └── scala │ └── ScalaBuffPlugin.scala └── sbt-test └── simple ├── build.sbt ├── project ├── build.scala └── plugins.sbt └── src └── main ├── protobuf ├── test0.simple.proto └── test1.simple.proto └── scala └── Test.scala /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | boot 3 | lib_managed 4 | _build 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sbt-scalabuff 2 | 3 | [SBT](http://github.com/harrah/xsbt) plugin to generate scala case class from [Google Protocol Buffers](https://developers.google.com/protocol-buffers/) using [ScalaBuff](https://github.com/SandroGrzicic/ScalaBuff). 4 | 5 | ## Usage 6 | 7 | Adding the plugin: 8 | 9 | addSbtPlugin("com.github.sbt" %% "sbt-scalabuff" % "0.2") 10 | 11 | Enable the plugin in your build: 12 | 13 | import scalabuff.ScalaBuffPlugin._ 14 | 15 | object build extends Build { 16 | lazy val root = Project("main", file("."), settings = Defaults.defaultSettings ++ scalabuffSettings).configs(ScalaBuff) 17 | } 18 | 19 | Once activated place your '.proto' definition in *src/main/protobuf* and that's all! 20 | 21 | ## Contribution Policy 22 | 23 | Contributions via GitHub pull requests are gladly accepted from their original author. 24 | Along with any pull requests, please state that the contribution is your original work and 25 | that you license the work to the project under the project's open source license. 26 | Whether or not you state this explicitly, by submitting any copyrighted material via pull request, 27 | email, or other means you agree to license the material under the project's open source license and 28 | warrant that you have the legal authority to do so. 29 | 30 | ## License 31 | 32 | This software is licensed under the Apache 2 license, quoted below. 33 | 34 | Copyright 2009-2013 Alois Cochard 35 | 36 | Licensed under the Apache License, Version 2.0 (the "License"); you may not 37 | use this file except in compliance with the License. You may obtain a copy of 38 | the License at http://www.apache.org/licenses/LICENSE-2.0 39 | 40 | Unless required by applicable law or agreed to in writing, software 41 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 42 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 43 | License for the specific language governing permissions and limitations under 44 | the License. 45 | -------------------------------------------------------------------------------- /build.sbt: -------------------------------------------------------------------------------- 1 | sbtPlugin := true 2 | 3 | name := "sbt-scalabuff" 4 | 5 | version := "1.3.7" 6 | 7 | organization := "com.github.sbt" 8 | 9 | crossBuildingSettings 10 | 11 | CrossBuilding.crossSbtVersions := Seq("0.12", "0.13") 12 | -------------------------------------------------------------------------------- /project/Build.scala: -------------------------------------------------------------------------------- 1 | import sbt._ 2 | import Keys._ 3 | 4 | object ScalaBuffBuild extends Build { 5 | lazy val project = Project( 6 | id = "root", 7 | base = file("."), 8 | settings = Defaults.defaultSettings ++ Seq( 9 | credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"), 10 | publishTo <<= (version) { version: String => 11 | val scalasbt = "http://repo.scala-sbt.org/scalasbt/" 12 | val (name, url) = if (version.contains("-SNAPSHOT")) 13 | ("sbt-plugin-snapshots", scalasbt+"sbt-plugin-snapshots") 14 | else 15 | ("sbt-plugin-releases", scalasbt+"sbt-plugin-releases") 16 | Some(Resolver.url(name, new URL(url))(Resolver.ivyStylePatterns)) 17 | }, 18 | publishMavenStyle := false 19 | ) 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version=0.13.1 2 | -------------------------------------------------------------------------------- /project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("net.virtual-void" % "sbt-cross-building" % "0.8.1") 2 | -------------------------------------------------------------------------------- /src/main/scala/ScalaBuffPlugin.scala: -------------------------------------------------------------------------------- 1 | package scalabuff 2 | 3 | import sbt._ 4 | import Keys._ 5 | import sbt.Fork 6 | 7 | import java.io.File 8 | 9 | object ScalaBuffPlugin extends Plugin { 10 | val ScalaBuff = config("scalabuff").hide 11 | 12 | val scalabuff = TaskKey[Seq[File]]("scalabuff", "Generate Scala sources from protocol buffers definitions") 13 | val scalabuffArgs = SettingKey[Seq[String]]("scalabuff-args", "Extra command line parameters to scalabuff.") 14 | val scalabuffMain = SettingKey[String]("scalabuff-main", "ScalaBuff main class.") 15 | val scalabuffVersion = SettingKey[String]("scalabuff-version", "ScalaBuff version.") 16 | 17 | lazy val scalabuffSettings = Seq[Project.Setting[_]]( 18 | scalabuffArgs := Seq(), 19 | scalabuffMain := "net.sandrogrzicic.scalabuff.compiler.ScalaBuff", 20 | scalabuffVersion := "1.3.6", 21 | libraryDependencies <++= (scalabuffVersion in ScalaBuff)(version => 22 | Seq( 23 | "net.sandrogrzicic" %% "scalabuff-compiler" % version % ScalaBuff.name, 24 | "net.sandrogrzicic" %% "scalabuff-runtime" % version 25 | ) 26 | ), 27 | sourceDirectory in ScalaBuff <<= (sourceDirectory in Compile), 28 | 29 | managedClasspath in ScalaBuff <<= (classpathTypes, update) map { (ct, report) => 30 | Classpaths.managedJars(ScalaBuff, ct, report) 31 | }, 32 | 33 | scalabuff <<= ( 34 | sourceDirectory in ScalaBuff, 35 | sourceManaged in ScalaBuff, 36 | scalabuffMain in ScalaBuff, 37 | scalabuffArgs in ScalaBuff, 38 | managedClasspath in ScalaBuff, 39 | javaHome, 40 | streams, 41 | cacheDirectory 42 | ).map(process), 43 | 44 | sourceGenerators in Compile <+= (scalabuff).task 45 | ) 46 | 47 | private def process( 48 | source: File, 49 | sourceManaged: File, 50 | mainClass: String, 51 | args: Seq[String], 52 | classpath: Classpath, 53 | javaHome: Option[File], 54 | streams: TaskStreams, 55 | cache: File 56 | ): Seq[File] = { 57 | val input = source / "protobuf" 58 | if (input.exists) { 59 | val output = sourceManaged / "scala" 60 | val cached = FileFunction.cached(cache / "scalabuff", FilesInfo.lastModified, FilesInfo.exists) { 61 | (in: Set[File]) => { 62 | IO.delete(output) 63 | IO.createDirectory(output) 64 | Fork.java( 65 | javaHome, 66 | List( 67 | "-cp", classpath.map(_.data).mkString(File.pathSeparator), mainClass, 68 | "--scala_out=" + output.toString 69 | ) ++ args.toSeq ++ in.toSeq.map(_.toString), 70 | streams.log 71 | ) 72 | (output ** ("*.scala")).get.toSet 73 | } 74 | } 75 | cached((input ** "*.proto").get.toSet).toSeq 76 | } else Nil 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/sbt-test/simple/build.sbt: -------------------------------------------------------------------------------- 1 | scalaVersion := "2.10.0" 2 | 3 | -------------------------------------------------------------------------------- /src/sbt-test/simple/project/build.scala: -------------------------------------------------------------------------------- 1 | import sbt._ 2 | import Keys.libraryDependencies 3 | 4 | import scalabuff.ScalaBuffPlugin._ 5 | 6 | object build extends Build { 7 | lazy val root = Project("main", file("."), settings = Defaults.defaultSettings ++ scalabuffSettings).configs(ScalaBuff) 8 | } 9 | -------------------------------------------------------------------------------- /src/sbt-test/simple/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | addSbtPlugin("com.github.sbt" %% "sbt-scalabuff" % "0.3-SNAPSHOT") 2 | -------------------------------------------------------------------------------- /src/sbt-test/simple/src/main/protobuf/test0.simple.proto: -------------------------------------------------------------------------------- 1 | package test0; 2 | 3 | option optimize_for = LITE_RUNTIME; 4 | 5 | message Simple { 6 | required int32 required_field = 1; 7 | optional float optional_field = 2; 8 | repeated string repeated_field = 3; 9 | 10 | optional int32 type = 4 [default=100]; 11 | optional int32 int32Default = 5 [default=100]; 12 | optional string stringDefault = 6 [default="some string"]; 13 | } 14 | -------------------------------------------------------------------------------- /src/sbt-test/simple/src/main/protobuf/test1.simple.proto: -------------------------------------------------------------------------------- 1 | package test1; 2 | 3 | option optimize_for = LITE_RUNTIME; 4 | 5 | message Simple { 6 | required int32 required_field = 1; 7 | optional float optional_field = 2; 8 | repeated string repeated_field = 3; 9 | 10 | optional int32 type = 4 [default=100]; 11 | optional int32 int32Default = 5 [default=100]; 12 | optional string stringDefault = 6 [default="some string"]; 13 | } 14 | -------------------------------------------------------------------------------- /src/sbt-test/simple/src/main/scala/Test.scala: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | object Test { 4 | test0.Simple() 5 | test1.Simple() 6 | } 7 | --------------------------------------------------------------------------------