Skip to content

Commit

Permalink
scrooge-sbt-plugin: Add additional SettingKeys
Browse files Browse the repository at this point in the history
Problem

Some of the possible settings that scrooge can take can't be passed in
via sbt.

Solution

Add sbt settings

Signed-off-by: Moses Nakamura <mnakamura@twitter.com>

RB_ID=837531
  • Loading branch information
jedesah authored and jenkins committed Jun 1, 2016
1 parent 70d030c commit 5979724
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions scrooge-sbt-plugin/src/main/scala/com/twitter/ScroogeSBT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.twitter.scrooge
import sbt._
import Keys._

import com.twitter.scrooge.backend.{WithFinagle, ServiceOption}
import java.io.File

object ScroogeSBT extends AutoPlugin {
Expand All @@ -17,7 +18,10 @@ object ScroogeSBT extends AutoPlugin {
thriftIncludes: Set[File],
namespaceMappings: Map[String, String],
language: String,
flags: Set[String]
flags: Set[ServiceOption],
disableStrict: Boolean,
scalaWarnOnJavaNSFallback: Boolean,
defaultNamespace: String
) {

val originalLoader: Option[ClassLoader] =
Expand All @@ -34,7 +38,11 @@ object ScroogeSBT extends AutoPlugin {
compiler.destFolder = outputDir.getPath
thriftIncludes.map { compiler.includePaths += _.getPath }
namespaceMappings.map { e => compiler.namespaceMappings.put(e._1, e._2) }
Main.parseOptions(compiler, flags.toSeq ++ thriftFiles.map { _.getPath })
compiler.flags ++= flags
compiler.thriftFiles ++= thriftFiles.map(_.getPath())
compiler.strict = !disableStrict
compiler.scalaWarnOnJavaNSFallback = scalaWarnOnJavaNSFallback
compiler.defaultNamespace = defaultNamespace
compiler.language = language.toLowerCase
compiler.run()
} finally {
Expand All @@ -52,8 +60,7 @@ object ScroogeSBT extends AutoPlugin {
}

object autoImport {

val scroogeBuildOptions = SettingKey[Seq[String]](
val scroogeBuildOptions = SettingKey[Seq[ServiceOption]](
"scrooge-build-options",
"command line args to pass to scrooge"
)
Expand All @@ -63,6 +70,21 @@ object ScroogeSBT extends AutoPlugin {
"Whether or not to publish thrift files in the jar"
)

val scroogeDisableStrict = SettingKey[Boolean](
"scrooge-disable-strict",
"issue warnings on non-severe parse errors instead of aborting"
)

val scroogeScalaWarnOnJavaNSFallback = SettingKey[Boolean](
"scrooge-scala-warn-on-java-fallback",
"Print a warning when the scala generator falls back to the java namespace"
)

val scroogeDefaultJavaNamespace = SettingKey[String](
"scrooge-default-java-namespace",
"Use <name> as default namespace if the thrift file doesn't define its own namespace. If this option is not specified either, then use \"thrift\" as default namespace"
)

val scroogeThriftDependencies = SettingKey[Seq[String]](
"scrooge-thrift-dependencies",
"artifacts to extract and compile thrift files from"
Expand Down Expand Up @@ -142,8 +164,11 @@ object ScroogeSBT extends AutoPlugin {
* e.g. inConfig(Assembly)(genThriftSettings)
*/
val genThriftSettings: Seq[Setting[_]] = Seq(
scroogeBuildOptions := Seq("--finagle"),
scroogeBuildOptions := Seq(WithFinagle),
scroogePublishThrift := false,
scroogeDisableStrict := false,
scroogeScalaWarnOnJavaNSFallback := false,
scroogeDefaultJavaNamespace := "thrift",
scroogeThriftSourceFolder <<= (sourceDirectory) { _ / "thrift" },
scroogeThriftExternalSourceFolder <<= (target) { _ / "thrift_external" },
scroogeThriftOutputFolder <<= (sourceManaged) { identity },
Expand Down Expand Up @@ -233,12 +258,15 @@ object ScroogeSBT extends AutoPlugin {
scroogeBuildOptions,
scroogeThriftIncludes,
scroogeThriftNamespaceMap,
scroogeLanguage
) map { (out, isDirty, sources, outputDir, opts, inc, ns, language) =>
scroogeLanguage,
scroogeDisableStrict,
scroogeScalaWarnOnJavaNSFallback,
scroogeDefaultJavaNamespace
) map { (out, isDirty, sources, outputDir, opts, inc, ns, language, disableStrict, warnOnJavaNSFallback, defaultNamespace) =>
// for some reason, sbt sometimes calls us multiple times, often with no source files.
if (isDirty && sources.nonEmpty) {
out.log.info("Generating scrooge thrift for %s ...".format(sources.mkString(", ")))
compile(out.log, outputDir, sources.toSet, inc.toSet, ns, language, opts.toSet)
compile(out.log, outputDir, sources.toSet, inc.toSet, ns, language, opts.toSet, disableStrict, warnOnJavaNSFallback, defaultNamespace)
}
(outputDir ** generatedExtensionPattern(language)).get.toSeq
},
Expand Down

0 comments on commit 5979724

Please sign in to comment.