Skip to content

Commit

Permalink
Removed support for Scala 2.9. Upgraded version of ScalaTest. Fixed v…
Browse files Browse the repository at this point in the history
…arious minor issues.

Upgraded version of scala-parser-combinators.
Big thanks to all supporters!
  • Loading branch information
SandroGrzicic committed Feb 10, 2015
1 parent 607fef2 commit ac79d58
Show file tree
Hide file tree
Showing 31 changed files with 174 additions and 255 deletions.
41 changes: 16 additions & 25 deletions project/ScalaBuffBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import com.typesafe.sbt.osgi.SbtOsgi._
*
* Useful SBT commands:
*
* run (arguments) Runs ScalaBuff inside SBT with the specified arguments.
* test Runs the tests.
* package Generates the main ScalaBuff compiler .JAR.
* update-test-resources Regenerates the test resources using ScalaBuff.
* run (arguments) Runs ScalaBuff inside SBT with the specified arguments.
* test Runs the tests.
* package Generates the main ScalaBuff compiler .JAR.
* update-test-resources Regenerates the test resources using ScalaBuff.
*
* project scalabuff-compiler Switches to the compiler project (default).
* project scalabuff-runtime Switches to the runtime project.
* project scalabuff-compiler Switches to the compiler project (default).
* project scalabuff-runtime Switches to the runtime project.
*
*/
object ScalaBuffBuild extends Build {

lazy val buildSettings = Seq(
name := "ScalaBuff",
organization := "net.sandrogrzicic",
version := "1.3.9",
scalaVersion := "2.10.4",
version := "1.4.0",
scalaVersion := "2.11.4",
logLevel := Level.Info
)

Expand All @@ -44,28 +44,19 @@ object ScalaBuffBuild extends Build {
),

libraryDependencies ++= Seq(
"com.google.protobuf" % "protobuf-java" % "2.5.0"
) ++ (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, scalaMajor)) if scalaMajor >= 10 =>
Seq("org.scalatest" %% "scalatest" % "2.1.5" % "test") ++ (
if (scalaMajor >= 11) Seq("org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.1") else Seq()
)
case Some((2, scalaMajor)) if scalaMajor == 9 =>
Seq("org.scalatest" %% "scalatest" % "1.9.2" % "test")
"com.google.protobuf" % "protobuf-java" % "2.5.0",
"org.scalatest" %% "scalatest" % "2.2.4" % "test"
) ++
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, scalaMajor)) if scalaMajor >= 11 =>
Seq("org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.3")
case _ =>
Seq()
}),

crossScalaVersions ++= Seq("2.10.4", "2.11.2"),
crossScalaVersions ++= Seq("2.10.4", "2.11.4"),

scalacOptions ++= Seq("-encoding", "utf8", "-unchecked", "-deprecation", "-Xlint"),
scalacOptions ++=
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, scalaMajor)) if scalaMajor >= 10 =>
Seq("-Xlog-reflective-calls")
case _ =>
Seq()
}),
scalacOptions ++= Seq("-encoding", "utf8", "-unchecked", "-deprecation", "-Xlint", "-feature", "-Xlog-reflective-calls"),

javacOptions ++= Seq("-encoding", "utf8", "-Xlint:unchecked", "-Xlint:deprecation"),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.sandrogrzicic.scalabuff.compiler

import scala.language.implicitConversions

/**
* Viktor Klang's Enum
* Source: https://gist.github.com/1057513/
Expand Down Expand Up @@ -133,6 +135,4 @@ object FieldTypes extends Enum {
} getOrElse CustomEnumVal(fieldType, fieldType, "null", WIRETYPE_LENGTH_DELIMITED)
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class Generator protected (sourceName: String, importedSymbols: Map[String, Impo
.append(field.number).append(", ").append(field.name.toScalaIdent).append(".get)\n")
case REPEATED =>
// TODO make this nicer currently code is generated 2 times
(field.fType.packable, field.options.filter(value => value.key == "packed" && value.value == "true").headOption) match {
(field.fType.packable, field.options.find(value => value.key == "packed" && value.value == "true")) match {
case (true, Some(option)) =>
out.append(indent2).append("if (!").append(field.name.toScalaIdent).append(".isEmpty) {\n")
out.append(indent3).append("val dataSize = ").append(field.name.toScalaIdent)
Expand Down Expand Up @@ -304,7 +304,7 @@ class Generator protected (sourceName: String, importedSymbols: Map[String, Impo

if (field.label == REPEATED) out.append("+")
out.append("= ")
if(isOptional)out.append("Some(")
if (isOptional) out.append("Some(")
if (field.fType == WIRETYPE_LENGTH_DELIMITED) out.append("in.readBytes()")
else if (field.fType.isEnum) {
// IFF this is an optional field, AND it has a default (i.e. is not
Expand Down Expand Up @@ -453,8 +453,7 @@ class Generator protected (sourceName: String, importedSymbols: Map[String, Impo
out.append(indent0).append("object ").append(name).append(" {\n")
.append(indent1)


out.append("@beans.BeanProperty val defaultInstance = new ")
out.append("@scala.beans.BeanProperty val defaultInstance = new ")

out.append(name).append("()\n").append("\n")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import util.parsing.combinator._
import util.parsing.input.{ PagedSeqReader, CharSequenceReader }
import collection.immutable.PagedSeq
import collection.mutable.ListBuffer
import scala.language.postfixOps

/**
* Main Protobuf parser.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.sandrogrzicic.scalabuff

import scala.language.implicitConversions

/**
* Useful things for this package.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.sandrogrzicic.scalabuff.test

import net.sandrogrzicic.scalabuff.compiler._
import java.io.File.{separator => SEP}
import java.io.File.{separator => /}
import java.io._
import scala.Some

Expand All @@ -28,13 +28,16 @@ object UpdateTestResources extends App {
def accept(filtered: File) = filtered.getName.endsWith(protoExtension)
}

val testDir = "scalabuff-compiler" + SEP + "src" + SEP + "test" + SEP
val testDir = "scalabuff-compiler" + / + "src" + / + "test" + /

val parsedDir = testDir + "resources" + SEP + "parsed" + SEP
val parsedDir = testDir + "resources" + / + "parsed" + /

val protoDirFile = new File(testDir + "resources" + SEP + "proto" + SEP)
val protoDirFile = new File(testDir + "resources" + / + "proto" + /)

for (file <- protoDirFile.listFiles(protoFileFilter)) {
println(s"Processing files in directory ($protoDirFile)...\n")

val protoFiles = protoDirFile.listFiles(protoFileFilter)
for (file <- protoFiles) {
val fileName = file.getName.dropRight(protoExtension.length).camelCase
val generatedParsedFile = new File(parsedDir + fileName + parsedExtension)
generatedParsedFile.delete()
Expand Down Expand Up @@ -95,6 +98,8 @@ object UpdateTestResources extends App {
}
println(fileName)
}

println(s"\nFinished processing (${protoFiles.length}) files.")
}

}
12 changes: 6 additions & 6 deletions scalabuff-compiler/src/test/resources/generated/Complex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ final case class ComplexMessage (
sb.append(indent1).append("\"simpleEnumField\": [").append(indent2).append(`simpleEnumField`.map("\"" + _ + "\"").mkString(", " + indent2)).append(indent1).append(']').append(',')
sb.append(indent1).append("\"repeatedStringField\": [").append(indent2).append(`repeatedStringField`.map("\"" + _ + "\"").mkString(", " + indent2)).append(indent1).append(']').append(',')
sb.append(indent1).append("\"repeatedBytesField\": [").append(indent2).append(`repeatedBytesField`.map("\"" + _ + "\"").mkString(", " + indent2)).append(indent1).append(']').append(',')
sb.length -= 1
if (sb.last.equals(',')) sb.length -= 1
sb.append(indent0).append("}")
sb.toString()
}

}

object ComplexMessage {
@reflect.BeanProperty val defaultInstance = new ComplexMessage()
@scala.beans.BeanProperty val defaultInstance = new ComplexMessage()

def parseFrom(data: Array[Byte]): ComplexMessage = defaultInstance.mergeFrom(data)
def parseFrom(data: Array[Byte], offset: Int, length: Int): ComplexMessage = defaultInstance.mergeFrom(data, offset, length)
Expand Down Expand Up @@ -241,15 +241,15 @@ object ComplexMessage {
.append("{")
sb.append(indent1).append("\"nestedField\": ").append("\"").append(`nestedField`).append("\"").append(',')
if (`nestedEnum`.isDefined) { sb.append(indent1).append("\"nestedEnum\": ").append("\"").append(`nestedEnum`.get).append("\"").append(',') }
sb.length -= 1
if (sb.last.equals(',')) sb.length -= 1
sb.append(indent0).append("}")
sb.toString()
}

}

object Nested {
@reflect.BeanProperty val defaultInstance = new Nested()
@scala.beans.BeanProperty val defaultInstance = new Nested()

def parseFrom(data: Array[Byte]): Nested = defaultInstance.mergeFrom(data)
def parseFrom(data: Array[Byte], offset: Int, length: Int): Nested = defaultInstance.mergeFrom(data, offset, length)
Expand Down Expand Up @@ -331,15 +331,15 @@ final case class AnotherMessage (
.append("{")
sb.append(indent1).append("\"fieldNested\": ").append(`fieldNested`.toJson(indent + 1)).append(',')
sb.append(indent1).append("\"fieldEnum\": ").append("\"").append(`fieldEnum`).append("\"").append(',')
sb.length -= 1
if (sb.last.equals(',')) sb.length -= 1
sb.append(indent0).append("}")
sb.toString()
}

}

object AnotherMessage {
@reflect.BeanProperty val defaultInstance = new AnotherMessage()
@scala.beans.BeanProperty val defaultInstance = new AnotherMessage()

def parseFrom(data: Array[Byte]): AnotherMessage = defaultInstance.mergeFrom(data)
def parseFrom(data: Array[Byte], offset: Int, length: Int): AnotherMessage = defaultInstance.mergeFrom(data, offset, length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ final case class DataTypes (
if (`lengthDelim2`.isDefined) output.writeBytes(201, `lengthDelim2`.get)
if (`lengthDelim3`.isDefined) output.writeEnum(202, `lengthDelim3`.get)
for (_v <- `lengthDelim4`) output.writeInt32(204, _v)
for (_v <- `lengthDelim5`) output.writeInt32(203, _v)
// write field length_delim5 packed
if (!`lengthDelim5`.isEmpty) {
import com.google.protobuf.CodedOutputStream._
val dataSize = `lengthDelim5`.map(computeInt32SizeNoTag(_)).sum
output.writeRawVarint32(1626)
output.writeRawVarint32(dataSize)
for (_v <- `lengthDelim5`) output.writeInt32NoTag(_v)
}
if (`f32bit1`.isDefined) output.writeFixed32(500, `f32bit1`.get)
if (`f32bit2`.isDefined) output.writeSFixed32(501, `f32bit2`.get)
if (`f32bit3`.isDefined) output.writeFloat(502, `f32bit3`.get)
Expand All @@ -105,7 +112,10 @@ final case class DataTypes (
if (`lengthDelim2`.isDefined) __size += computeBytesSize(201, `lengthDelim2`.get)
if (`lengthDelim3`.isDefined) __size += computeEnumSize(202, `lengthDelim3`.get)
for (_v <- `lengthDelim4`) __size += computeInt32Size(204, _v)
for (_v <- `lengthDelim5`) __size += computeInt32Size(203, _v)
if (!`lengthDelim5`.isEmpty) {
val dataSize = `lengthDelim5`.map(computeInt32SizeNoTag(_)).sum
__size += 2 + computeInt32SizeNoTag(dataSize) + dataSize
}
if (`f32bit1`.isDefined) __size += computeFixed32Size(500, `f32bit1`.get)
if (`f32bit2`.isDefined) __size += computeSFixed32Size(501, `f32bit2`.get)
if (`f32bit3`.isDefined) __size += computeFloatSize(502, `f32bit3`.get)
Expand Down Expand Up @@ -249,15 +259,15 @@ final case class DataTypes (
if (`f32bit1`.isDefined) { sb.append(indent1).append("\"f32bit1\": ").append("\"").append(`f32bit1`.get).append("\"").append(',') }
if (`f32bit2`.isDefined) { sb.append(indent1).append("\"f32bit2\": ").append("\"").append(`f32bit2`.get).append("\"").append(',') }
if (`f32bit3`.isDefined) { sb.append(indent1).append("\"f32bit3\": ").append("\"").append(`f32bit3`.get).append("\"").append(',') }
sb.length -= 1
if (sb.last.equals(',')) sb.length -= 1
sb.append(indent0).append("}")
sb.toString()
}

}

object DataTypes {
@reflect.BeanProperty val defaultInstance = new DataTypes()
@scala.beans.BeanProperty val defaultInstance = new DataTypes()

def parseFrom(data: Array[Byte]): DataTypes = defaultInstance.mergeFrom(data)
def parseFrom(data: Array[Byte], offset: Int, length: Int): DataTypes = defaultInstance.mergeFrom(data, offset, length)
Expand Down
24 changes: 12 additions & 12 deletions scalabuff-compiler/src/test/resources/generated/DhComplex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ final case class Response (
sb
.append("{")
sb.append(indent1).append("\"response\": [").append(indent2).append(`response`.map(_.toJson(indent + 1)).mkString(", " + indent2)).append(indent1).append(']').append(',')
sb.length -= 1
if (sb.last.equals(',')) sb.length -= 1
sb.append(indent0).append("}")
sb.toString()
}

}

object Response {
@reflect.BeanProperty val defaultInstance = new Response()
@scala.beans.BeanProperty val defaultInstance = new Response()

def parseFrom(data: Array[Byte]): Response = defaultInstance.mergeFrom(data)
def parseFrom(data: Array[Byte], offset: Int, length: Int): Response = defaultInstance.mergeFrom(data, offset, length)
Expand Down Expand Up @@ -170,15 +170,15 @@ object Response {
if (`profileKey`.isDefined) { sb.append(indent1).append("\"profileKey\": ").append("\"").append(`profileKey`.get).append("\"").append(',') }
if (`data`.isDefined) { sb.append(indent1).append("\"data\": ").append("\"").append(`data`.get).append("\"").append(',') }
sb.append(indent1).append("\"property\": [").append(indent2).append(`property`.map(_.toJson(indent + 1)).mkString(", " + indent2)).append(indent1).append(']').append(',')
sb.length -= 1
if (sb.last.equals(',')) sb.length -= 1
sb.append(indent0).append("}")
sb.toString()
}

}

object Rendition {
@reflect.BeanProperty val defaultInstance = new Rendition()
@scala.beans.BeanProperty val defaultInstance = new Rendition()

def parseFrom(data: Array[Byte]): Rendition = defaultInstance.mergeFrom(data)
def parseFrom(data: Array[Byte], offset: Int, length: Int): Rendition = defaultInstance.mergeFrom(data, offset, length)
Expand Down Expand Up @@ -259,15 +259,15 @@ object Response {
.append("{")
sb.append(indent1).append("\"key\": ").append("\"").append(`key`).append("\"").append(',')
sb.append(indent1).append("\"value\": ").append("\"").append(`value`).append("\"").append(',')
sb.length -= 1
if (sb.last.equals(',')) sb.length -= 1
sb.append(indent0).append("}")
sb.toString()
}

}

object Property {
@reflect.BeanProperty val defaultInstance = new Property()
@scala.beans.BeanProperty val defaultInstance = new Property()

def parseFrom(data: Array[Byte]): Property = defaultInstance.mergeFrom(data)
def parseFrom(data: Array[Byte], offset: Int, length: Int): Property = defaultInstance.mergeFrom(data, offset, length)
Expand Down Expand Up @@ -402,15 +402,15 @@ object Response {
if (`assetKey`.isDefined) { sb.append(indent1).append("\"assetKey\": ").append("\"").append(`assetKey`.get).append("\"").append(',') }
if (`duration`.isDefined) { sb.append(indent1).append("\"duration\": ").append("\"").append(`duration`.get).append("\"").append(',') }
sb.append(indent1).append("\"renditions\": [").append(indent2).append(`renditions`.map(_.toJson(indent + 1)).mkString(", " + indent2)).append(indent1).append(']').append(',')
sb.length -= 1
if (sb.last.equals(',')) sb.length -= 1
sb.append(indent0).append("}")
sb.toString()
}

}

object Video {
@reflect.BeanProperty val defaultInstance = new Video()
@scala.beans.BeanProperty val defaultInstance = new Video()

def parseFrom(data: Array[Byte]): Video = defaultInstance.mergeFrom(data)
def parseFrom(data: Array[Byte], offset: Int, length: Int): Video = defaultInstance.mergeFrom(data, offset, length)
Expand Down Expand Up @@ -510,15 +510,15 @@ object Response {
if (`assetKey`.isDefined) { sb.append(indent1).append("\"assetKey\": ").append("\"").append(`assetKey`.get).append("\"").append(',') }
sb.append(indent1).append("\"reason\": [").append(indent2).append(`reason`.map("\"" + _ + "\"").mkString(", " + indent2)).append(indent1).append(']').append(',')
if (`cause`.isDefined) { sb.append(indent1).append("\"cause\": ").append("\"").append(`cause`.get).append("\"").append(',') }
sb.length -= 1
if (sb.last.equals(',')) sb.length -= 1
sb.append(indent0).append("}")
sb.toString()
}

}

object VideoFailure {
@reflect.BeanProperty val defaultInstance = new VideoFailure()
@scala.beans.BeanProperty val defaultInstance = new VideoFailure()

def parseFrom(data: Array[Byte]): VideoFailure = defaultInstance.mergeFrom(data)
def parseFrom(data: Array[Byte], offset: Int, length: Int): VideoFailure = defaultInstance.mergeFrom(data, offset, length)
Expand Down Expand Up @@ -639,15 +639,15 @@ object Response {
.append("{")
if (`success`.isDefined) { sb.append(indent1).append("\"success\": ").append(`success`.get.toJson(indent + 1)).append(',') }
if (`failure`.isDefined) { sb.append(indent1).append("\"failure\": ").append(`failure`.get.toJson(indent + 1)).append(',') }
sb.length -= 1
if (sb.last.equals(',')) sb.length -= 1
sb.append(indent0).append("}")
sb.toString()
}

}

object VideoResult {
@reflect.BeanProperty val defaultInstance = new VideoResult()
@scala.beans.BeanProperty val defaultInstance = new VideoResult()

def parseFrom(data: Array[Byte]): VideoResult = defaultInstance.mergeFrom(data)
def parseFrom(data: Array[Byte], offset: Int, length: Int): VideoResult = defaultInstance.mergeFrom(data, offset, length)
Expand Down
Loading

0 comments on commit ac79d58

Please sign in to comment.