lib/core/build.rb in buildr-0.15.0 vs lib/core/build.rb in buildr-0.16.0
- old
+ new
@@ -1,27 +1,84 @@
+require "open3"
+
+
module Buildr
+ BUILD_TASKS = {
+ :build =>"Build the project",
+ :clean =>"Clean files generated during a build",
+ :package =>"Create packages",
+ :install =>"Install packages created by the project",
+ :uninstall=>"Remove previously installed packages",
+ :deploy =>"Deploy packages created by the project"
+ }
+
+ # Handles the build and clean tasks.
+ BUILD_TASKS.each { |name, comment| LocalDirectoryTask.define_task(name).add_comment(comment) }
+
+ Project.on_define do |project|
+ BUILD_TASKS.each { |name, comment| project.recursive_task name }
+ end
+
+ class Project
+ def build(*args, &block)
+ returning(@build_task ||= task("build")) do |task|
+ task.enhance args, &block
+ end
+ end
+
+ def clean(*args, &block)
+ returning(@clean_task ||= task("clean")) do |task|
+ task.enhance args, &block
+ end
+ end
+ end
+
+ Project.on_define do |project|
+ project.build
+ project.clean
+ end
+
+
class ReleaseTask < Rake::Task
VERSION_NUMBER_PATTERN = /VERSION_NUMBER\s*=\s*(["'])(.*)\1/
NEXT_VERSION_PATTERN = /NEXT_VERSION\s*=\s*(["'])(.*)\1/
+ class << self
+ def svn_ignores()
+ @ignores = (@ignores || []).map { |pat| pat.is_a?(Regexp) ? pat : Regexp.new("^.*\s+#{Regexp.escape pat}$") }
+ end
+ end
+
def initialize(*args)
super
enhance do |task|
# Make sure we don't have anything uncommitted in SVN.
- fail "Uncommitted SVN files violate the First Principle Of Release!" unless
- svn("status").empty?
- # Load the Rakefile and find the version numbers.
+ check_status
+ # Update current version to next version before deploying.
next_ver = update_version
- # Run the deployment externally using the new version number.
+ # Run the deployment externally using the new version number
+ # (from the modified Rakefile).
sh "rake deploy"
+ # Update the next version as well to the next increment and commit.
update_next_version next_ver
- tag_repository
+ # Tag the repository for this release.
+ tag_repository next_ver
+ # Update the next version to end with -SNAPSHOT.
+ update_version_to_snapshot next_ver
end
end
+ def check_status()
+ ignores = ReleaseTask.svn_ignores
+ status = svn("status", "--ignore-externals", :verbose=>false).
+ reject { |line| line =~ /^X\s/ || ignores.any? { |pat| line =~ pat } }
+ fail "Uncommitted SVN files violate the First Principle Of Release!\n#{status}" unless
+ status.empty?
+ end
+
# Change the Rakefile and update the current version number to the
# next version number (VERSION_NUMBER = NEXT_VERSION). We need this
# before making a release with the next version. Return the next version.
def update_version()
rakefile = File.read(Rake.application.rakefile)
@@ -52,56 +109,45 @@
rakefile = File.read(Rake.application.rakefile)
rakefile.gsub!(NEXT_VERSION_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{next_ver}"}) }
File.open(Rake.application.rakefile, "w") { |file| file.write rakefile }
# Commit new version number.
- svn "commit", "-m", "Changed release number to #{version}"
+ svn "commit", "-m", "Changed version number to #{version}", Rake.application.rakefile
end
# Create a tag in the SVN repository.
- def tag_repository()
+ def tag_repository(version)
# Copy to tag.
cur_url = svn("info").scan(/URL: (.*)/)[0][0]
- new_url = cur_url.sub(/trunk$/, "tags/#{cur_ver}")
- svn "copy", cur_url, new_url
+ new_url = cur_url.sub(/trunk$/, "tags/#{version}")
+ svn "remove", new_url, "-m", "Removing old copy" rescue nil
+ svn "copy", cur_url, new_url, "-m", "Release #{version}"
end
- def svn(*args)
- stdin, stdout, stderr = Open3.popen3("svn", *args)
- stdin.close
- error = stderr.read
- fail error unless error.empty?
- stdout.read
+ def update_version_to_snapshot(version)
+ version += "-SNAPSHOT"
+ rakefile = File.read(Rake.application.rakefile)
+ rakefile.gsub!(VERSION_NUMBER_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{version}"}) }
+ File.open(Rake.application.rakefile, "w") { |file| file.write rakefile }
+ # Commit new version number.
+ svn "commit", "-m", "Changed version number to #{version}", Rake.application.rakefile
end
- end
- # Handles the build and clean tasks.
- desc "Clean all projects"
- LocalDirectoryTask.define_task("clean")
- desc "Build all projects"
- LocalDirectoryTask.define_task("build")
- desc "Make a release"
- ReleaseTask.define_task "release"
-
- class Project
- def build(*args, &block)
- returning(@build_task ||= recursive_task("build")) do |task|
- task.enhance args, &block
+ def svn(*args)
+ if Hash === args.last
+ options = args.pop
+ else
+ options = { :verbose=>verbose }
end
- end
-
- def clean(*args, &block)
- returning(@clean_task ||= recursive_task("clean")) do |task|
- task.enhance args, &block
+ puts ["svn", *args].join(" ") if options[:verbose]
+ Open3.popen3("svn", *args) do |stdin, stdout, stderr|
+ stdin.close
+ error = stderr.read
+ fail error unless error.empty?
+ returning(stdout.read) { |output| puts output if Rake.application.options.trace }
end
end
end
- Project.on_create do |project|
- desc "Clean all files generated during the build process"
- project.clean
-
- desc "Build this project"
- project.build
- end
-
+ desc "Make a release"
+ ReleaseTask.define_task "release"
end