scala-bootstrapper 0.7.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.0
1
+ 0.7.2
@@ -4,13 +4,13 @@ require File.dirname(__FILE__) + "/../vendor/trollop"
4
4
 
5
5
  opts = Trollop::options do
6
6
  banner "Usage: #{$0} [options] PROJECT_NAME"
7
-
8
- opt :public, "Use the public twitter maven repo"
7
+
8
+ opt :public, "Use the public twitter maven repo"
9
9
  opt :namespace, "Use something besides com.twitter", :type => :string
10
10
  end
11
11
 
12
12
 
13
- if ARGV.length < 1
13
+ if ARGV.length < 1
14
14
  Trollop::die "PROJECT_NAME is required"
15
15
  exit 1
16
16
  end
@@ -22,7 +22,7 @@ class String
22
22
  else
23
23
  self[0].chr.downcase + camelize(self)[1..-1]
24
24
  end
25
- end
25
+ end
26
26
  def underscore
27
27
  self.gsub(/::/, '/').
28
28
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
@@ -72,4 +72,8 @@ Dir["#{root}/**/*"].select{|path| File.file?(path)}.each do |path|
72
72
  puts "writing #{target_path}"
73
73
  mkdir_p(File.dirname(target_path))
74
74
  File.open(target_path, "w") {|f| f.print(gsub_birds(template.result(binding), project_name, namespace)) }
75
- end
75
+ end
76
+
77
+ if File.exists?("src/scripts/startup.sh")
78
+ `mv src/scripts/startup.sh src/scripts/#{project_name.downcase}.sh`
79
+ end
@@ -1,6 +1,6 @@
1
- import com.twitter.ostrich.admin.config._
2
1
  import com.twitter.conversions.time._
3
2
  import com.twitter.logging.config._
3
+ import com.twitter.ostrich.admin.config._
4
4
  import com.twitter.birdname.config._
5
5
 
6
6
  // development mode.
@@ -27,7 +27,7 @@ new BirdNameServiceConfig {
27
27
 
28
28
  loggers =
29
29
  new LoggerConfig {
30
- level = Level.INFO
30
+ level = Level.DEBUG
31
31
  handlers = new FileHandlerConfig {
32
32
  filename = "birdname.log"
33
33
  roll = Policy.SigHup
@@ -1,6 +1,6 @@
1
- import com.twitter.ostrich.admin.config._
2
1
  import com.twitter.conversions.time._
3
2
  import com.twitter.logging.config._
3
+ import com.twitter.ostrich.admin.config._
4
4
  import com.twitter.birdname.config._
5
5
 
6
6
  // production mode.
@@ -1,6 +1,6 @@
1
- import com.twitter.ostrich.admin.config._
2
1
  import com.twitter.conversions.time._
3
2
  import com.twitter.logging.config._
3
+ import com.twitter.ostrich.admin.config._
4
4
  import com.twitter.birdname.config._
5
5
 
6
6
  // test mode.
@@ -3,6 +3,6 @@
3
3
  project.organization=com.twitter
4
4
  project.name=birdname
5
5
  sbt.version=0.7.4
6
- project.version=1.0-SNAPSHOT
6
+ project.version=1.0.0-SNAPSHOT
7
7
  build.scala.versions=2.8.1
8
8
  project.initialize=false
@@ -2,9 +2,19 @@ import sbt._
2
2
  import Process._
3
3
  import com.twitter.sbt._
4
4
 
5
+ /**
6
+ * Sbt project files are written in a DSL in scala.
7
+ *
8
+ * The % operator is just turning strings into maven dependency declarations, so lines like
9
+ * val example = "com.example" % "exampleland" % "1.0.3"
10
+ * mean to add a dependency on exampleland version 1.0.3 from provider "com.example".
11
+ */
5
12
  class BirdNameProject(info: ProjectInfo) extends StandardServiceProject(info)
6
- with CompileThriftScala with NoisyDependencies with DefaultRepos with SubversionPublisher {
7
-
13
+ with CompileThriftScala
14
+ with NoisyDependencies
15
+ with DefaultRepos
16
+ with SubversionPublisher
17
+ {
8
18
  val finagleVersion = "1.2.1"
9
19
  val finagleC = "com.twitter" % "finagle-core" % finagleVersion
10
20
  val finagleT = "com.twitter" % "finagle-thrift" % finagleVersion
@@ -12,7 +22,6 @@ with CompileThriftScala with NoisyDependencies with DefaultRepos with Subversion
12
22
 
13
23
  // thrift
14
24
  val libthrift = "thrift" % "libthrift" % "0.5.0"
15
- val util = "com.twitter" % "util" % "1.8.0"
16
25
 
17
26
  override def originalThriftNamespaces = Map("BirdName" -> "com.twitter.birdname.thrift")
18
27
  val scalaThriftTargetNamespace = "com.twitter.birdname"
@@ -2,6 +2,6 @@ import sbt._
2
2
 
3
3
  class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
4
4
  val twitterMaven = "twitter.com" at "http://maven.twttr.com/"
5
- val defaultProject = "com.twitter" % "standard-project" % "0.11.1"
5
+ val standardProject = "com.twitter" % "standard-project" % "0.11.1"
6
6
  val sbtThrift = "com.twitter" % "sbt-thrift" % "1.1.0"
7
7
  }
data/lib/template/run ADDED
@@ -0,0 +1,125 @@
1
+ #!/bin/bash
2
+
3
+ function path_append {
4
+ _var=$1
5
+ _path=$2
6
+ eval "
7
+ if [[ -z \"\$$_var\" ]] ; then
8
+ export $_var=$_path
9
+ elif ! echo \$$_var | egrep -q \"(^|:)$_path($|:)\" ; then
10
+ export $_var=\$$_var:$_path
11
+ fi"
12
+ }
13
+
14
+ function path_prepend() {
15
+ _var=$1
16
+ _path=$2
17
+ eval "
18
+ if [[ -z \"\$$_var\" ]] ; then
19
+ export $_var=$_path
20
+ elif ! echo \$$_var | egrep -q \"(^|:)$_path($|:)\" ; then
21
+ export $_var=$_path:\$$_var
22
+ fi"
23
+ }
24
+
25
+ function find_sbt_root {
26
+ while [ ! -d project -a "x$PWD" != "x/" ] ; do
27
+ cd ..
28
+ done
29
+
30
+ if [ "x$PWD" = "/" ]; then
31
+ echo "couldn't find sbt project!" 1>&2
32
+ exit 1
33
+ fi
34
+
35
+ echo $PWD
36
+ }
37
+
38
+ function ensure_java_bin_on_path {
39
+ if [ -d "$JAVA_HOME" ]; then
40
+ __java_bindir="$JAVA_HOME/bin"
41
+ else
42
+ __java_bindir=`which java | xargs readlink | xargs dirname`
43
+ fi
44
+
45
+ if [ -x "$__java_bindir/java" ]; then
46
+ path_append PATH $__java_bindir
47
+ else
48
+ echo "Binary 'java' is not on the PATH, and JAVA_HOME is not set. Fix one of these."
49
+ exit 1
50
+ fi
51
+ }
52
+
53
+ function include {
54
+ _var=$1
55
+ _dir=$2
56
+
57
+ for jar in $_dir/lib_managed/compile/*.jar; do
58
+ path_append $_var $jar
59
+ done
60
+
61
+ for jar in $_dir/lib/*.jar; do
62
+ path_append $_var $jar
63
+ done
64
+
65
+ path_append $_var $_dir/src/main/resources
66
+ path_append $_var $_dir/target/classes
67
+ }
68
+
69
+ ensure_java_bin_on_path
70
+
71
+ root=$(find_sbt_root)
72
+ if [ $? -ne 0 ]; then
73
+ exit 1
74
+ fi
75
+
76
+ if [ -z $project ]; then
77
+ project="."
78
+ fi
79
+
80
+ set -- $(getopt i:ygdh: "$@")
81
+ while [ $# -gt 0 ]; do
82
+ case "$1" in
83
+ -i)
84
+ include CP $2
85
+ ;;
86
+ -y)
87
+ JAVA_OPTS="-agentlib:yjpagent $JAVA_OPTS"
88
+ ;;
89
+ -g)
90
+ GC_OPTS="-verbosegc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:/tmp/gc.log"
91
+ ;;
92
+ -d)
93
+ JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n $JAVA_OPTS"
94
+ ;;
95
+ -h)
96
+ path_prepend DYLD_LIBRARY_PATH $2
97
+ JAVA_OPTS="-Xbootclasspath/a:$2 -agentlib:heapster $JAVA_OPTS"
98
+ ;;
99
+ --) shift; break;;
100
+ esac
101
+ shift
102
+ done
103
+
104
+ if [ $# -eq 0 ]; then
105
+ echo "usage: $0 [-i INCLUDE] [-h HEAPSTER] [-ygd] CLASS ..." >&2
106
+ echo " -i INCLUDE include in the classpath the project with the sbt root INCLUDE" >&2
107
+ echo " -h HEAPSTER use heapster in the directory HEAPSTER" >&2
108
+ echo " -y enable yourkit debugging" >&2
109
+ echo " -g enable GC debugging/logging" >&2
110
+ echo " -d enable JVM debugging" >&2
111
+ exit 1
112
+ fi
113
+
114
+ ## Set up the classpath. Scala base jars first.
115
+ path_prepend CP $root/project/boot/scala-2.8.1/lib/scala-library.jar
116
+ path_prepend CP $root/project/boot/scala-2.8.1/lib/scala-compiler.jar
117
+
118
+ # This goes last:
119
+ include CP $root
120
+
121
+ # Disable IPv6
122
+ export JAVA_OPTS="-Djava.net.preferIPv4Stack=true $JAVA_OPTS"
123
+
124
+ export JAVA_OPTS="$JAVA_OPTS -server -Xmx2G -XX:MaxPermSize=256m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC $GC_OPTS"
125
+ exec java $JAVA_OPTS -cp $CP "$@"
@@ -1,7 +1,8 @@
1
1
  package com.twitter.birdname
2
2
 
3
- import com.twitter.util._
4
3
  import java.util.concurrent.Executors
4
+ import scala.collection.mutable
5
+ import com.twitter.util._
5
6
  import config._
6
7
 
7
8
  class BirdNameServiceImpl(config: BirdNameServiceConfig) extends BirdNameServiceServer {
@@ -22,11 +23,23 @@ class BirdNameServiceImpl(config: BirdNameServiceConfig) extends BirdNameService
22
23
  * }
23
24
  *
24
25
  */
25
-
26
- // TODO: Please implement your api. You should have already created your thrift definition.
27
-
28
- def hello() = {
29
- Future("world")
26
+
27
+ val database = new mutable.HashMap[String, String]()
28
+
29
+ def get(key: String) = {
30
+ database.get(key) match {
31
+ case None =>
32
+ log.debug("get %s: miss", key)
33
+ Future.exception(new BirdNameException("No such key"))
34
+ case Some(value) =>
35
+ log.debug("get %s: hit", key)
36
+ Future(value)
37
+ }
30
38
  }
31
39
 
32
- }
40
+ def put(key: String, value: String) = {
41
+ log.debug("put %s")
42
+ database(key) = value
43
+ Future.void
44
+ }
45
+ }
@@ -1,6 +1,6 @@
1
1
  package com.twitter.birdname
2
2
 
3
- import com.twitter.ostrich.admin._
3
+ import com.twitter.ostrich.admin.RuntimeEnvironment
4
4
 
5
5
  object Main {
6
6
  def main(args: Array[String]) {
@@ -1,10 +1,11 @@
1
1
  package com.twitter.birdname
2
2
  package config
3
3
 
4
- import com.twitter.ostrich.admin.{RuntimeEnvironment, ServiceTracker}
5
- import com.twitter.ostrich.admin.config._
6
4
  import com.twitter.logging.Logger
7
5
  import com.twitter.logging.config._
6
+ import com.twitter.ostrich.admin.{RuntimeEnvironment, ServiceTracker}
7
+ import com.twitter.ostrich.admin.config._
8
+ import com.twitter.util.Config
8
9
 
9
10
  class BirdNameServiceConfig extends ServerConfig[BirdNameServiceServer] {
10
11
  var thriftPort: Int = 9999
@@ -1,12 +1,20 @@
1
1
  namespace java com.twitter.birdname.thrift
2
2
  namespace rb BirdName
3
3
 
4
+ /**
5
+ * It's considered good form to declare an exception type for your service.
6
+ * Thrift will serialize and transmit them transparently.
7
+ */
4
8
  exception BirdNameException {
5
9
  1: string description
6
10
  }
7
11
 
12
+ /**
13
+ * A simple memcache-like service, which stores strings by key/value.
14
+ * You should replace this with your actual service.
15
+ */
8
16
  service BirdNameService {
9
- // TODO: Please implement your externally accessible API
10
-
11
- string hello() throws(1: BirdNameException ex)
12
- }
17
+ string get(1: string key) throws(1: BirdNameException ex)
18
+
19
+ void put(1: string key, 2: string value)
20
+ }
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- $: << File.dirname(__FILE__) + "/../target/gen-rb"
2
+ $: << File.dirname(__FILE__) + "/../../../target/gen-rb"
3
3
 
4
4
  require "rubygems"
5
5
  require "bundler/setup"
@@ -0,0 +1,136 @@
1
+ #!/bin/sh
2
+ #
3
+ # birdname init.d script.
4
+ #
5
+ # All java services require the same directory structure:
6
+ # /usr/local/$APP_NAME
7
+ # /var/log/$APP_NAME
8
+ # /var/run/$APP_NAME
9
+
10
+ APP_NAME="birdname"
11
+ ADMIN_PORT="9900"
12
+ VERSION="@VERSION@"
13
+ APP_HOME="/usr/local/$APP_NAME/current"
14
+ DAEMON="/usr/local/bin/daemon"
15
+
16
+ JAR_NAME="$APP_NAME-$VERSION.jar"
17
+ STAGE="production"
18
+
19
+ HEAP_OPTS="-Xmx4096m -Xms4096m -XX:NewSize=768m"
20
+ GC_OPTS="-verbosegc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+UseConcMarkSweepGC -XX:+UseParNewGC"
21
+ GC_LOG="-Xloggc:/var/log/$APP_NAME/gc.log"
22
+ DEBUG_OPTS="-XX:ErrorFile=/var/log/$APP_NAME/java_error%p.log"
23
+ JAVA_OPTS="-server -Dstage=$STAGE $GC_OPTS $GC_LOG $HEAP_OPTS $DEBUG_OPTS"
24
+
25
+ pidfile="/var/run/$APP_NAME/$APP_NAME.pid"
26
+ daemon_pidfile="/var/run/$APP_NAME/$APP_NAME-daemon.pid"
27
+ daemon_args="--name $APP_NAME --pidfile $daemon_pidfile --core --chdir /"
28
+ daemon_start_args="--stdout=/var/log/$APP_NAME/stdout --stderr=/var/log/$APP_NAME/error"
29
+
30
+ function running() {
31
+ $DAEMON $daemon_args --running
32
+ }
33
+
34
+ function find_java() {
35
+ if [ ! -z "$JAVA_HOME" ]; then
36
+ return
37
+ fi
38
+ for dir in /opt/jdk /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home /usr/java/default; do
39
+ if [ -x $dir/bin/java ]; then
40
+ JAVA_HOME=$dir
41
+ break
42
+ fi
43
+ done
44
+ }
45
+
46
+ find_java
47
+
48
+
49
+ case "$1" in
50
+ start)
51
+ echo -n "Starting $APP_NAME... "
52
+
53
+ if [ ! -r $APP_HOME/$JAR_NAME ]; then
54
+ echo "FAIL"
55
+ echo "*** $APP_NAME jar missing: $APP_HOME/$JAR_NAME - not starting"
56
+ exit 1
57
+ fi
58
+ if [ ! -x $JAVA_HOME/bin/java ]; then
59
+ echo "FAIL"
60
+ echo "*** $JAVA_HOME/bin/java doesn't exist -- check JAVA_HOME?"
61
+ exit 1
62
+ fi
63
+ if running; then
64
+ echo "already running."
65
+ exit 0
66
+ fi
67
+
68
+ ulimit -c unlimited || echo -n " (no coredump)"
69
+ $DAEMON $daemon_args $daemon_start_args -- sh -c "echo "'$$'" > $pidfile; exec ${JAVA_HOME}/bin/java ${JAVA_OPTS} -jar ${APP_HOME}/${JAR_NAME}"
70
+ tries=0
71
+ while ! running; do
72
+ tries=$((tries + 1))
73
+ if [ $tries -ge 5 ]; then
74
+ echo "FAIL"
75
+ exit 1
76
+ fi
77
+ sleep 1
78
+ done
79
+ echo "done."
80
+ ;;
81
+
82
+ stop)
83
+ echo -n "Stopping $APP_NAME... "
84
+ if ! running; then
85
+ echo "wasn't running."
86
+ exit 0
87
+ fi
88
+
89
+ curl -s http://localhost:${ADMIN_PORT}/shutdown.txt > /dev/null
90
+ tries=0
91
+ while running; do
92
+ tries=$((tries + 1))
93
+ if [ $tries -ge 15 ]; then
94
+ echo "FAILED SOFT SHUTDOWN, TRYING HARDER"
95
+ if [ -f $pidfile ]; then
96
+ kill $(cat $pidfile)
97
+ else
98
+ echo "CAN'T FIND PID, TRY KILL MANUALLY"
99
+ exit 1
100
+ fi
101
+ hardtries=0
102
+ while running; do
103
+ hardtries=$((hardtries + 1))
104
+ if [ $hardtries -ge 5 ]; then
105
+ echo "FAILED HARD SHUTDOWN, TRY KILL -9 MANUALLY"
106
+ exit 1
107
+ fi
108
+ sleep 1
109
+ done
110
+ fi
111
+ sleep 1
112
+ done
113
+ echo "done."
114
+ ;;
115
+
116
+ status)
117
+ if running; then
118
+ echo "$APP_NAME is running."
119
+ else
120
+ echo "$APP_NAME is NOT running."
121
+ fi
122
+ ;;
123
+
124
+ restart)
125
+ $0 stop
126
+ sleep 2
127
+ $0 start
128
+ ;;
129
+
130
+ *)
131
+ echo "Usage: /etc/init.d/${APP_NAME}.sh {start|stop|restart|status}"
132
+ exit 1
133
+ ;;
134
+ esac
135
+
136
+ exit 0
@@ -15,4 +15,4 @@ abstract class AbstractSpec extends Specification {
15
15
  ServiceTracker.shutdown // all services
16
16
  out
17
17
  }
18
- }
18
+ }
@@ -3,10 +3,12 @@ package com.twitter.birdname
3
3
  class BirdNameServiceSpec extends AbstractSpec {
4
4
  "BirdNameService" should {
5
5
 
6
- // TODO: Please implement your own tests
6
+ // TODO: Please implement your own tests.
7
7
 
8
- "hello world" in {
9
- birdName.hello.get() mustEqual "world"
8
+ "set a key, get a key" in {
9
+ birdName.put("name", "bluebird")()
10
+ birdName.get("name")() mustEqual "bluebird"
11
+ birdName.get("what?")() must throwA[Exception]
10
12
  }
11
13
  }
12
- }
14
+ }
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scala-bootstrapper
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 7
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 7
8
- - 0
9
- version: 0.7.0
9
+ - 2
10
+ version: 0.7.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Kyle Maxwell
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-03-11 00:00:00 -08:00
18
+ date: 2011-03-20 00:00:00 -07:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: thoughtbot-shoulda
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
@@ -41,7 +44,6 @@ extra_rdoc_files:
41
44
  - README.rdoc
42
45
  files:
43
46
  - .document
44
- - .gitignore
45
47
  - LICENSE
46
48
  - README.rdoc
47
49
  - Rakefile
@@ -51,7 +53,6 @@ files:
51
53
  - lib/template/.gitignore
52
54
  - lib/template/Capfile
53
55
  - lib/template/Gemfile
54
- - lib/template/bin/console.erb
55
56
  - lib/template/config/development.scala.erb
56
57
  - lib/template/config/production.scala.erb
57
58
  - lib/template/config/staging.scala.erb
@@ -59,10 +60,13 @@ files:
59
60
  - lib/template/project/build.properties
60
61
  - lib/template/project/build/BirdNameProject.scala.erb
61
62
  - lib/template/project/plugins/Plugins.scala.erb
63
+ - lib/template/run
62
64
  - lib/template/src/main/scala/com/twitter/birdname/BirdNameServiceImpl.scala.erb
63
65
  - lib/template/src/main/scala/com/twitter/birdname/Main.scala.erb
64
66
  - lib/template/src/main/scala/com/twitter/birdname/config/BirdNameServiceConfig.scala.erb
65
67
  - lib/template/src/main/thrift/birdname.thrift.erb
68
+ - lib/template/src/scripts/console.erb
69
+ - lib/template/src/scripts/startup.sh
66
70
  - lib/template/src/test/scala/com/twitter/birdname/AbstractSpec.scala.erb
67
71
  - lib/template/src/test/scala/com/twitter/birdname/BirdNameServiceSpec.scala.erb
68
72
  - vendor/sbt-launch-0.7.4.jar
@@ -72,28 +76,32 @@ homepage: http://github.com/fizx/scala-bootstrapper
72
76
  licenses: []
73
77
 
74
78
  post_install_message:
75
- rdoc_options:
76
- - --charset=UTF-8
79
+ rdoc_options: []
80
+
77
81
  require_paths:
78
82
  - lib
79
83
  required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
80
85
  requirements:
81
86
  - - ">="
82
87
  - !ruby/object:Gem::Version
88
+ hash: 3
83
89
  segments:
84
90
  - 0
85
91
  version: "0"
86
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
87
94
  requirements:
88
95
  - - ">="
89
96
  - !ruby/object:Gem::Version
97
+ hash: 3
90
98
  segments:
91
99
  - 0
92
100
  version: "0"
93
101
  requirements: []
94
102
 
95
103
  rubyforge_project:
96
- rubygems_version: 1.3.6
104
+ rubygems_version: 1.5.0
97
105
  signing_key:
98
106
  specification_version: 3
99
107
  summary: Twitter scala project init
data/.gitignore DELETED
@@ -1,21 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC