Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: twitter/scrooge
...
head fork: twitter/scrooge
Checking mergeability… Don't worry, you can still create the pull request.
  • 13 commits
  • 20 files changed
  • 0 commit comments
  • 3 contributors
Showing with 115 additions and 63 deletions.
  1. +17 −0 CHANGELOG
  2. +1 −1  pom.xml
  3. +2 −2 scrooge-generator/pom.xml
  4. +1 −1  scrooge-generator/src/main/resources/javagen/consts.java
  5. +1 −1  scrooge-generator/src/main/resources/javagen/enum.java
  6. +1 −1  scrooge-generator/src/main/resources/javagen/service.java
  7. +1 −1  scrooge-generator/src/main/resources/javagen/struct.java
  8. +1 −1  scrooge-generator/src/main/resources/javagen/union.java
  9. +1 −1  scrooge-generator/src/main/resources/scalagen/consts.scala
  10. +2 −2 scrooge-generator/src/main/resources/scalagen/enum.scala
  11. +1 −1  scrooge-generator/src/main/resources/scalagen/finagleClientFunction.scala
  12. +1 −1  scrooge-generator/src/main/resources/scalagen/service.scala
  13. +24 −33 scrooge-generator/src/main/scala/com/twitter/scrooge/AST/Identifier.scala
  14. +21 −11 scrooge-generator/src/test/scala/com/twitter/scrooge/ASTSpec.scala
  15. +23 −0 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/ServiceGeneratorSpec.scala
  16. +6 −0 scrooge-generator/src/test/thrift/standalone/test.thrift
  17. +3 −2 scrooge-maven-plugin/demo/pom.xml
  18. +2 −2 scrooge-maven-plugin/pom.xml
  19. +5 −1 scrooge-maven-plugin/src/main/java/com/twitter/AbstractMavenScroogeMojo.java
  20. +1 −1  scrooge-runtime/pom.xml
View
17 CHANGELOG
@@ -1,8 +1,25 @@
+3.0.8 - 03/18/2013
+===============================================================================
+* When scrooge-maven-plugin extracts Thrift files from a dependency artifact, it
+ now puts them in a sub folder named after the artifact id. This way, the user
+ project can use same-named Thrift files from different artifacts.
+* Title case and camel case more consistent with previous version before 3.0.7
+ We still preserve consecutive upper cases but not in an all-up-case string, eg:
+ TBird (original) -> tBird (camel case) -> TBird (title case)
+ HTML (original) -> html (camel case) -> Html (title case)
+ Thanks to @erikvanoosten
+* Finagle client can throw exception on void function. Thanks to @brancek
+* Support documentation on enum values. Thanks to @erikvanoosten
+* Reorganizing test folder, and add Apache standard test
+
3.0.7 - 03/07/2013
===============================================================================
* All on-wire names in the Thrift messages are now consistent with
Apache generated code. This allows Scrooge generated services to exchange
Thrift messages with Apache generated services.
+* Title case ids now preserve consecutive upper case letters. Eg:
+ TBird (original) -> Tbird (old) -> TBird (now)
+ See test case in scrooge-generator/src/test/scala/com/twitter/scrooge/ASTSpec.scala
* scrooge-maven-plugin now enforces an explicit white list in <dependencyConfig>.
The old behavior is that if a dependency artifact has a "idl" classifier, we
will extract thrift files from it to compile. The new behavior is that the
View
2  pom.xml
@@ -4,7 +4,7 @@
<groupId>com.twitter</groupId>
<artifactId>scrooge</artifactId>
<packaging>pom</packaging>
- <version>3.0.8-SNAPSHOT</version>
+ <version>3.0.8</version>
<name>scrooge</name>
<url>http://github.com/twitter/scrooge</url>
<description>A Thrift generator for Scala</description>
View
4 scrooge-generator/pom.xml
@@ -8,7 +8,7 @@
<parent>
<groupId>com.twitter</groupId>
<artifactId>scrooge</artifactId>
- <version>3.0.8-SNAPSHOT</version>
+ <version>3.0.8</version>
</parent>
<properties>
<git.dir>${project.basedir}/../../.git</git.dir>
@@ -25,7 +25,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-runtime</artifactId>
- <version>3.0.8-SNAPSHOT</version>
+ <version>3.0.8</version>
<scope>test</scope>
</dependency>
<!-- library dependencies -->
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", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
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", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
public enum {{EnumName}} {
{{#values}}
{{valuedocstring}}
View
2  scrooge-generator/src/main/resources/javagen/service.java
@@ -46,7 +46,7 @@
{{/withOstrichServer}}
{{docstring}}
-@javax.annotation.Generated(value = "com.twitter.scrooge", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
public class {{ServiceName}} {
public interface Iface {{syncExtends}}{
{{#syncFunctions}}
View
2  scrooge-generator/src/main/resources/javagen/struct.java
@@ -17,7 +17,7 @@
import java.util.HashSet;
{{docstring}}
-@javax.annotation.Generated(value = "com.twitter.scrooge", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
public {{/public}}{{^public}}static {{/public}}class {{StructName}}{{#isException}} extends Exception{{/isException}} implements ThriftStruct {
private static final TStruct STRUCT = new TStruct("{{StructNameForWire}}");
{{#fields}}
View
2  scrooge-generator/src/main/resources/javagen/union.java
@@ -17,7 +17,7 @@
import java.util.HashSet;
{{docstring}}
-@javax.annotation.Generated(value = "com.twitter.scrooge", date = "{{date}}")
+@javax.annotation.Generated(value = "com.twitter.scrooge.Compiler", date = "{{date}}")
public {{/public}}{{^public}}static {{/public}}class {{StructName}} implements ThriftStruct {
private static final TStruct STRUCT = new TStruct("{{StructNameForWire}}");
{{#fields}}
View
2  scrooge-generator/src/main/resources/scalagen/consts.scala
@@ -1,6 +1,6 @@
package {{package}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
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"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
case object {{EnumName}} {
{{#values}}
{{valuedocstring}}
@@ -51,5 +51,5 @@ case object {{EnumName}} {
{{docstring}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
sealed trait {{EnumName}} extends ThriftEnum with Serializable
View
2  scrooge-generator/src/main/resources/scalagen/finagleClientFunction.scala
@@ -17,7 +17,7 @@ private[this] object {{__stats_name}} {
None
{{/hasThrows}}
{{#void}}
- Future.Done
+ exception.getOrElse(Future.Done)
{{/void}}
{{^void}}
exception.orElse(result.success.map(Future.value)).getOrElse(Future.exception(missingResult("{{clientFuncNameForWire}}")))
View
2  scrooge-generator/src/main/resources/scalagen/service.scala
@@ -34,7 +34,7 @@ import java.util.concurrent.atomic.AtomicReference
{{/withOstrichServer}}
{{docstring}}
-@javax.annotation.Generated(value = Array("com.twitter.scrooge"), date = "{{date}}")
+@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"), date = "{{date}}")
object {{ServiceName}} {
trait Iface {{syncExtends}}{
{{#syncFunctions}}
View
57 scrooge-generator/src/main/scala/com/twitter/scrooge/AST/Identifier.scala
@@ -1,6 +1,6 @@
package com.twitter.scrooge.ast
-import collection.mutable.StringBuilder
+import scala.collection.mutable
import com.twitter.scrooge.ScroogeInternalException
sealed abstract class Identifier extends IdNode {
@@ -38,42 +38,33 @@ object Identifier {
* is converted to upper case.
* - first character (non underscore char) is upper case if
* firstCharUp is true, lower case if false
- * - If there are consecutive upper case letters in the original
- * string, preserve the upper case.
+ * - first character of the second and following parts (text between underscores)
+ * is always in upper case
+ * - if a part is all upper case it is converted to lower case (except for first character),
+ * in other cases case is preserved
*
* Examples: (original, camel case, title case)
- * (genID, genID, GenID)
- * (_genID, _genID, _GenID)
- * (gen_id, genId, GenId)
+ * (gen_html_report, genHtmlReport, GenHtmlReport)
+ * (GEN_HTML_REPORT, genHtmlReport, GenHtmlReport)
+ * (Gen_HTMLReport, genHTMLReport, GenHTMLReport)
+ * (Gen_HTML_Report, genHtmlReport, GenHtmlReport)
+ * (GENHTMLREPORT, genhtmlreport, Genhtmlreport)
+ * (genhtmlreport, genhtmlreport, Genhtmlreport)
+ * (genHtmlReport, genHtmlReport, GenHtmlReport)
+ * (genHTMLReport, genHTMLReport, GenHtmlReport)
+ * (_genHtmlReport, _genHtmlReport, _GenHtmlReport)
*/
def toCamelCase(str: String, firstCharUp: Boolean = false): String = {
- val sb = new StringBuilder(str.length)
- // copy leading _
- val firstCharPos = str.indexWhere(c => c != '_')
- if (firstCharPos > 0)
- sb.append(str.substring(0, firstCharPos))
-
- // the first char
- if (firstCharPos < str.size) {
- val firstChar = str.charAt(firstCharPos)
- if (firstCharUp) sb.append(firstChar.toUpper)
- else sb.append(firstChar.toLower)
- }
-
- // the rest
- var lastWas_ = false
- for (c <- str.substring(firstCharPos + 1)) {
- if (c == '_')
- lastWas_ = true
- else {
- if (c.isUpper || lastWas_)
- sb.append(c.toUpper)
- else
- sb.append(c)
- lastWas_ = false
- }
- }
- sb.toString()
+ str.takeWhile(_ == '_') + str.
+ split('_').
+ filterNot(_.isEmpty).
+ zipWithIndex.map { case (part, ind) =>
+ val first = if (ind == 0 && !firstCharUp) part(0).toLower else part(0).toUpper
+ val isAllUpperCase = part.forall(_.isUpper)
+ val rest = if (isAllUpperCase) part.drop(1).toLowerCase else part.drop(1)
+ new mutable.StringBuilder(part.size).append(first).append(rest)
+ }.
+ mkString
}
}
View
32 scrooge-generator/src/test/scala/com/twitter/scrooge/ASTSpec.scala
@@ -41,17 +41,27 @@ class ASTSpec extends SpecificationWithJUnit {
"Identifier" should {
val simpleCases = List(
- "hello" ->("hello", "Hello"),
- "hello_world" ->("helloWorld", "HelloWorld"),
- "a_b_c_d" ->("aBCD", "ABCD"),
- "HELLO_WORLD" ->("hELLOWORLD", "HELLOWORLD"),
- "helloWorld" ->("helloWorld", "HelloWorld"),
- "hello_World" ->("helloWorld", "HelloWorld"),
- "HELLOWORLD" ->("hELLOWORLD", "HELLOWORLD"),
- "_Foo_bar" ->("_fooBar", "_FooBar"),
- "__foo_bar" ->("__fooBar", "__FooBar"),
- "ThriftClientRequestID" ->("thriftClientRequestID", "ThriftClientRequestID"),
- "TChatbirdKey"->("tChatbirdKey", "TChatbirdKey")
+ "hello" -> ("hello", "Hello"),
+ "hello_world" -> ("helloWorld", "HelloWorld"),
+ "a_b_c_d" -> ("aBCD", "ABCD"),
+ "HELLO_WORLD" -> ("helloWorld", "HelloWorld"),
+ "helloWorld" -> ("helloWorld", "HelloWorld"),
+ "hello_World" -> ("helloWorld", "HelloWorld"),
+ "HELLOWORLD" -> ("helloworld", "Helloworld"),
+ "_Foo_bar" -> ("_fooBar", "_FooBar"),
+ "__foo_bar" -> ("__fooBar", "__FooBar"),
+ "ThriftClientRequestID" -> ("thriftClientRequestID", "ThriftClientRequestID"),
+ "TChatbirdKey" -> ("tChatbirdKey", "TChatbirdKey"),
+ "gen_html_report" -> ("genHtmlReport", "GenHtmlReport"),
+ "GEN_HTML_REPORT" -> ("genHtmlReport", "GenHtmlReport"),
+ "Gen_HTMLReport" -> ("genHTMLReport", "GenHTMLReport"),
+ "Gen_HTML_Report" -> ("genHtmlReport", "GenHtmlReport"),
+ "GENHTMLREPORT" -> ("genhtmlreport", "Genhtmlreport"),
+ "genHTMLReport" -> ("genHTMLReport", "GenHTMLReport"),
+ "genhtmlreport" -> ("genhtmlreport", "Genhtmlreport"),
+ "genHtmlReport" -> ("genHtmlReport", "GenHtmlReport"),
+ "_genHtmlReport" -> ("_genHtmlReport", "_GenHtmlReport"),
+ "__genHtmlReport" -> ("__genHtmlReport", "__GenHtmlReport")
)
"camel case conversion" in {
simpleCases foreach {
View
23 scrooge-generator/src/test/scala/com/twitter/scrooge/backend/ServiceGeneratorSpec.scala
@@ -241,6 +241,17 @@ class ServiceGeneratorSpec extends SpecificationWithJUnit with EvalHelper with J
client.deliver("Boston")() mustEqual 42
}
+ "success void" in {
+ val request = encodeRequest("remove", ExceptionalService.remove$args(123))
+ val response = encodeResponse("remove", ExceptionalService.remove$result())
+
+ expect {
+ one(impl).remove(123) willReturn Future.Done
+ }
+
+ client.remove(123)() mustEqual ()
+ }
+
"exception" in {
val request = encodeRequest("deliver", ExceptionalService.deliver$args("Boston"))
val ex = Xception(1, "boom")
@@ -252,6 +263,18 @@ class ServiceGeneratorSpec extends SpecificationWithJUnit with EvalHelper with J
client.deliver("Boston")() must throwA[ThriftException](ex)
}
+
+ "void exception" in {
+ val request = encodeRequest("remove", ExceptionalService.remove$args(123))
+ val ex = Xception(1, "boom")
+ val response = encodeResponse("remove", ExceptionalService.remove$result(ex = Some(ex)))
+
+ expect {
+ one(impl).remove(123) willReturn Future.exception(ex)
+ }
+
+ client.remove(123)() must throwA[ThriftException](ex)
+ }
}
"correctly inherit traits across services" in {
View
6 scrooge-generator/src/test/thrift/standalone/test.thrift
@@ -300,6 +300,12 @@ service ExceptionalService {
2: Xception2 ex2
3: EmptyXception ex3
)
+
+ void remove(1: i32 id) throws (
+ 1: Xception ex
+ 2: Xception2 ex2
+ 3: EmptyXception ex3
+ )
}
service ThriftTest
View
5 scrooge-maven-plugin/demo/pom.xml
@@ -22,6 +22,7 @@
<groupId>com.twitter</groupId>
<artifactId>event-logger-thrift</artifactId>
<version>0.0.3</version>
+ <scope>provided</scope>
</dependency>
<!-- common library dependencies -->
@@ -64,7 +65,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-runtime</artifactId>
- <version>3.0.8-SNAPSHOT</version>
+ <version>3.0.8</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@@ -143,7 +144,7 @@
<plugin>
<groupId>com.twitter</groupId>
<artifactId>scrooge-maven-plugin</artifactId>
- <version>3.0.8-SNAPSHOT</version>
+ <version>3.0.8</version>
<configuration>
<thriftNamespaceMappings>
<thriftNamespaceMapping>
View
4 scrooge-maven-plugin/pom.xml
@@ -10,7 +10,7 @@
<parent>
<groupId>com.twitter</groupId>
<artifactId>scrooge</artifactId>
- <version>3.0.8-SNAPSHOT</version>
+ <version>3.0.8</version>
</parent>
<dependencyManagement>
<dependencies>
@@ -124,7 +124,7 @@
<dependency>
<groupId>com.twitter</groupId>
<artifactId>scrooge-generator</artifactId>
- <version>3.0.8-SNAPSHOT</version>
+ <version>3.0.8</version>
</dependency>
</dependencies>
<reporting>
View
6 scrooge-maven-plugin/src/main/java/com/twitter/AbstractMavenScroogeMojo.java
@@ -254,7 +254,11 @@ private long lastModified(Set<File> files) {
*/
private Set<Artifact> findThriftDependencies(Set<String> whitelist) throws IOException {
Set<Artifact> thriftDependencies = new HashSet<Artifact>();
- for(Artifact artifact : (Collection<Artifact>)project.getArtifacts()) {
+ Set<Artifact> allDependencies = new HashSet<Artifact>();
+ allDependencies.addAll(project.getArtifacts());
+ allDependencies.addAll(project.getDependencyArtifacts());
+
+ for(Artifact artifact : allDependencies) {
String artifactId = artifact.getArtifactId();
if (whitelist.contains(artifactId)) {
thriftDependencies.add(artifact);
View
2  scrooge-runtime/pom.xml
@@ -7,7 +7,7 @@
<parent>
<groupId>com.twitter</groupId>
<artifactId>scrooge</artifactId>
- <version>3.0.8-SNAPSHOT</version>
+ <version>3.0.8</version>
</parent>
<properties>
<git.dir>${project.basedir}/../../.git</git.dir>

No commit comments for this range

Something went wrong with that request. Please try again.