Permalink
Browse files

Merge pull request #4 from twitter/fixup

Fixup
  • Loading branch information...
Kyle Maxwell
Kyle Maxwell committed Sep 9, 2011
2 parents 30937d4 + 511fd10 commit 3bea47b076cbcf932effd24af35ed3a3a614faab
View
@@ -0,0 +1 @@
+When you make changes to this project, please test by bootstrapping a new project and running `sbt update test` there.
View
@@ -1,8 +1,47 @@
This creates a standard environment for your twitter-centric sbt/scala thrift service.
+Building:
+
+ :$ rake build
+ :$ gem install pkg/scala-bootstrapper-*.gem
+
Usage:
- :$ mkdir foo
- :$ cd foo
- :$ scala-bootstrapper foo
- :$ sbt update test
+ :$ mkdir birdname
+ :$ cd birdname
+ :$ scala-bootstrapper birdname
+ :$ sbt update test
+
+Tutorial:
+
+ :$ less TUTORIAL.md
+
+== Git support
+
+You can track files generated by scala-bootstrapper in a Git branch,
+and later merge changes from the branch (e.g. to rename a project, or
+to upgrade to a newer version of scala-bootstrapper.
+
+To get started:
+
+ :$ scala-bootstrapper --git foo
+
+For a brand-new project (no <tt>.git</tt> directory) this will
+initialize a Git repo in the directory, generate files into the
+<tt>scala-bootstrapper</tt> branch, and merge the branch to
+<tt>master</tt>.
+
+For an existing project, this will generate files into the
+<tt>scala-bootstrapper</tt> branch, and merge it to the current branch
+*without* actually taking the changes (just making
+<tt>scala-bootstrapper</tt> a parent of the current branch to anchor
+future merges). This is to avoid clobbering files if you had
+previously run <tt>scala-bootstrapper</tt> without the <tt>--git</tt>
+option (or created files some other way). If you want to merge the
+changes and manually resolve any conflicts, do
+
+ :$ git cherry-pick --no-commit scala-bootstrapper
+
+Once the <tt>scala-bootstrapper</tt> branch is created, subsequent
+runs will generate files into the branch and merge it to the current
+branch; if there are conflicts you can resolve them in the usual way.
View
@@ -1 +1 @@
-0.7.1
+0.9.2
View
@@ -1,2 +0,0 @@
-#!/usr/bin/env ruby
-exec "java","-Xmx2g", "-XX:+CMSClassUnloadingEnabled", "-XX:MaxPermSize=256m", "-jar", File.dirname(__FILE__) + "/../vendor/sbt-launch-0.7.4.jar", *ARGV
View
@@ -7,6 +7,7 @@ opts = Trollop::options do
opt :public, "Use the public twitter maven repo"
opt :namespace, "Use something besides com.twitter", :type => :string
+ opt :git, "Use Git to track updates to generated files"
end
@@ -34,12 +35,16 @@ end
def gsub_birds(haystack, name, namespace)
haystack.
+ gsub("com.twitter.birdname", "#{namespace}.#{name.downcase}").
+ gsub("com/twitter/birdname", "#{namespace.gsub('.', '/')}/#{name.downcase}").
gsub("BirdName", name).
gsub("birdname", name.downcase).
gsub("bird_name", name.underscore).
- gsub("birdName", name.camelize).
- gsub("com.twitter", namespace).
- gsub("com/twitter", namespace.gsub(".", "/"))
+ gsub("birdName", name.camelize)
+end
+
+def sys(cmd, abort_on_fail=true)
+ system(cmd + " &> /dev/null") || abort_on_fail && abort("failed: #{cmd}")
end
require "erb"
@@ -49,6 +54,35 @@ include FileUtils
project_name = ARGV.pop.camelize(true)
is_public = opts[:public]
namespace = opts[:namespace] || "com.twitter"
+git = opts[:git]
+$overwrite_all = true if git
+$ex_post_facto = false
+$branch = 'master'
+$files = []
+
+if git
+ if !File.exists?('.git')
+ if `ls -l` != ''
+ abort('files in directory, no git repo.')
+ end
+ sys('git init')
+ sys('touch README.md')
+ sys('git add .')
+ sys("git commit -m'first commit'")
+ sys('git checkout -b scala-bootstrapper')
+
+ else
+ if `git status -s` != ''
+ abort('uncommitted files in directory.')
+ end
+ $branch = `git branch`.grep(/^\*/).first.chomp.gsub(/^\* (.+)$/, '\1')
+
+ if !sys('git checkout scala-bootstrapper', false)
+ $ex_post_facto = true
+ sys('git checkout -b scala-bootstrapper')
+ end
+ end
+end
root = File.expand_path(File.dirname(__FILE__) + "/../lib/template")
@@ -72,8 +106,47 @@ Dir["#{root}/**/*"].select{|path| File.file?(path)}.each do |path|
puts "writing #{target_path}"
mkdir_p(File.dirname(target_path))
File.open(target_path, "w") {|f| f.print(gsub_birds(template.result(binding), project_name, namespace)) }
+ $files << target_path
end
if File.exists?("src/scripts/startup.sh")
- `mv src/scripts/startup.sh src/scripts/#{project_name.downcase}.sh`
+ startup = "src/scripts/#{project_name.downcase}.sh"
+ `mv src/scripts/startup.sh #{startup}`
+ $files << startup
+end
+
+[ "src/scripts/#{project_name.downcase}.sh", "src/scripts/console", "run" ].each do |executable|
+ `chmod +x #{executable}` if File.exists?(executable)
+end
+
+if git
+ $files.each { |file| sys("git add #{file}") if File.exists?(file) }
+ sys("git commit -m'scala-bootstrapper'", false) # fails if no change
+ sys("git checkout #{$branch}")
+ sys('git merge --no-ff --no-commit scala-bootstrapper')
+
+ if $ex_post_facto
+ # don't commit anything, just make scala-bootstrapper head a parent
+ sys('rm .git/index')
+ sys('git checkout HEAD .')
+ sys('git clean -fdx')
+ end
+
+ sys("git commit -m'merged scala-bootstrapper'", false) # fails if no change
+end
+
+if $ex_post_facto
+ puts <<EOF
+Found existing .git directory; scala-bootstrapper branch created but
+generated files not merged to #{$branch}. To manually merge changes,
+run
+
+ git cherry-pick --no-commit scala-bootstrapper
+
+then
+
+ git commit
+
+once you have resolved any conflicts.
+EOF
end
File renamed without changes.
View
@@ -1,6 +1,8 @@
+# use "bundle install" to update gems; "gem install bundler" to install bundler.
source :rubygems
source "http://gems.local.twitter.com"
-gem "thrift_client", "0.6"
-gem "thrift", "0.5"
+gem "thrift_client", "0.6.2"
+gem "thrift", "0.6"
gem "railsless-deploy"
-gem "twitter-cap-utils", "~>0.8.0"
+gem "capistrano"
+gem "twitter-cap-utils", "~>0.8.0"
View
@@ -0,0 +1,24 @@
+# Project BirdName
+
+Welcome to your birdname project! To make sure things are working
+properly, you may want to:
+
+ $ sbt update test
+
+There is a tutorial for what to do next, which you can find in the
+scala-bootstrapper README.rdoc file.
+
+# Configuring Intellij
+
+If you want to setup Intellij, it has to happen off to the side:
+
+ $ sbt
+ > *sbtIdeaRepo at http://mpeltonen.github.com/maven/
+ > *idea is com.github.mpeltonen sbt-idea-processor 0.4.0
+ > update
+ > idea
+
+# Documenting your project
+
+Add documentation here! Eventually, you'll be able to publish this to
+a web site for the world to easily find and read.
Oops, something went wrong.

0 comments on commit 3bea47b

Please sign in to comment.