Permalink
Browse files

Adds a javax.annotation.Generated annotation to generated sources.

  • Loading branch information...
erikvanoosten committed Mar 15, 2013
1 parent 8301a76 commit a1e009037d82d9709e5e71b562e8e72f1dacccb2
@@ -5,6 +5,7 @@
import java.util.Map;
import java.util.Set;
+@javax.annotation.Generated(value = "com.twitter.scrooge", date = "{{date}}")
public final class Constants {
{{#constants}}
{{docstring}}
@@ -1,6 +1,7 @@
package {{package}};
{{docstring}}
+@javax.annotation.Generated(value = "com.twitter.scrooge", date = "{{date}}")
public enum {{EnumName}} {
{{#values}}
{{valuedocstring}}
@@ -46,6 +46,7 @@
{{/withOstrichServer}}
{{docstring}}
+@javax.annotation.Generated(value = "com.twitter.scrooge", date = "{{date}}")
public class {{ServiceName}} {
public interface Iface {{syncExtends}}{
{{#syncFunctions}}
@@ -17,6 +17,7 @@
import java.util.HashSet;
{{docstring}}
+@javax.annotation.Generated(value = "com.twitter.scrooge", date = "{{date}}")
public {{/public}}{{^public}}static {{/public}}class {{StructName}}{{#isException}} extends Exception{{/isException}} implements ThriftStruct {
private static final TStruct STRUCT = new TStruct("{{StructNameForWire}}");
{{#fields}}
@@ -17,6 +17,7 @@
import java.util.HashSet;
{{docstring}}
+@javax.annotation.Generated(value = "com.twitter.scrooge", date = "{{date}}")
public {{/public}}{{^public}}static {{/public}}class {{StructName}} implements ThriftStruct {
private static final TStruct STRUCT = new TStruct("{{StructNameForWire}}");
{{#fields}}
@@ -1,5 +1,6 @@
package {{package}}
+@javax.annotation.Generated(value = Array("com.twitter.scrooge"), date = "{{date}}")
object Constants {
{{#constants}}
{{docstring}}
@@ -3,6 +3,7 @@ package {{package}}
import com.twitter.scrooge.ThriftEnum
{{docstring}}
+@javax.annotation.Generated(value = Array("com.twitter.scrooge"), date = "{{date}}")
case object {{EnumName}} {
{{#values}}
{{valuedocstring}}
@@ -50,4 +51,5 @@ case object {{EnumName}} {
{{docstring}}
+@javax.annotation.Generated(value = Array("com.twitter.scrooge"), date = "{{date}}")
sealed trait {{EnumName}} extends ThriftEnum with Serializable
@@ -34,6 +34,7 @@ import java.util.concurrent.atomic.AtomicReference
{{/withOstrichServer}}
{{docstring}}
+@javax.annotation.Generated(value = Array("com.twitter.scrooge"), date = "{{date}}")
object {{ServiceName}} {
trait Iface {{syncExtends}}{
{{#syncFunctions}}
@@ -11,9 +11,11 @@ import scala.collection.mutable
import scala.collection.{Map, Set}
{{/public}}
+@javax.annotation.Generated(value = Array("com.twitter.scrooge"), date = "{{date}}")
sealed trait {{StructName}} extends {{parentType}}
{{docstring}}
+@javax.annotation.Generated(value = Array("com.twitter.scrooge"), date = "{{date}}")
object {{StructName}} extends ThriftStructCodec[{{StructName}}] {
val Union = new TStruct("{{StructNameForWire}}")
{{#fields}}
@@ -20,6 +20,8 @@ import scala.collection.mutable
import java.io.{File, FileWriter}
import com.twitter.scrooge.backend.{Generator, ServiceOption}
import com.twitter.scrooge.frontend.{ThriftParser, Importer}
+import org.apache.commons.lang.time.FastDateFormat
+import java.util.Date
object Language extends Enumeration {
type Language = Value
@@ -42,6 +44,7 @@ class Compiler {
var dryRun: Boolean = false
var language: Language = Scala
var defaultNamespace: String = "thrift"
+ 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.
@@ -65,7 +68,7 @@ class Compiler {
if (verbose) println("+ Compiling %s".format(inputFile))
val resolvedDoc = TypeResolver()(doc0)
- val generator = Generator(language, resolvedDoc.resolver.includeMap, defaultNamespace)
+ val generator = Generator(language, resolvedDoc.resolver.includeMap, defaultNamespace, now)
val generatedFiles = generator(
resolvedDoc.document,
flags.toSet,
@@ -19,6 +19,7 @@ trait ConstsTemplate {
"value" -> genConstant(c.value),
"docstring" -> codify(c.docstring.getOrElse(""))
)
- })
+ }),
+ "date" -> codify(generationDate)
)
}
@@ -22,6 +22,7 @@ trait EnumTemplate {
"nameLowerCase" -> genID(value.sid.toLowerCase),
"value" -> codify(value.value.toString)
)
- })
+ }),
+ "date" -> codify(generationDate)
)
}
@@ -36,10 +36,11 @@ object Generator {
def apply(
lan: Language,
includeMap: Map[String, ResolvedDocument],
- defaultNamespace: String
+ defaultNamespace: String,
+ generationDate: String
): Generator = lan match {
- case Scala => new ScalaGenerator(includeMap, defaultNamespace)
- case Java => new JavaGenerator(includeMap, defaultNamespace)
+ case Scala => new ScalaGenerator(includeMap, defaultNamespace, generationDate)
+ case Java => new JavaGenerator(includeMap, defaultNamespace, generationDate)
}
}
@@ -53,6 +54,7 @@ abstract class Generator
*/
val includeMap: Map[String, ResolvedDocument]
val defaultNamespace: String
+ val generationDate: String
/******************** helper functions ************************/
private[this] def namespacedFolder(destFolder: File, namespace: String, dryRun: Boolean) = {
@@ -22,7 +22,8 @@ import com.twitter.scrooge.mustache.Dictionary._
class JavaGenerator(
val includeMap: Map[String, ResolvedDocument],
- val defaultNamespace: String
+ val defaultNamespace: String,
+ val generationDate: String
) extends Generator
{
val fileExtension = ".java"
@@ -22,7 +22,8 @@ import com.twitter.scrooge.mustache.Dictionary._
class ScalaGenerator(
val includeMap: Map[String, ResolvedDocument],
- val defaultNamespace: String
+ val defaultNamespace: String,
+ val generationDate: String
) extends Generator
{
val fileExtension = ".scala"
@@ -202,7 +202,8 @@ trait ServiceTemplate {
"withFinagleService" -> v(s.options contains WithFinagleService),
"withOstrichServer" -> v(s.options contains WithOstrichServer),
"withFinagle" -> v((s.options contains WithFinagleClient)
- || (s.options contains WithFinagleService))
+ || (s.options contains WithFinagleService)),
+ "date" -> codify(generationDate)
)
}
}
@@ -264,7 +264,8 @@ trait StructTemplate {
"arity1" -> v((if (arity == 1) fieldDictionaries.take(1) else Nil)),
"arityN" -> v(arity > 1 && arity <= 22),
"withProxy" -> v(struct.isInstanceOf[Struct]),
- "withFinagleClient" -> v(serviceOptions contains WithFinagleClient)
+ "withFinagleClient" -> v(serviceOptions contains WithFinagleClient),
+ "date" -> codify(generationDate)
)
}
}

0 comments on commit a1e0090

Please sign in to comment.