Permalink
Browse files

Merge branch 'sbt11'

  • Loading branch information...
2 parents 81d7f41 + 1736915 commit 5cd1e1cfeab6595ef926a9c7ba7c2b61ad43091b Robey Pointer committed Apr 10, 2012
View
4 README.rdoc
@@ -1,3 +1,7 @@
+This gem produces a skeleton finagled service directory to be used with the new SBT 0.11 and Scala 2.9.1
+
+-----
+
This creates a standard environment for your twitter-centric sbt/scala thrift service.
Building:
View
2 VERSION
@@ -1 +1 @@
-0.10.0
+0.11.0
View
19 bin/scala-bootstrapper
@@ -55,6 +55,8 @@ project_name = ARGV.pop.camelize(true)
is_public = opts[:public]
namespace = opts[:namespace] || "com.twitter"
git = opts[:git]
+sbt11_requested = opts[:sbt11]
+
$overwrite_all = true if git
$ex_post_facto = false
$branch = 'master'
@@ -95,12 +97,16 @@ Dir["#{root}/**/*"].select { |path| File.file?(path) }.each do |path|
print "File exists `#{relative}`, replace? ([Y]es, [N]o, [A]ll, [Q]uit)"
$stdout.flush
case STDIN.gets
- when /^y/i: # continue
- when /^n/i: next
- when /^a/i: $overwrite_all = true
- when /^q/i: exit(2)
+ when /^y/i
+ #continue
+ when /^n/i
+ next
+ when /^a/i
+ $overwrite_all = true
+ when /^q/i
+ exit(2)
else
- retry
+ redo
end
end
puts "writing #{target_path}"
@@ -117,9 +123,8 @@ end
[
"src/scripts/#{project_name.downcase}.sh",
- "src/scripts/console",
"src/scripts/devel.sh",
- "run"
+ "console",
].each do |executable|
`chmod +x #{executable}` if File.exists?(executable)
end
View
1 lib/template/Gemfile
@@ -5,4 +5,3 @@ gem "thrift_client", "0.6.2"
gem "thrift", "0.6"
gem "railsless-deploy"
gem "capistrano"
-gem "twitter-cap-utils", "~>0.8.0"
View
28 lib/template/build.sbt.erb
@@ -0,0 +1,28 @@
+import com.twitter.sbt._
+
+seq((
+ Project.defaultSettings ++
+ StandardProject.newSettings ++
+ SubversionPublisher.newSettings ++
+ CompileThriftScrooge.newSettings
+): _*)
+
+organization := "com.twitter"
+
+name := "birdname"
+
+version := "1.0.0-SNAPSHOT"
+
+libraryDependencies ++= Seq(
+ "org.scala-lang" % "jline" % "2.9.1",
+ "com.twitter" %% "scrooge-runtime" % "1.1.3",
+ "com.twitter" %% "finagle-core" % "2.0.1",
+ "com.twitter" %% "finagle-thrift" % "2.0.1",
+ "com.twitter" %% "finagle-ostrich4" % "2.0.1",
+ "org.scalatest" %% "scalatest" % "1.7.1" % "test",
+ "com.twitter" %% "scalatest-mixins" % "1.0.0" % "test"
+)
+
+mainClass in (Compile, run) := Some("com.twitter.birdname.Main")
+
+mainClass in (Compile, packageBin) := Some("com.twitter.birdname.Main")
View
2 lib/template/config/test.scala.erb
@@ -20,7 +20,7 @@ new BirdNameServiceConfig {
loggers =
new LoggerConfig {
- level = Level.INFO
+ level = Level.FATAL
handlers = new ConsoleHandlerConfig
}
}
View
8 lib/template/console.erb
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+if [ $# -lt 2 ] ; then
+ echo "usage: console <host> <port>"
+ exit 0
+fi
+
+sbt "run-main com.twitter.birdname.BirdNameConsoleClient $1 $2"
View
8 lib/template/project/build.properties
@@ -1,8 +0,0 @@
-#Project properties
-#Thu Feb 24 16:45:35 PST 2011
-project.organization=com.twitter
-project.name=birdname
-sbt.version=0.7.4
-project.version=1.0.0-SNAPSHOT
-build.scala.versions=2.8.1
-project.initialize=false
View
41 lib/template/project/build/BirdNameProject.scala.erb
@@ -1,41 +0,0 @@
-import sbt._
-import Process._
-import com.twitter.sbt._
-
-/**
- * Sbt project files are written in a DSL in scala.
- *
- * The % operator is just turning strings into maven dependency declarations, so lines like
- * val example = "com.example" % "exampleland" % "1.0.3"
- * mean to add a dependency on exampleland version 1.0.3 from provider "com.example".
- */
-class BirdNameProject(info: ProjectInfo) extends StandardServiceProject(info)
- with NoisyDependencies
- with DefaultRepos
- with SubversionPublisher
- with PublishSourcesAndJavadocs
- with PublishSite
- with CompileThriftRuby
- with CompileThriftScroogeMixin
-{
- val finagleVersion = "1.9.6"
-
- val finagleC = "com.twitter" % "finagle-core" % finagleVersion
- val finagleT = "com.twitter" % "finagle-thrift" % finagleVersion
- val finagleO = "com.twitter" % "finagle-ostrich4" % finagleVersion
-
- val scrooge_runtime = "com.twitter" % "scrooge-runtime" % "1.0.3"
- override def scroogeVersion = "2.2.0"
-
- // for tests
- val specs = "org.scala-tools.testing" % "specs_2.8.1" % "1.6.7" % "test" withSources()
- val jmock = "org.jmock" % "jmock" % "2.4.0" % "test"
- val hamcrest_all = "org.hamcrest" % "hamcrest-all" % "1.1" % "test"
- val cglib = "cglib" % "cglib" % "2.1_3" % "test"
- val asm = "asm" % "asm" % "1.5.3" % "test"
- val objenesis = "org.objenesis" % "objenesis" % "1.1" % "test"
-
- override def mainClass = Some("com.twitter.birdname.Main")
-
- override def subversionRepository = Some("http://svn.local.twitter.com/maven<%= '-public' if is_public %>")
-}
View
24 lib/template/project/plugins.sbt
@@ -0,0 +1,24 @@
+sbtResolver <<= (sbtResolver) { r =>
+ Option(System.getenv("SBT_PROXY_REPO")) map { x =>
+ Resolver.url("proxy repo for sbt", url(x))(Resolver.ivyStylePatterns)
+ } getOrElse r
+}
+
+resolvers <<= (resolvers) { r =>
+ (Option(System.getenv("SBT_PROXY_REPO")) map { url =>
+ Seq("proxy-repo" at url)
+ } getOrElse {
+ r ++ Seq(
+ "twitter.com" at "http://maven.twttr.com/",
+ "scala-tools" at "http://scala-tools.org/repo-releases/",
+ "maven" at "http://repo1.maven.org/maven2/",
+ "freemarker" at "http://freemarker.sourceforge.net/maven2/"
+ )
+ }) ++ Seq("local" at ("file:" + System.getProperty("user.home") + "/.m2/repo/"))
+}
+
+externalResolvers <<= (resolvers) map identity
+
+addSbtPlugin("com.twitter" %% "sbt-package-dist" % "1.0.0")
+
+addSbtPlugin("com.twitter" %% "sbt11-scrooge" % "1.0.0")
View
25 lib/template/project/plugins/Plugins.scala.erb
@@ -1,25 +0,0 @@
-import sbt._
-
-class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
- import scala.collection.jcl
- val environment = jcl.Map(System.getenv())
- def isSBTOpenTwitter = environment.get("SBT_OPEN_TWITTER").isDefined
- def isSBTTwitter = environment.get("SBT_TWITTER").isDefined
-
- override def repositories = if (isSBTOpenTwitter) {
- Set("twitter.artifactory" at "http://artifactory.local.twitter.com/open-source/")
- } else if (isSBTTwitter) {
- Set("twitter.artifactory" at "http://artifactory.local.twitter.com/repo/")
- } else {
- super.repositories ++ Set(
- "twitter.com" at "http://maven.twttr.com/",
- "scala-tools" at "http://scala-tools.org/repo-releases/",
- "freemarker" at "http://freemarker.sourceforge.net/maven2/"
- )
- }
- override def ivyRepositories = Seq(Resolver.defaultLocal(None)) ++ repositories
-
- val standardProject = "com.twitter" % "standard-project" % "1.0.0"
- val sbtThrift = "com.twitter" % "sbt-thrift" % "2.0.1"
- val sbtScrooge = "com.twitter" % "sbt-scrooge" % "2.2.0"
-}
View
125 lib/template/run
@@ -1,125 +0,0 @@
-#!/bin/bash
-
-function path_append {
- _var=$1
- _path=$2
- eval "
- if [[ -z \"\$$_var\" ]] ; then
- export $_var=$_path
- elif ! echo \$$_var | egrep -q \"(^|:)$_path($|:)\" ; then
- export $_var=\$$_var:$_path
- fi"
-}
-
-function path_prepend() {
- _var=$1
- _path=$2
- eval "
- if [[ -z \"\$$_var\" ]] ; then
- export $_var=$_path
- elif ! echo \$$_var | egrep -q \"(^|:)$_path($|:)\" ; then
- export $_var=$_path:\$$_var
- fi"
-}
-
-function find_sbt_root {
- while [ ! -d project -a "x$PWD" != "x/" ] ; do
- cd ..
- done
-
- if [ "x$PWD" = "/" ]; then
- echo "couldn't find sbt project!" 1>&2
- exit 1
- fi
-
- echo $PWD
-}
-
-function ensure_java_bin_on_path {
- if [ -d "$JAVA_HOME" ]; then
- __java_bindir="$JAVA_HOME/bin"
- else
- __java_bindir=`which java | xargs readlink | xargs dirname`
- fi
-
- if [ -x "$__java_bindir/java" ]; then
- path_append PATH $__java_bindir
- else
- echo "Binary 'java' is not on the PATH, and JAVA_HOME is not set. Fix one of these."
- exit 1
- fi
-}
-
-function include {
- _var=$1
- _dir=$2
-
- for jar in $_dir/lib_managed/compile/*.jar; do
- path_append $_var $jar
- done
-
- for jar in $_dir/lib/*.jar; do
- path_append $_var $jar
- done
-
- path_append $_var $_dir/src/main/resources
- path_append $_var $_dir/target/classes
-}
-
-ensure_java_bin_on_path
-
-root=$(find_sbt_root)
-if [ $? -ne 0 ]; then
- exit 1
-fi
-
-if [ -z $project ]; then
- project="."
-fi
-
-set -- $(getopt i:ygdh: "$@")
-while [ $# -gt 0 ]; do
- case "$1" in
- -i)
- include CP $2
- ;;
- -y)
- JAVA_OPTS="-agentlib:yjpagent $JAVA_OPTS"
- ;;
- -g)
- GC_OPTS="-verbosegc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:/tmp/gc.log"
- ;;
- -d)
- JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n $JAVA_OPTS"
- ;;
- -h)
- path_prepend DYLD_LIBRARY_PATH $2
- JAVA_OPTS="-Xbootclasspath/a:$2 -agentlib:heapster $JAVA_OPTS"
- ;;
- --) shift; break;;
- esac
- shift
-done
-
-if [ $# -eq 0 ]; then
- echo "usage: $0 [-i INCLUDE] [-h HEAPSTER] [-ygd] CLASS ..." >&2
- echo " -i INCLUDE include in the classpath the project with the sbt root INCLUDE" >&2
- echo " -h HEAPSTER use heapster in the directory HEAPSTER" >&2
- echo " -y enable yourkit debugging" >&2
- echo " -g enable GC debugging/logging" >&2
- echo " -d enable JVM debugging" >&2
- exit 1
-fi
-
-## Set up the classpath. Scala base jars first.
-path_prepend CP $root/project/boot/scala-2.8.1/lib/scala-library.jar
-path_prepend CP $root/project/boot/scala-2.8.1/lib/scala-compiler.jar
-
-# This goes last:
-include CP $root
-
-# Disable IPv6
-export JAVA_OPTS="-Djava.net.preferIPv4Stack=true $JAVA_OPTS"
-
-export JAVA_OPTS="$JAVA_OPTS -server -Xmx2G -XX:MaxPermSize=256m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC $GC_OPTS"
-exec java $JAVA_OPTS -cp $CP "$@"
View
42 lib/template/src/main/scala/com/twitter/birdname/BirdNameConsoleClient.scala.erb
@@ -0,0 +1,42 @@
+package com.twitter.birdname
+
+import com.twitter.conversions.time._
+import com.twitter.finagle.builder.ClientBuilder
+import com.twitter.finagle.thrift.ThriftClientFramedCodec
+import java.net.InetSocketAddress
+import scala.tools.nsc.interpreter._
+import scala.tools.nsc.Settings
+
+object BirdNameConsoleClient extends App {
+ val service = ClientBuilder()
+ .hosts(new InetSocketAddress(args(0), args(1).toInt))
+ .codec(ThriftClientFramedCodec())
+ .hostConnectionLimit(1)
+ .tcpConnectTimeout(3.seconds)
+ .build()
+
+ val client = new BirdNameService.FinagledClient(service)
+
+ val intLoop = new ILoop()
+
+ Console.println("'client' is bound to your thrift client.")
+ intLoop.setPrompt("\nfinagle-client> ")
+
+ intLoop.settings = {
+ val s = new Settings(Console.println)
+ s.embeddedDefaults[BirdNameService.FinagledClient]
+ s.Yreplsync.value = true
+ s
+ }
+
+ intLoop.createInterpreter()
+ intLoop.in = new JLineReader(new JLineCompletion(intLoop))
+
+ intLoop.intp.beQuietDuring {
+ intLoop.intp.interpret("""def exit = println("Type :quit to resume program execution.")""")
+ intLoop.intp.bind(NamedParam("client", client))
+ }
+
+ intLoop.loop()
+ intLoop.closeInterpreter()
+}
View
1 lib/template/src/main/scala/com/twitter/birdname/BirdNameServiceImpl.scala.erb
@@ -5,7 +5,6 @@ import com.twitter.util._
import java.util.concurrent.Executors
import scala.collection.mutable
import config._
-import thrift._
class BirdNameServiceImpl(config: BirdNameServiceConfig) extends BirdNameService.ThriftServer {
val serverName = "BirdName"
View
18 lib/template/src/main/scala/com/twitter/birdname/Main.scala.erb
@@ -1,16 +1,22 @@
package com.twitter.birdname
import com.twitter.logging.Logger
-import com.twitter.ostrich.admin.RuntimeEnvironment
-import thrift._
+import com.twitter.ostrich.admin.{RuntimeEnvironment, ServiceTracker}
object Main {
private val log = Logger.get(getClass)
def main(args: Array[String]) {
- val env = RuntimeEnvironment(this, args)
- val service = env.loadRuntimeConfig[BirdNameService.ThriftServer]()
- service.start()
- log.info("BirdName %s started.", env.jarVersion)
+ val runtime = RuntimeEnvironment(this, args)
+ val server = runtime.loadRuntimeConfig[BirdNameService.ThriftServer]
+ try {
+ log.info("Starting BirdNameService")
+ server.start()
+ } catch {
+ case e: Exception =>
+ log.error(e, "Failed starting BirdNameService, exiting")
+ ServiceTracker.shutdown()
+ System.exit(1)
+ }
}
}
View
1 lib/template/src/main/scala/com/twitter/birdname/config/BirdNameServiceConfig.scala.erb
@@ -7,7 +7,6 @@ import com.twitter.logging.config._
import com.twitter.ostrich.admin.{RuntimeEnvironment, ServiceTracker}
import com.twitter.ostrich.admin.config._
import com.twitter.util.Config
-import thrift._
class BirdNameServiceConfig extends ServerConfig[BirdNameService.ThriftServer] {
var thriftPort: Int = 9999
View
2 lib/template/src/main/thrift/birdname.thrift.erb
@@ -1,4 +1,4 @@
-namespace java com.twitter.birdname.thrift
+namespace java com.twitter.birdname
namespace rb BirdName
/**
View
29 lib/template/src/scripts/console.erb
@@ -1,29 +0,0 @@
-#!/usr/bin/env ruby
-$: << File.dirname(__FILE__) + "/../../../target/gen-rb"
-
-require "rubygems"
-require "bundler/setup"
-
-require "thrift"
-require "thrift_client"
-require "bird_name_service"
-require "irb"
-
-class BirdNameClient < ThriftClient
- DEFAULTS = { :transport_wrapper => Thrift::FramedTransport }
- def initialize(servers = nil, options = {})
- if servers.nil? or servers.empty?
- STDERR.puts "No servers specified, using 127.0.0.1:9999"
- servers = ['127.0.0.1:9999']
- else
- servers = Array(servers)
- end
-
- super(BirdName::BirdNameService::Client, servers, DEFAULTS.merge(options))
- end
-end
-
-puts "Hint: the client is in the variable `$client`"
-$client = BirdNameClient.new ARGV.shift
-
-IRB.start
View
2 lib/template/src/scripts/devel.sh
@@ -1,3 +1,3 @@
#!/bin/bash
echo "Starting birdname in development mode..."
-java -server -Xmx1024m -Dstage=development -jar ./dist/birdname/birdname-@VERSION@.jar
+java -server -Xmx1024m -Dstage=development -jar ./dist/birdname/@DIST_NAME@-@VERSION@.jar
View
8 lib/template/src/test/scala/com/twitter/birdname/AbstractSpec.scala.erb
@@ -2,12 +2,12 @@ package com.twitter.birdname
import com.twitter.conversions.time._
import com.twitter.ostrich.admin._
+import com.twitter.scalatest.TestLogging
import com.twitter.util._
-import org.specs.Specification
-import thrift._
+import org.scalatest._
-abstract class AbstractSpec extends Specification {
- val env = RuntimeEnvironment(this, Array("-f", "config/test.scala"))
+abstract class AbstractSpec extends FunSpec with TestLogging {
+ lazy val env = RuntimeEnvironment(this, Array("-f", "config/test.scala"))
lazy val birdName = {
val out = env.loadRuntimeConfig[BirdNameService.ThriftServer]
View
8 lib/template/src/test/scala/com/twitter/birdname/BirdNameServiceSpec.scala.erb
@@ -1,14 +1,14 @@
package com.twitter.birdname
class BirdNameServiceSpec extends AbstractSpec {
- "BirdNameService" should {
+ describe("BirdNameService") {
// TODO: Please implement your own tests.
- "set a key, get a key" in {
+ it("sets a key, then gets it") {
birdName.put("name", "bluebird")()
- birdName.get("name")() mustEqual "bluebird"
- birdName.get("what?")() must throwA[Exception]
+ assert(birdName.get("name")() === "bluebird")
+ intercept[Exception] { birdName.get("what?")() }
}
}
}
View
29 scala-bootstrapper.gemspec
@@ -5,19 +5,20 @@
Gem::Specification.new do |s|
s.name = "scala-bootstrapper"
- s.version = "0.10.0"
+ s.version = "0.11.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Kyle Maxwell"]
s.date = "2011-11-18"
s.description = "Twitter scala project init"
s.email = "kmaxwell@twitter.com"
+ s.default_executable = "scala-bootstrapper"
s.executables = ["scala-bootstrapper"]
s.extra_rdoc_files = [
"LICENSE",
"README.rdoc"
]
- s.files = [
+ s.files = Dir.glob("lib/template/**/*") + [
".document",
"HACKING",
"LICENSE",
@@ -26,32 +27,10 @@ Gem::Specification.new do |s|
"Rakefile",
"VERSION",
"bin/scala-bootstrapper",
- "lib/template/.gitignore.erb",
- "lib/template/Capfile",
- "lib/template/Gemfile",
- "lib/template/README.md",
- "lib/template/TUTORIAL.md",
- "lib/template/config/development.scala.erb",
- "lib/template/config/production.scala.erb",
- "lib/template/config/staging.scala.erb",
- "lib/template/config/test.scala.erb",
- "lib/template/project/build.properties",
- "lib/template/project/build/BirdNameProject.scala.erb",
- "lib/template/project/plugins/Plugins.scala.erb",
- "lib/template/run",
- "lib/template/src/main/scala/com/twitter/birdname/BirdNameServiceImpl.scala.erb",
- "lib/template/src/main/scala/com/twitter/birdname/Main.scala.erb",
- "lib/template/src/main/scala/com/twitter/birdname/config/BirdNameServiceConfig.scala.erb",
- "lib/template/src/main/thrift/birdname.thrift.erb",
- "lib/template/src/scripts/console.erb",
- "lib/template/src/scripts/devel.sh",
- "lib/template/src/scripts/startup.sh",
- "lib/template/src/test/scala/com/twitter/birdname/AbstractSpec.scala.erb",
- "lib/template/src/test/scala/com/twitter/birdname/BirdNameServiceSpec.scala.erb",
"scala-bootstrapper.gemspec",
"vendor/trollop.rb"
]
- s.homepage = "http://github.com/fizx/scala-bootstrapper"
+ s.homepage = "http://github.com/twitter/scala-bootstrapper"
s.require_paths = ["lib"]
s.rubygems_version = "1.8.11"
s.summary = "Twitter scala project init"

0 comments on commit 5cd1e1c

Please sign in to comment.