Permalink
Browse files

Merge branch 'tmp'

  • Loading branch information...
2 parents 32fa6f5 + 40e4785 commit 327b67ac029fa184b1b6526b9cbeb08d477585d7 Jenkins (CI) committed Feb 20, 2014
Showing with 294 additions and 95 deletions.
  1. +14 −0 CHANGES
  2. +1 −1 pom.xml
  3. +3 −3 project/Build.scala
  4. +4 −4 scrooge-benchmark/pom.xml
  5. +1 −1 scrooge-core/pom.xml
  6. +14 −0 scrooge-core/src/main/scala/com/twitter/scrooge/ThriftStructMetaData.scala
  7. +7 −7 scrooge-generator/pom.xml
  8. +1 −1 scrooge-generator/src/main/resources/javagen/consts.java
  9. +1 −1 scrooge-generator/src/main/resources/javagen/enum.java
  10. +1 −1 scrooge-generator/src/main/resources/javagen/service.java
  11. +1 −1 scrooge-generator/src/main/resources/javagen/struct.java
  12. +13 −2 scrooge-generator/src/main/resources/javagen/union.java
  13. +1 −1 scrooge-generator/src/main/resources/scalagen/consts.scala
  14. +2 −2 scrooge-generator/src/main/resources/scalagen/enum.scala
  15. +1 −1 scrooge-generator/src/main/resources/scalagen/finagleClient.scala
  16. +1 −1 scrooge-generator/src/main/resources/scalagen/finagleService.scala
  17. +0 −1 scrooge-generator/src/main/resources/scalagen/readField.scala
  18. +2 −2 scrooge-generator/src/main/resources/scalagen/service.scala
  19. +26 −6 scrooge-generator/src/main/resources/scalagen/struct.scala
  20. +18 −4 scrooge-generator/src/main/resources/scalagen/union.scala
  21. +0 −4 scrooge-generator/src/main/scala/com/twitter/scrooge/Compiler.scala
  22. +1 −2 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/ConstsTemplate.scala
  23. +1 −2 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/EnumTemplate.scala
  24. +5 −8 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/Generator.scala
  25. +9 −6 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/JavaGenerator.scala
  26. +8 −5 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/ScalaGenerator.scala
  27. +1 −4 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/ServiceTemplate.scala
  28. +11 −2 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/StructTemplate.scala
  29. +4 −0 scrooge-generator/src/main/scala/com/twitter/scrooge/frontend/ParseException.scala
  30. +6 −1 scrooge-generator/src/main/scala/com/twitter/scrooge/frontend/ThriftParser.scala
  31. +0 −1 scrooge-generator/src/main/scala/com/twitter/scrooge/java_generator/ApacheJavaGenerator.scala
  32. +39 −2 scrooge-generator/src/test/scala/com/twitter/scrooge/ThriftStructMetaDataSpec.scala
  33. +2 −3 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/GeneratorFactorySpec.scala
  34. +17 −0 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/JavaGeneratorSpec.scala
  35. +18 −0 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/ScalaGeneratorSpec.scala
  36. +12 −0 scrooge-generator/src/test/scala/com/twitter/scrooge/frontend/ThriftParserSpec.scala
  37. +1 −0 scrooge-generator/src/test/thrift/relative/candy.thrift
  38. +24 −0 scrooge-generator/src/test/thrift/standalone/union.thrift
  39. +2 −2 scrooge-maven-plugin/pom.xml
  40. +9 −1 scrooge-maven-plugin/src/main/java/com/twitter/AbstractMavenScroogeMojo.java
  41. +3 −3 scrooge-ostrich/pom.xml
  42. +3 −3 scrooge-runtime/pom.xml
  43. +2 −2 scrooge-sbt-plugin/src/main/scala/com/twitter/ScroogeSBT.scala
  44. +4 −4 scrooge-serializer/pom.xml
View
14 CHANGES
@@ -6,6 +6,20 @@ as it is included in Scoorge's user's guide.
3.x
-----
+3.12.3
+~~~~~
+
+- scrooge: add the thrift root to the list of includes for scrooge
+- scrooge: Automatically whitelist all idl jar dependencies
+- scrooge: fixed issue when default value is enum from other namespace where namespace is missing in generated code
+- scrooge: Update mustache to 0.8.13
+- scrooge: update util to 6.12.0
+- scrooge: update finagle to 6.12.1
+- scrooge: update util to 6.12.1
+- scrooge: add extra fields to generated companion object for reflection use
+- scrooge: capture unknown union values as its own value (THRIFT-99)
+- scrooge: Update scrooge to remove date from Generated annotation so generated code is reproducible.
+
3.12.2
~~~~~
View
2 pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>scrooge</artifactId>
<packaging>pom</packaging>
- <version>3.12.3-SNAPSHOT</version>
+ <version>3.12.4-SNAPSHOT</version>
<distributionManagement>
<repository>
<id>artifactory-release</id>
View
6 project/Build.scala
@@ -4,9 +4,9 @@ import com.typesafe.sbt.SbtSite.site
import com.typesafe.sbt.site.SphinxSupport.Sphinx
object Scrooge extends Build {
- val libVersion = "3.12.2"
- val utilVersion = "6.11.1"
- val finagleVersion = "6.11.1"
+ val libVersion = "3.12.3"
+ val utilVersion = "6.12.1"
+ val finagleVersion = "6.12.1"
def util(which: String) = "com.twitter" %% ("util-"+which) % utilVersion
def finagle(which: String) = "com.twitter" %% ("finagle-"+which) % finagleVersion
View
8 scrooge-benchmark/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>scrooge-benchmark</artifactId>
<packaging>jar</packaging>
- <version>3.12.3-SNAPSHOT</version>
+ <version>3.12.4-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -19,7 +19,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-runtime</artifactId>
- <version>3.12.3-SNAPSHOT</version>
+ <version>3.12.4-SNAPSHOT</version>
</dependency>
<!-- library dependencies -->
<dependency>
@@ -30,12 +30,12 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-generator</artifactId>
- <version>3.12.3-SNAPSHOT</version>
+ <version>3.12.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-app</artifactId>
- <version>6.11.2-SNAPSHOT</version>
+ <version>6.12.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.caliper</groupId>
View
2 scrooge-core/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>scrooge-core</artifactId>
<packaging>jar</packaging>
- <version>3.12.3-SNAPSHOT</version>
+ <version>3.12.4-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
View
14 scrooge-core/src/main/scala/com/twitter/scrooge/ThriftStructMetaData.scala
@@ -20,6 +20,7 @@ final class ThriftStructMetaData[T <: ThriftStruct](val codec: ThriftStructCodec
}.
mkString
}
+
/**
* The Class object for the ThriftStructCodec subclass.
*/
@@ -83,3 +84,16 @@ final class ThriftStructField[T <: ThriftStruct](val tfield: TField, val method:
*/
def getValue[R](struct: T): R = method.invoke(struct).asInstanceOf[R]
}
+
+/**
+ * Field information to be embedded in a generated struct's companion class.
+ * Allows for reflection on field types.
+ */
+final class ThriftStructFieldInfo(
+ val tfield: TField,
+ val isOptional: Boolean,
+ val manifest: Manifest[_],
+ val keyManifest: scala.Option[Manifest[_]],
+ val valueManifest: scala.Option[Manifest[_]]
+)
+
View
14 scrooge-generator/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>scrooge-generator</artifactId>
<packaging>jar</packaging>
- <version>3.12.3-SNAPSHOT</version>
+ <version>3.12.4-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -20,7 +20,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-runtime</artifactId>
- <version>3.12.3-SNAPSHOT</version>
+ <version>3.12.4-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<!-- library dependencies -->
@@ -37,12 +37,12 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
- <version>6.11.2-SNAPSHOT</version>
+ <version>6.12.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-codec</artifactId>
- <version>6.11.2-SNAPSHOT</version>
+ <version>6.12.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@@ -101,13 +101,13 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>finagle-core</artifactId>
- <version>6.11.2-SNAPSHOT</version>
+ <version>6.12.2-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>finagle-thrift</artifactId>
- <version>6.11.2-SNAPSHOT</version>
+ <version>6.12.2-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -119,7 +119,7 @@
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
- <version>0.8.12</version>
+ <version>0.8.12.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
View
2 scrooge-generator/src/main/resources/javagen/consts.java
@@ -5,7 +5,7 @@
import java.util.Map;
import java.util.Set;
-@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler")
public final class Constants {
{{#constants}}
{{docstring}}
View
2 scrooge-generator/src/main/resources/javagen/enum.java
@@ -1,7 +1,7 @@
package {{package}};
{{docstring}}
-@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler")
public enum {{EnumName}} {
{{#values}}
{{valuedocstring}}
View
2 scrooge-generator/src/main/resources/javagen/service.java
@@ -34,7 +34,7 @@
{{/withFinagle}}
{{docstring}}
-@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler")
public class {{ServiceName}} {
public interface Iface {{#syncParent}}extends {{syncParent}} {{/syncParent}}{
{{#syncFunctions}}
View
2 scrooge-generator/src/main/resources/javagen/struct.java
@@ -18,7 +18,7 @@
import java.util.HashSet;
{{docstring}}
-@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler")
public {{/public}}{{^public}}static {{/public}}class {{StructName}}{{#isException}} extends Exception{{/isException}} implements ThriftStruct {
private static final TStruct STRUCT = new TStruct("{{StructNameForWire}}");
{{#fields}}
View
15 scrooge-generator/src/main/resources/javagen/union.java
@@ -18,7 +18,7 @@
import java.util.HashSet;
{{docstring}}
-@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler")
public {{/public}}{{^public}}static {{/public}}class {{StructName}} implements ThriftStruct {
private static final TStruct STRUCT = new TStruct("{{StructNameForWire}}");
{{#fields}}
@@ -29,7 +29,8 @@
public enum Field {
{{#fields}}
{{FIELD_NAME}}{{/fields|,
-}}
+}},
+UNKNOWN_UNION_VALUE;
}
@@ -53,6 +54,9 @@
{{/readWriteInfo}}
{{/fields}}
default:
+ if (_field.type != TType.STOP) {
+ result = new {{StructName}}();
+ }
TProtocolUtil.skip(_iprot, _field.type);
}
if (_field.type != TType.STOP) {
@@ -93,6 +97,13 @@ public static void encode({{StructName}} struct, TProtocol oprot) throws org.apa
CODEC.encode(struct, oprot);
}
+ private {{StructName}}() {
+ this.setField = Field.UNKNOWN_UNION_VALUE;
+ {{#fields}}
+ this.{{fieldName}} = null;
+ {{/fields}}
+ }
+
public {{StructName}}(
Field setField,
Object value
View
2 scrooge-generator/src/main/resources/scalagen/consts.scala
@@ -1,6 +1,6 @@
package {{package}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
object Constants {
{{#constants}}
{{docstring}}
View
4 scrooge-generator/src/main/resources/scalagen/enum.scala
@@ -3,7 +3,7 @@ package {{package}}
import com.twitter.scrooge.ThriftEnum
{{docstring}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
case object {{EnumName}} {
{{#values}}
{{valuedocstring}}
@@ -57,5 +57,5 @@ case object {{EnumName}} {
{{docstring}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
sealed trait {{EnumName}} extends ThriftEnum with Serializable
View
2 scrooge-generator/src/main/resources/scalagen/finagleClient.scala
@@ -13,7 +13,7 @@ import org.apache.thrift.transport.{TMemoryBuffer, TMemoryInputTransport}
import scala.collection.{Map, Set}
{{docstring}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
class {{ServiceName}}$FinagleClient(
{{#hasParent}}override {{/hasParent}}val service: FinagleService[ThriftClientRequest, Array[Byte]],
{{#hasParent}}override {{/hasParent}}val protocolFactory: TProtocolFactory = new TBinaryProtocol.Factory,
View
2 scrooge-generator/src/main/resources/scalagen/finagleService.scala
@@ -13,7 +13,7 @@ import scala.collection.mutable.{
import scala.collection.{Map, Set}
{{docstring}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
class {{ServiceName}}$FinagleService(
iface: {{ServiceName}}[Future],
protocolFactory: TProtocolFactory
View
1 scrooge-generator/src/main/resources/scalagen/readField.scala
@@ -9,7 +9,6 @@ _field.`type` match {
{{#required}}
{{gotName}} = true
{{/required}}
- _readField = true
}
case _ => // skip
}
View
4 scrooge-generator/src/main/resources/scalagen/service.scala
@@ -1,7 +1,7 @@
package {{package}}
import com.twitter.scrooge.{
- TFieldBlob, ThriftService, ThriftStruct, ThriftStructCodec, ThriftStructCodec3, ThriftUtil}
+ TFieldBlob, ThriftService, ThriftStruct, ThriftStructCodec, ThriftStructCodec3, ThriftStructFieldInfo, ThriftUtil}
import java.nio.ByteBuffer
import java.util.Arrays
import org.apache.thrift.protocol._
@@ -16,7 +16,7 @@ import scala.collection.mutable.{
import scala.collection.{Map, Set}
{{docstring}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
trait {{ServiceName}}[+MM[_]] {{#genericParent}}extends {{genericParent}} {{/genericParent}}{
{{#genericFunctions}}
{{>function}}
View
32 scrooge-generator/src/main/resources/scalagen/struct.scala
@@ -2,7 +2,7 @@
package {{package}}
import com.twitter.scrooge.{
- TFieldBlob, ThriftException, ThriftStruct, ThriftStructCodec3, ThriftUtil}
+ TFieldBlob, ThriftException, ThriftStruct, ThriftStructCodec3, ThriftStructFieldInfo, ThriftUtil}
import org.apache.thrift.protocol._
import org.apache.thrift.transport.{TMemoryBuffer, TTransport}
import java.nio.ByteBuffer
@@ -28,6 +28,31 @@ object {{StructName}} extends ThriftStructCodec3[{{StructName}}] {
{{/fields}}
/**
+ * Field information in declaration order.
+ */
+ lazy val fieldInfos: scala.List[ThriftStructFieldInfo] = scala.List[ThriftStructFieldInfo](
+{{#fields}}
+ new ThriftStructFieldInfo(
+ {{fieldConst}},
+ {{optional}},
+ {{fieldConst}}Manifest,
+{{#fieldKeyType}}
+ Some(implicitly[Manifest[{{fieldKeyType}}]]),
+{{/fieldKeyType}}
+{{^fieldKeyType}}
+ None,
+{{/fieldKeyType}}
+{{#fieldValueType}}
+ Some(implicitly[Manifest[{{fieldValueType}}]])
+{{/fieldValueType}}
+{{^fieldValueType}}
+ None
+{{/fieldValueType}}
+ )
+{{/fields|,}}
+ )
+
+ /**
* Checks that all required fields are non-null.
*/
def validate(_item: {{StructName}}) {
@@ -65,7 +90,6 @@ object {{StructName}} extends ThriftStructCodec3[{{StructName}}] {
if (_field.`type` == TType.STOP) {
_done = true
} else {
- var _readField = false
_field.id match {
{{#fields}}
case {{id}} =>
@@ -75,10 +99,6 @@ object {{StructName}} extends ThriftStructCodec3[{{StructName}}] {
if (_passthroughFields == null)
_passthroughFields = immutable$Map.newBuilder[Short, TFieldBlob]
_passthroughFields += (_field.id -> TFieldBlob.read(_field, _iprot))
- _readField = true
- }
- if (!_readField) {
- TProtocolUtil.skip(_iprot, _field.`type`)
}
_iprot.readFieldEnd()
}
View
22 scrooge-generator/src/main/resources/scalagen/union.scala
@@ -1,7 +1,7 @@
{{#public}}
package {{package}}
-import com.twitter.scrooge.{ThriftStruct, ThriftStructCodec3}
+import com.twitter.scrooge.{ThriftStruct, ThriftStructCodec3, TFieldBlob}
import org.apache.thrift.protocol._
import java.nio.ByteBuffer
import java.util.Arrays
@@ -11,11 +11,11 @@ import scala.collection.mutable.{
import scala.collection.{Map, Set}
{{/public}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
sealed trait {{StructName}} extends {{parentType}}
{{docstring}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
object {{StructName}} extends ThriftStructCodec3[{{StructName}}] {
val Union = new TStruct("{{StructNameForWire}}")
{{#fields}}
@@ -36,7 +36,12 @@ object {{StructName}} extends ThriftStructCodec3[{{StructName}}] {
{{>readUnionField}}
{{/readWriteInfo}}
{{/fields}}
- case _ => TProtocolUtil.skip(_iprot, _field.`type`)
+ case _ =>
+ if (_field.`type` != TType.STOP) {
+ _result = UnknownUnionField(TFieldBlob.read(_field, _iprot))
+ } else {
+ TProtocolUtil.skip(_iprot, _field.`type`)
+ }
}
if (_field.`type` != TType.STOP) {
_iprot.readFieldEnd()
@@ -79,4 +84,13 @@ object {{StructName}} extends ThriftStructCodec3[{{StructName}}] {
}
}
{{/fields}}
+
+ case class UnknownUnionField private[{{StructName}}](private val field: TFieldBlob) extends {{StructName}} {
+ override def write(_oprot: TProtocol) {
+ _oprot.writeStructBegin(Union)
+ field.write(_oprot)
+ _oprot.writeFieldStop()
+ _oprot.writeStructEnd()
+ }
+ }
}
View
4 scrooge-generator/src/main/scala/com/twitter/scrooge/Compiler.scala
@@ -20,8 +20,6 @@ import scala.collection.mutable
import java.io.{File, FileWriter}
import com.twitter.scrooge.backend.{Generator, ScalaGenerator, ServiceOption}
import com.twitter.scrooge.frontend.{TypeResolver, ThriftParser, Importer}
-import org.apache.commons.lang.time.FastDateFormat
-import java.util.Date
class Compiler {
val defaultDestFolder = "."
@@ -40,7 +38,6 @@ class Compiler {
var language: String = "scala"
var defaultNamespace: String = "thrift"
var scalaWarnOnJavaNSFallback: Boolean = false
- val now: String = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date())
def run() {
// if --gen-file-map is specified, prepare the map file.
@@ -70,7 +67,6 @@ class Compiler {
language,
resolvedDoc.resolver.includeMap,
defaultNamespace,
- now,
experimentFlags)
generator match {
View
3 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/ConstsTemplate.scala
@@ -19,7 +19,6 @@ trait ConstsTemplate {
"value" -> genConstant(c.value),
"docstring" -> codify(c.docstring.getOrElse(""))
)
- }),
- "date" -> codify(generationDate)
+ })
)
}
View
3 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/EnumTemplate.scala
@@ -22,7 +22,6 @@ trait EnumTemplate {
"unquotedNameLowerCase" -> codify(value.sid.fullName.toLowerCase),
"value" -> codify(value.value.toString)
)
- }),
- "date" -> codify(generationDate)
+ })
)
}
View
13 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/Generator.scala
@@ -54,10 +54,9 @@ object Generator {
lan: String,
includeMap: Map[String, ResolvedDocument],
defaultNamespace: String,
- generationDate: String,
experimentFlags: Seq[String]
): ThriftGenerator = Generators.get(lan) match {
- case Some(gen) => gen(includeMap, defaultNamespace, generationDate, experimentFlags)
+ case Some(gen) => gen(includeMap, defaultNamespace, experimentFlags)
case None => throw new Exception("Generator for language \"%s\" not found".format(lan))
}
}
@@ -67,7 +66,6 @@ trait GeneratorFactory {
def apply(
includeMap: Map[String, ResolvedDocument],
defaultNamespace: String,
- generationDate: String,
experimentFlags: Seq[String]
): ThriftGenerator
}
@@ -85,7 +83,6 @@ trait Generator
*/
val includeMap: Map[String, ResolvedDocument]
val defaultNamespace: String
- val generationDate: String
val experimentFlags: Seq[String]
/******************** helper functions ************************/
@@ -169,7 +166,7 @@ trait Generator
case QualifiedID(names) => codify(names.map { quoteKeyword(_) }.mkString("."))
}
- def genConstant(constant: RHS, mutable: Boolean = false): CodeFragment = {
+ def genConstant(constant: RHS, mutable: Boolean = false, fieldType: Option[FieldType] = None): CodeFragment = {
constant match {
case NullLiteral => codify("null")
case StringLiteral(value) => codify(quote(value))
@@ -179,7 +176,7 @@ trait Generator
case c@ListRHS(_) => genList(c, mutable)
case c@SetRHS(_) => genSet(c, mutable)
case c@MapRHS(_) => genMap(c, mutable)
- case c: EnumRHS => genEnum(c)
+ case c: EnumRHS => genEnum(c, fieldType)
case iv@IdRHS(id) => genID(id)
}
}
@@ -190,7 +187,7 @@ trait Generator
def genMap(map: MapRHS, mutable: Boolean = false): CodeFragment
- def genEnum(enum: EnumRHS): CodeFragment
+ def genEnum(enum: EnumRHS, fieldType: Option[FieldType] = None): CodeFragment
/**
* The default value for the specified type and mutability.
@@ -209,7 +206,7 @@ trait Generator
if (f.requiredness.isOptional) {
None
} else {
- f.default.map(genConstant(_, false)) orElse {
+ f.default.map(genConstant(_, false, Some(f.fieldType))) orElse {
if (f.fieldType.isInstanceOf[ContainerType]) {
Some(genDefaultValue(f.fieldType))
} else {
View
15 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/JavaGenerator.scala
@@ -25,15 +25,13 @@ object JavaGeneratorFactory extends GeneratorFactory {
def apply(
includeMap: Map[String, ResolvedDocument],
defaultNamespace: String,
- generationDate: String,
experimentFlags: Seq[String]
- ): ThriftGenerator = new JavaGenerator(includeMap, defaultNamespace, generationDate)
+ ): ThriftGenerator = new JavaGenerator(includeMap, defaultNamespace)
}
class JavaGenerator(
val includeMap: Map[String, ResolvedDocument],
- val defaultNamespace: String,
- val generationDate: String
+ val defaultNamespace: String
) extends Generator with ThriftGenerator {
val fileExtension = ".java"
@@ -116,8 +114,13 @@ class JavaGenerator(
codify(code)
}
- def genEnum(enum: EnumRHS): CodeFragment =
- genID(enum.value.sid.toUpperCase.addScope(enum.enum.sid.toTitleCase))
+ def genEnum(enum: EnumRHS, fieldType: Option[FieldType] = None): CodeFragment = {
+ def getTypeId: Identifier = fieldType.getOrElse(Void) match {
+ case n: NamedType => qualifyNamedType(n)
+ case _ => enum.enum.sid
+ }
+ genID(enum.value.sid.toUpperCase.addScope(getTypeId.toTitleCase))
+ }
/**
* Generates a suffix to append to a field expression that will
View
13 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/ScalaGenerator.scala
@@ -26,15 +26,13 @@ object ScalaGeneratorFactory extends GeneratorFactory {
def apply(
includeMap: Map[String, ResolvedDocument],
defaultNamespace: String,
- generationDate: String,
experimentFlags: Seq[String]
- ): ThriftGenerator = new ScalaGenerator(includeMap, defaultNamespace, generationDate, experimentFlags)
+ ): ThriftGenerator = new ScalaGenerator(includeMap, defaultNamespace, experimentFlags)
}
class ScalaGenerator(
val includeMap: Map[String, ResolvedDocument],
val defaultNamespace: String,
- val generationDate: String,
val experimentFlags: Seq[String]
) extends Generator with ThriftGenerator {
@@ -133,8 +131,13 @@ class ScalaGenerator(
codify(code)
}
- def genEnum(enum: EnumRHS): CodeFragment =
- genID(enum.value.sid.toTitleCase.addScope(enum.enum.sid.toTitleCase))
+ def genEnum(enum: EnumRHS, fieldType: Option[FieldType] = None): CodeFragment = {
+ def getTypeId: Identifier = fieldType.getOrElse(Void) match {
+ case n: NamedType => qualifyNamedType(n)
+ case _ => enum.enum.sid
+ }
+ genID(enum.value.sid.toTitleCase.addScope(getTypeId.toTitleCase))
+ }
override def genDefaultValue(fieldType: FieldType, mutable: Boolean = false): CodeFragment = {
val code = fieldType match {
View
5 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/ServiceTemplate.scala
@@ -90,7 +90,6 @@ trait ServiceTemplate {
Dictionary(
"package" -> genID(namespace),
"ServiceName" -> genID(service.sid.toTitleCase),
- "date" -> codify(generationDate),
"docstring" -> codify(service.docstring.getOrElse("")),
"hasParent" -> v(service.parent.isDefined),
"finagleClientParent" ->
@@ -126,7 +125,6 @@ trait ServiceTemplate {
Dictionary(
"package" -> genID(namespace),
"ServiceName" -> genID(service.sid.toTitleCase),
- "date" -> codify(generationDate),
"docstring" -> codify(service.docstring.getOrElse("")),
"hasParent" -> v(service.parent.isDefined),
"finagleServiceParent" ->
@@ -205,8 +203,7 @@ trait ServiceTemplate {
"finagleServices" -> v(
if (withFinagle) Seq(finagleService(service, namespace)) else Seq()
),
- "withFinagle" -> v(withFinagle),
- "date" -> codify(generationDate)
+ "withFinagle" -> v(withFinagle)
)
}
}
View
13 scrooge-generator/src/main/scala/com/twitter/scrooge/backend/StructTemplate.scala
@@ -132,6 +132,16 @@ trait StructTemplate {
"isPrimitive" -> v(isPrimitive(field.fieldType)),
"primitiveFieldType" -> genPrimitiveType(field.fieldType, mutable = false),
"fieldType" -> genType(field.fieldType, mutable = false),
+ "fieldKeyType" -> v(field.fieldType match {
+ case MapType(keyType, _, _) => Some(genType(keyType))
+ case _ => None
+ }),
+ "fieldValueType" -> v(field.fieldType match {
+ case MapType(_, valueType, _) => Some(genType(valueType))
+ case ListType(valueType, _) => Some(genType(valueType))
+ case SetType(valueType, _) => Some(genType(valueType))
+ case _ => None
+ }),
"isImported" -> v(field.fieldType match {
case n: NamedType => n.scopePrefix.isDefined
case _ => false
@@ -271,8 +281,7 @@ trait StructTemplate {
"arity1" -> v((if (arity == 1) fieldDictionaries.take(1) else Nil)),
"arityN" -> v(arity > 1 && arity <= 22),
"withFieldGettersAndSetters" -> v(isStruct || isException),
- "withTrait" -> v(isStruct),
- "date" -> codify(generationDate)
+ "withTrait" -> v(isStruct)
)
}
}
View
4 scrooge-generator/src/main/scala/com/twitter/scrooge/frontend/ParseException.scala
@@ -14,6 +14,10 @@ class DuplicateFieldIdException(name: String)
class RepeatingEnumValueException(name: String, value: Int)
extends ParseException("Repeating enum value in " + name + ": " + value)
+class UnionFieldInvalidNameException(union: String, field: String)
+ extends ParseException("Field " + field + " in union " + union + " is prohibited")
+
+
// warnings (non-severe errors). If the strict mode is on, Scrooge will throw these exceptions;
// otherwise it merely prints warnings.
class ParseWarning(reason: String, cause: Throwable)
View
7 scrooge-generator/src/main/scala/com/twitter/scrooge/frontend/ThriftParser.scala
@@ -295,10 +295,15 @@ class ThriftParser(
Struct(sid, sid.name, fixFieldIds(fields), comment, annotations)
}
+ private[this] val disallowedUnionFieldNames = Set("unknown_union_field", "unknownunionfield") map { _.toLowerCase }
+
lazy val union = structLike("union") ^^ {
case comment ~ sid ~ fields ~ annotations =>
val fields0 = fields.map {
- case f @ Field(_, _, _, _, _, r, _, _) if r == Requiredness.Default => f
+ case f @ Field(_, _, _, _, _, r, _, _) if r == Requiredness.Default =>
+ if (disallowedUnionFieldNames.contains(f.sid.name.toLowerCase)) {
+ throw new UnionFieldInvalidNameException(sid.name, f.sid.name)
+ } else f
case f @ _ =>
failOrWarn(UnionFieldRequirednessException(sid.name, f.sid.name, f.requiredness.toString))
f.copy(requiredness = Requiredness.Default)
View
1 ...oge-generator/src/main/scala/com/twitter/scrooge/java_generator/ApacheJavaGenerator.scala
@@ -20,7 +20,6 @@ object ApacheJavaGeneratorFactory extends GeneratorFactory {
def apply(
includeMap: Map[String, ResolvedDocument],
defaultNamespace: String,
- generationDate: String,
experimentFlags: Seq[String]
): ThriftGenerator = new ApacheJavaGenerator(includeMap, defaultNamespace)
}
View
41 scrooge-generator/src/test/scala/com/twitter/scrooge/ThriftStructMetaDataSpec.scala
@@ -10,16 +10,18 @@ import thrift.test._
// generation and testing and anyway requires scrooge-runtime for
// tests.
class ThriftStructMetaDataSpec extends Spec {
+ val metaData = XtructColl.metaData
+ val fields = metaData.fields.sortBy(_.id)
+
"Provide useful metadata" in {
val s = XtructColl(Map(1 -> 2L), Seq("test"), Set(10.toByte), 123)
- val metaData = XtructColl.metaData
assert(metaData.codecClass == XtructColl.getClass) // mustEqual doesn't work here
metaData.structClassName must be("thrift.test.XtructColl")
metaData.structName must be("XtructColl")
metaData.structClass must be(classOf[XtructColl])
- val Seq(f1, f2, f3, f4) = metaData.fields.sortBy(_.id)
+ val Seq(f1, f2, f3, f4) = fields
f1.name must be("a_map")
f1.id must be(1)
@@ -45,4 +47,39 @@ class ThriftStructMetaDataSpec extends Spec {
f4.manifest must be(Some(implicitly[Manifest[Int]]))
f4.getValue[Int](s) must be(123)
}
+
+ "fieldInfos" in {
+ (XtructColl.fieldInfos zip fields).foreach { pairs =>
+ val (info, field) = pairs
+ info.tfield.name must be(field.name)
+ // All of the XtructColl fields are required
+ info.isOptional must be(false)
+
+ field.id match {
+ case 1 =>
+ info.manifest must be(implicitly[Manifest[Map[Int, Long]]])
+ info.keyManifest must be(Some(implicitly[Manifest[Int]]))
+ info.valueManifest must be(Some(implicitly[Manifest[Long]]))
+ case 2 =>
+ info.manifest must be(implicitly[Manifest[Seq[String]]])
+ info.keyManifest must be(None)
+ info.valueManifest must be(Some(implicitly[Manifest[String]]))
+ case 3 =>
+ info.manifest must be(implicitly[Manifest[Set[Byte]]])
+ info.keyManifest must be(None)
+ info.valueManifest must be(Some(implicitly[Manifest[Byte]]))
+ case 4 =>
+ info.manifest must be(implicitly[Manifest[Int]])
+ info.keyManifest must be(None)
+ info.valueManifest must be(None)
+ case _ =>
+ throw new Exception("Unexpected field")
+ }
+ }
+
+ // All of the OneOfEachOptional fields are optional:
+ OneOfEachOptional.fieldInfos.foreach { fieldInfo =>
+ fieldInfo.isOptional must be(true)
+ }
+ }
}
View
5 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/GeneratorFactorySpec.scala
@@ -8,15 +8,14 @@ class TestGeneratorFactory extends GeneratorFactory {
def apply(
includeMap: Map[String, ResolvedDocument],
defaultNamespace: String,
- generationDate: String,
experimentFlags: Seq[String]
- ): ThriftGenerator = new ScalaGenerator(includeMap, defaultNamespace, generationDate, experimentFlags)
+ ): ThriftGenerator = new ScalaGenerator(includeMap, defaultNamespace, experimentFlags)
}
class GeneratorFactorySpec extends Spec {
"GeneratorFactory" should {
"be loadable" in {
- val generator = Generator("test", Map.empty[String, ResolvedDocument], "", "", Seq.empty[String])
+ val generator = Generator("test", Map.empty[String, ResolvedDocument], "", Seq.empty[String])
generator.isInstanceOf[ScalaGenerator] must be(true)
}
}
View
17 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/JavaGeneratorSpec.scala
@@ -574,6 +574,23 @@ class JavaGeneratorSpec extends JMockSpec with EvalHelper {
// no write test because it's not possible
}
+ "unknown field" should {
+ "read as unknown" in { _ =>
+ val prot = new TBinaryProtocol(new TMemoryBuffer(64))
+ val unionField = new NewUnionField(
+ 14653230,
+ new SomeInnerUnionStruct(26, "a_a")
+ )
+ val newUnion = UnionPostEvolution.newNewField(unionField)
+ UnionPostEvolution.encode(newUnion, prot)
+ val decoded = UnionPreEvolution.decode(prot)
+
+ // work around weird error when trying to reference java enums from scala.
+ // java.lang.AssertionError: thrift/java_test/UnionPreEvolution$AnotherName already declared as ch.epfl.lamp.fjbg.JInnerClassesAttribute$Entry@3ac8b10
+ decoded.setField.toString must be("UNKNOWN_UNION_VALUE")
+ }
+ }
+
"nested struct" should {
"read" in { cycle => import cycle._
val protocol = mock[TProtocol]
View
18 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/ScalaGeneratorSpec.scala
@@ -141,6 +141,23 @@ class ScalaGeneratorSpec extends JMockSpec with EvalHelper {
EnumUnion.decode(prot) must be(eUnion)
}
+ "encode-decode union with unknown field" in { _ =>
+ val prot = new TBinaryProtocol(new TMemoryBuffer(64))
+ val unionField = NewUnionField(
+ 14653230,
+ SomeInnerUnionStruct(26, "a_a")
+ )
+ val newUnion = UnionPostEvolution.NewField(unionField)
+ UnionPostEvolution.encode(newUnion, prot)
+ val decoded = UnionPreEvolution.decode(prot)
+ decoded.isInstanceOf[UnionPreEvolution.UnknownUnionField] must be(true)
+
+ val oldProt = new TBinaryProtocol(new TMemoryBuffer(64))
+ UnionPreEvolution.encode(decoded, oldProt)
+ val decodedNew = UnionPostEvolution.decode(oldProt)
+ decodedNew must be(UnionPostEvolution.NewField(unionField))
+ }
+
"be identified as an ENUM" in { _ =>
EnumStruct.NumberField.`type` must be(TType.ENUM)
}
@@ -843,6 +860,7 @@ class ScalaGeneratorSpec extends JMockSpec with EvalHelper {
candy.brand must be("Hershey")
candy.count must be(10)
candy.headline must be("Life is short, eat dessert first")
+ candy.defaultCandyType.value must be(0)
}
"hide internal helper function to avoid naming conflict" in { _ =>
View
12 scrooge-generator/src/test/scala/com/twitter/scrooge/frontend/ThriftParserSpec.scala
@@ -214,6 +214,18 @@ enum Foo
Field(3, SimpleID("g"), "g", ReferenceType(Identifier("Glider")), None, Requiredness.Default)
), None, Map.empty))
}
+
+ "invalid field name" in {
+ intercept[UnionFieldInvalidNameException] {
+ parser.parse("""
+ union Fruit {
+ 1: Apple apple
+ 2: Banana banana
+ 3: UnknownFruit unknown_union_field
+ }
+ """, parser.definition)
+ }
+ }
}
"exception" in {
View
1 scrooge-generator/src/test/thrift/relative/candy.thrift
@@ -22,4 +22,5 @@ struct Candy {
3: string headline = include1.HEADLINE
4: optional string brand = include2.BRAND
5: i32 count = include3.PIECES
+ 6: CandyType default_candy_type = CandyType.OLD
}
View
24 scrooge-generator/src/test/thrift/standalone/union.thrift
@@ -0,0 +1,24 @@
+namespace java thrift.test
+
+struct OldUnionField {
+ 1: i64 oldValue
+}
+
+struct SomeInnerUnionStruct {
+ 1: i32 anInt
+ 2: string aString
+}
+
+struct NewUnionField {
+ 1: i32 newValue
+ 2: SomeInnerUnionStruct innerStruct
+}
+
+union UnionPreEvolution {
+ 1: OldUnionField oldField
+}
+
+union UnionPostEvolution {
+ 1: OldUnionField oldField
+ 2: NewUnionField newField
+}
View
4 scrooge-maven-plugin/pom.xml
@@ -5,7 +5,7 @@
<artifactId>scrooge-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<name>scrooge-maven-plugin</name>
- <version>3.12.2</version>
+ <version>3.12.3</version>
<prerequisites>
<maven>2.0.6</maven>
</prerequisites>
@@ -217,7 +217,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-generator_2.9.2</artifactId>
- <version>3.12.2</version>
+ <version>3.12.3</version>
</dependency>
</dependencies>
<reporting>
View
10 scrooge-maven-plugin/src/main/java/com/twitter/AbstractMavenScroogeMojo.java
@@ -219,6 +219,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {
Set<File> includes = thriftIncludes;
includes.add(getResourcesOutputDirectory());
+ // Include thrift root
+ final File thriftSourceRoot = getThriftSourceRoot();
+ if (thriftSourceRoot != null && thriftSourceRoot.exists()) {
+ includes.add(thriftSourceRoot);
+ }
+
runner.compile(
getLog(),
new File(outputDirectory, "scrooge"),
@@ -317,7 +323,9 @@ private long lastModified(Set<File> files) {
// This artifact is on the whitelist directly.
if (whitelist.contains(artifact.getArtifactId())) {
thriftDependencies.add(artifact);
-
+ // This artifact has an IDL classifier, whitelist it
+ } else if ("idl".equalsIgnoreCase(artifact.getClassifier())) {
+ thriftDependencies.add(artifact);
// Check if this artifact is being pulled in by an idl jar that's been whitelisted
} else {
List<String> depTrail = artifact.getDependencyTrail();
View
6 scrooge-ostrich/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>scrooge-ostrich</artifactId>
<packaging>jar</packaging>
- <version>3.12.3-SNAPSHOT</version>
+ <version>3.12.4-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -20,12 +20,12 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>finagle-thrift</artifactId>
- <version>6.11.2-SNAPSHOT</version>
+ <version>6.12.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>finagle-ostrich4</artifactId>
- <version>6.11.2-SNAPSHOT</version>
+ <version>6.12.2-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
View
6 scrooge-runtime/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>scrooge-runtime</artifactId>
<packaging>jar</packaging>
- <version>3.12.3-SNAPSHOT</version>
+ <version>3.12.4-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -20,12 +20,12 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-core</artifactId>
- <version>3.12.3-SNAPSHOT</version>
+ <version>3.12.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>finagle-thrift</artifactId>
- <version>6.11.2-SNAPSHOT</version>
+ <version>6.12.2-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
View
4 scrooge-sbt-plugin/src/main/scala/com/twitter/ScroogeSBT.scala
@@ -108,8 +108,8 @@ object ScroogeSBT extends Plugin {
scroogeBuildOptions := Seq("--finagle"),
scroogeThriftSourceFolder <<= (sourceDirectory) { _ / "thrift" },
scroogeThriftExternalSourceFolder <<= (target) { _ / "thrift_external" },
- scroogeThriftOutputFolder <<= (sourceManaged) { x => x },
- scroogeThriftIncludeFolders := Seq(),
+ scroogeThriftOutputFolder <<= (sourceManaged) { identity },
+ scroogeThriftIncludeFolders <<= (scroogeThriftSourceFolder) { Seq(_) },
scroogeThriftNamespaceMap := Map(),
scroogeThriftDependencies := Seq(),
View
8 scrooge-serializer/pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>scrooge-serializer</artifactId>
<packaging>jar</packaging>
- <version>3.12.3-SNAPSHOT</version>
+ <version>3.12.4-SNAPSHOT</version>
<parent>
<groupId>com.twitter</groupId>
<artifactId>scala-parent-292</artifactId>
@@ -25,17 +25,17 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-codec</artifactId>
- <version>6.11.2-SNAPSHOT</version>
+ <version>6.12.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>util-core</artifactId>
- <version>6.11.2-SNAPSHOT</version>
+ <version>6.12.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-core</artifactId>
- <version>3.12.3-SNAPSHOT</version>
+ <version>3.12.4-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

0 comments on commit 327b67a

Please sign in to comment.