lib/core/build.rb in buildr-0.16.0 vs lib/core/build.rb in buildr-0.18.0
- old
+ new
@@ -11,92 +11,89 @@
: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) }
+ BUILD_TASKS.each { |name, comment| Project.local_task(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
+ task("build").enhance args, &block
end
def clean(*args, &block)
- returning(@clean_task ||= task("clean")) do |task|
- task.enhance args, &block
- end
+ task("clean").enhance args, &block
end
end
Project.on_define do |project|
+ # Make sure these tasks are defined in the project.
project.build
project.clean
end
- class ReleaseTask < Rake::Task
+ class Release
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.
- check_status
- # Update current version to next version before deploying.
- next_ver = update_version
- # 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 the repository for this release.
- tag_repository next_ver
- # Update the next version to end with -SNAPSHOT.
- update_version_to_snapshot next_ver
- end
+ def initialize(rakefile = nil)
+ @rakefile = rakefile || File.read(Rake.application.rakefile)
end
+ attr_reader :rakefile
+
+ def invoke()
+ # Make sure we don't have anything uncommitted in SVN.
+ check_status
+ # Update current version to next version before deploying.
+ next_ver = update_version
+ # 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 the repository for this release.
+ tag_repository next_ver
+ # Update the next version to end with -SNAPSHOT.
+ update_version_to_snapshot next_ver
+ end
+
def check_status()
- ignores = ReleaseTask.svn_ignores
+ ignores = Release.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)
+ rakefile = read_rakefile
version = rakefile.scan(VERSION_NUMBER_PATTERN)[0][1] or
fail "Looking for VERSION_NUMBER = \"...\" in your Rakefile, none found"
next_ver = rakefile.scan(NEXT_VERSION_PATTERN)[0][1] or
fail "Looking for NEXT_VERSION = \"...\" in your Rakefile, none found"
if verbose
puts "Current version: #{version}"
puts "Next version: #{next_ver}"
end
-
# Switch version numbers.
- rakefile.gsub!(VERSION_NUMBER_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{next_ver}"}) }
- File.open(Rake.application.rakefile, "w") { |file| file.write rakefile }
-
+ write_rakefile rakefile.gsub(VERSION_NUMBER_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{next_ver}"}) }
next_ver
end
# Change the Rakefile and update the next version number to one after
# (NEXT_VERSION = NEXT_VERSION + 1). We do this to automatically increment
@@ -104,16 +101,13 @@
def update_next_version(version)
# Update to new version number.
nums = version.split(".")
nums[-1] = nums[-1].to_i + 1
next_ver = nums.join(".")
- 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 }
-
+ write_rakefile read_rakefile.gsub(NEXT_VERSION_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{next_ver}"}) }
# Commit new version number.
- svn "commit", "-m", "Changed version number to #{version}", Rake.application.rakefile
+ svn "commit", "-m", "Changed version number to #{version}", rakefile
end
# Create a tag in the SVN repository.
def tag_repository(version)
# Copy to tag.
@@ -123,17 +117,25 @@
svn "copy", cur_url, new_url, "-m", "Release #{version}"
end
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 }
+ write_rakefile read_rakefile.gsub(VERSION_NUMBER_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{version}"}) }
# Commit new version number.
- svn "commit", "-m", "Changed version number to #{version}", Rake.application.rakefile
+ svn "commit", "-m", "Changed version number to #{version}", rakefile
end
+ protected
+
+ def read_rakefile()
+ File.read(rakefile)
+ end
+
+ def write_rakefile(contents)
+ File.open(rakefile, "w") { |file| file.write contents }
+ end
+
def svn(*args)
if Hash === args.last
options = args.pop
else
options = { :verbose=>verbose }
@@ -144,10 +146,19 @@
error = stderr.read
fail error unless error.empty?
returning(stdout.read) { |output| puts output if Rake.application.options.trace }
end
end
+
end
+
desc "Make a release"
- ReleaseTask.define_task "release"
+ task("release").tap do |release|
+ class << release
+ def release()
+ @release ||= Release.new
+ end
+ end
+ release.enhance { release.invoke }
+ end
end