buildr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lac...@apache.org
Subject svn commit: r690727 - in /incubator/buildr/trunk: CHANGELOG lib/buildr/core/build.rb spec/build_spec.rb
Date Sun, 31 Aug 2008 16:52:13 GMT
Author: lacton
Date: Sun Aug 31 09:52:13 2008
New Revision: 690727

URL: http://svn.apache.org/viewvc?rev=690727&view=rev
Log:
BUILDR-141 "Release task is confusing". Removed NEXT_VERSION.

Added tests on Release#make (the most important method!).
Extracted a buildr method to make testing easier.  Otherwise, the make method would fail when
trying to spawn a new buildr instance.
Removed some parameters from some methods' signatures when the values could be deduced from
the context.
Reduced duplication by reusing Release#change_version.

Modified:
    incubator/buildr/trunk/CHANGELOG
    incubator/buildr/trunk/lib/buildr/core/build.rb
    incubator/buildr/trunk/spec/build_spec.rb

Modified: incubator/buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/CHANGELOG?rev=690727&r1=690726&r2=690727&view=diff
==============================================================================
--- incubator/buildr/trunk/CHANGELOG (original)
+++ incubator/buildr/trunk/CHANGELOG Sun Aug 31 09:52:13 2008
@@ -13,6 +13,7 @@
           (http://www.scala-lang.org/node/94)
 * Change: Buildr.application.buildfile returns a task instead of a String.
 * Change: BUILDR-139 Incremental test run.
+* Change: BUILDR-141 Removed NEXT_VERSION from release task.
 * Fixed:  BUILDR-106 download(artifact(...)=>url) broken in certain cases
           (Lacton).
 * Fixed:  BUILDR-108 Trace to explain why a compile is done (Lacton).

Modified: incubator/buildr/trunk/lib/buildr/core/build.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/build.rb?rev=690727&r1=690726&r2=690727&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/build.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/build.rb Sun Aug 31 09:52:13 2008
@@ -150,7 +150,6 @@
   class Release
 
     THIS_VERSION_PATTERN  = /(THIS_VERSION|VERSION_NUMBER)\s*=\s*(["'])(.*)\2/
-    NEXT_VERSION_PATTERN  = /NEXT_VERSION\s*=\s*(["'])(.*)\1/
 
     class << self
 
@@ -160,32 +159,25 @@
       # Make a release.
       def make()
         check
-        version = with_next_version do |filename| 
-          options = ['--buildfile', filename, 'DEBUG=no']
+        with_release_candidate_version do |release_candidate_buildfile| 
+          options = ['--buildfile', release_candidate_buildfile, 'DEBUG=no']
           options << '--environment' << Buildr.environment unless Buildr.environment.to_s.empty?
-          sh "#{command} _#{Buildr::VERSION}_ clean upload #{options.join(' ')}"
+          buildr %w{clean upload}, options
         end
-        tag version
-        commit version + '-SNAPSHOT'
+        tag_release
+        commit_new_snapshot
       end
 
       # :call-seq:
-      #   extract_versions(buildfile) => this_version, next_version
+      #   extract_version() => this_version
       #
-      # Extract the current and next version numbers from a buildfile.
+      # Extract the current version number from the buildfile.
       # Raise an error if not found.
-      def extract_versions buildfile
-        begin
-          this_version = buildfile.scan(THIS_VERSION_PATTERN)[0][2]
-        rescue
-          fail 'Looking for THIS_VERSION = "..." in your Buildfile, none found'
-        end
-        begin
-          next_version = buildfile.scan(NEXT_VERSION_PATTERN)[0][1]
-        rescue
-          fail 'Looking for NEXT_VERSION = "..." in your Buildfile, none found'
-        end
-        [this_version, next_version]
+      def extract_version
+        buildfile = File.read(Buildr.application.buildfile.to_s)
+        buildfile.scan(THIS_VERSION_PATTERN)[0][2]
+      rescue
+        fail 'Looking for THIS_VERSION = "..." in your Buildfile, none found'
       end
       
       # :call-seq:
@@ -216,86 +208,92 @@
 
     protected
 
+      # :call-seq:
+      #   buildr(tasks, options)
+      #
+      # Calls another instance of buildr.
+      def buildr tasks, options
+          sh "#{command} _#{Buildr::VERSION}_ #{tasks.join(' ')} #{options.join(' ')}"
+      end
+      
       def command() #:nodoc:
         Config::CONFIG['arch'] =~ /dos|win32/i ? $PROGRAM_NAME.ext('cmd') : $PROGRAM_NAME
       end
 
       # :call-seq:
-      #   with_next_version() { |filename| ... } => version
+      #   with_release_candidate_version() { |filename| ... }
       #
-      # Yields to block with upgraded version number, before committing to use it. Returns
the *new*
-      # current version number.
+      # Yields to block with release candidate buildfile, before committing to use it.
       #
       # We need a Buildfile with upgraded version numbers to run the build, but we don't
want the
-      # Buildfile modified unless the build succeeds. So this method updates the version
numbers in
+      # Buildfile modified unless the build succeeds. So this method updates the version
number in
       # a separate (Buildfile.next) file, yields to the block with that filename, and if
successful
       # copies the new file over the existing one.
       #
-      # Version numbers are updated as follows. The next release version becomes the current
one,
-      # and the next version is upgraded by one to become the new next version. So:
-      #   THIS_VERSION = 1.1.0
-      #   NEXT_VERSION = 1.2.0
+      # The release version is the current version without '-SNAPSHOT'.  So:
+      #   THIS_VERSION = 1.1.0-SNAPSHOT
       # becomes:
-      #   THIS_VERSION = 1.2.0
-      #   NEXT_VERSION = 1.2.1
-      # and the method will return 1.2.0.
-      def with_next_version()
-        new_filename = Buildr.application.buildfile.to_s + '.next'
-        modified = change_version do |this_version, next_version|
-          one_after = next_version.split('.')
-          one_after[-1] = one_after[-1].to_i + 1
-          [ next_version, one_after.join('.') ]
+      #   THIS_VERSION = 1.1.0
+      # for the release buildfile.
+      def with_release_candidate_version
+        release_candidate_buildfile = Buildr.application.buildfile.to_s + '.next'
+        release_candidate_buildfile_contents = change_version do |version|
+          release_candidate_version = version.split('.')
+          release_candidate_version[-1] = release_candidate_version[-1].to_i
+          release_candidate_version.join('.')
         end
-        File.open(new_filename, 'w') { |file| file.write modified }
+        File.open(release_candidate_buildfile, 'w') { |file| file.write release_candidate_buildfile_contents
}
         begin
-          yield new_filename
-          mv new_filename, Buildr.application.buildfile.to_s
+          yield release_candidate_buildfile
+          mv release_candidate_buildfile, Buildr.application.buildfile.to_s
         ensure
-          rm new_filename rescue nil
+          rm release_candidate_buildfile rescue nil
         end
-        extract_versions(File.read(Buildr.application.buildfile.to_s))[0]
       end
 
       # :call-seq:
-      #   change_version() { |this, next| ... } => buildfile
+      #   change_version() { |this_version| ... } => buildfile
       #
-      # Change version numbers in the current Buildfile, but without writing a new file (yet).
-      # Returns the contents of the Buildfile with the modified version numbers.
+      # Change version number in the current Buildfile, but without writing a new file (yet).
+      # Returns the contents of the Buildfile with the modified version number.
       #
-      # This method yields to the block with the current (this) and next version numbers
and expects
-      # an array with the new this and next version numbers.
+      # This method yields to the block with the current (this) version number and expects
+      # a new version number.
       def change_version()
-        buildfile = File.read(Buildr.application.buildfile.to_s)
-        this_version, next_version = extract_versions buildfile
-        this_version, next_version = yield(this_version, next_version)
+        this_version = extract_version
+        new_version = yield(this_version)
         if verbose
-          puts 'Upgrading version numbers:'
+          puts 'Upgrading version numbers:' # TODO Add tests on this
           puts "  This:  #{this_version}"
-          puts "  Next:  #{next_version}"
+          puts "  Next:  #{new_version}"
         end
-        buildfile.gsub(THIS_VERSION_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{this_version}"})
}.
-          gsub(NEXT_VERSION_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{next_version}"})
}
+        buildfile = File.read(Buildr.application.buildfile.to_s)
+        buildfile.gsub(THIS_VERSION_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{new_version}"})
}
       end
 
       # :call-seq:
-      #   tag(version)
+      #   tag_release()
       #
       # Tags the current working copy with the release version number.
-      def tag(version)
+      def tag_release
+        version = extract_version
         url = tag_url Svn.repo_url, version
         Svn.remove url, 'Removing old copy' rescue nil
         Svn.copy Dir.pwd, url, "Release #{version}"
       end
 
       # :call-seq:
-      #   commit(version)
+      #   commit_new_snapshot()
       #
-      # Last, we commit what we currently have in the working copy.
-      def commit(version)
-        buildfile = File.read(Buildr.application.buildfile.to_s).
-          gsub(THIS_VERSION_PATTERN) { |ver| ver.sub(/(["']).*\1/, %Q{"#{version}"}) }
+      # Last, we commit what we currently have in the working copy with an upgraded version
number.
+      def commit_new_snapshot
+        buildfile = change_version do |version|
+          version = version.split('.')
+          version[-1] = version[-1].to_i + 1
+          version.join('.') + '-SNAPSHOT'
+        end
         File.open(Buildr.application.buildfile.to_s, 'w') { |file| file.write buildfile }
-        Svn.commit Buildr.application.buildfile.to_s, "Changed version number to #{version}"
+        Svn.commit Buildr.application.buildfile.to_s, "Changed version number to #{extract_version}"
       end
     end
   end

Modified: incubator/buildr/trunk/spec/build_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/build_spec.rb?rev=690727&r1=690726&r2=690727&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/build_spec.rb (original)
+++ incubator/buildr/trunk/spec/build_spec.rb Sun Aug 31 09:52:13 2008
@@ -193,6 +193,39 @@
 end
 
 
+describe Buildr::Release, '#make' do
+  before do
+    write 'buildfile', "VERSION_NUMBER = '1.0.0-SNAPSHOT'"
+    # Prevent a real call to a spawned buildr process.
+    Release.stub!(:buildr)
+    Svn.stub!(:repo_url).and_return('http://my.repo.org/foo/trunk')
+    Svn.stub!(:uncommitted_files).and_return('')
+    Svn.stub!(:remove)
+    Svn.stub!(:copy)
+    Svn.stub!(:commit)
+  end
+  
+  it 'should tag a release with the release version' do
+    Svn.should_receive(:copy).with(Dir.pwd, 'http://my.repo.org/foo/tags/1.0.0', 'Release
1.0.0').and_return {
+      file('buildfile').should contain('VERSION_NUMBER = "1.0.0"')
+    }
+    Release.make
+  end
+  
+  it 'should update the buildfile with the next version number' do
+    Release.make
+    file('buildfile').should contain('VERSION_NUMBER = "1.0.1-SNAPSHOT"')
+  end
+  
+  it 'should commit the updated buildfile' do
+    Svn.should_receive(:commit).with(File.expand_path('buildfile'), 'Changed version number
to 1.0.1-SNAPSHOT').and_return {
+      file('buildfile').should contain('VERSION_NUMBER = "1.0.1-SNAPSHOT"')
+    }
+    Release.make
+  end
+end
+
+
 describe Buildr::Release, '#check' do
   before do
     Buildr::Svn.stub!(:uncommitted_files).and_return('')
@@ -208,7 +241,7 @@
     lambda { Release.check }.should_not raise_error
   end
   
-  it 'should reject to release from a tag' do
+  it 'should reject releasing from a tag' do
     Buildr::Svn.stub!(:repo_url).and_return('http://my.repo.org/foo/tags/1.0.0')
     lambda { Release.check }.should raise_error(RuntimeError, "SVN URL must contain 'trunk'
or 'branches/...'")
   end
@@ -228,36 +261,31 @@
 end
   
 
-describe Buildr::Release, '#extract_versions' do
+describe Buildr::Release, '#extract_version' do
   
-  it 'should extract VERSION_NUMBER and NEXT_VERSION with single quotes' do
-    buildfile = ["VERSION_NUMBER = '1.0.0-SNAPSHOT'", "NEXT_VERSION = '1.0.1'"].join("\n")
-    Release.extract_versions(buildfile).should == ['1.0.0-SNAPSHOT', '1.0.1']
+  it 'should extract VERSION_NUMBER with single quotes' do
+    write 'buildfile', "VERSION_NUMBER = '1.0.0-SNAPSHOT'"
+    Release.extract_version.should == '1.0.0-SNAPSHOT'
   end
   
-  it 'should extract VERSION_NUMBER and NEXT_VERSION with double quotes' do
-    buildfile = [%{VERSION_NUMBER = "1.0.1-SNAPSHOT"}, %{NEXT_VERSION = "1.0.2"}].join("\n")
-    Release.extract_versions(buildfile).should == ['1.0.1-SNAPSHOT', '1.0.2']
+  it 'should extract VERSION_NUMBER with double quotes' do
+    write 'buildfile', %{VERSION_NUMBER = "1.0.1-SNAPSHOT"}
+    Release.extract_version.should == '1.0.1-SNAPSHOT'
   end
   
-  it 'should extract VERSION_NUMBER and NEXT_VERSION without any spaces' do
-    buildfile = ["VERSION_NUMBER='1.0.2-SNAPSHOT'", "NEXT_VERSION='1.0.3'"].join("\n")
-    Release.extract_versions(buildfile).should == ['1.0.2-SNAPSHOT', '1.0.3']
+  it 'should extract VERSION_NUMBER without any spaces' do
+    write 'buildfile', "VERSION_NUMBER='1.0.2-SNAPSHOT'"
+    Release.extract_version.should == '1.0.2-SNAPSHOT'
   end
   
   it 'should extract THIS_VERSION as an alternative to VERSION_NUMBER' do
-    buildfile = ["THIS_VERSION = '1.0.3-SNAPSHOT'", "NEXT_VERSION = '1.0.4'"].join("\n")
-    Release.extract_versions(buildfile).should == ['1.0.3-SNAPSHOT', '1.0.4']
+    write 'buildfile', "THIS_VERSION = '1.0.3-SNAPSHOT'"
+    Release.extract_version.should == '1.0.3-SNAPSHOT'
   end
   
   it 'should complain if no current version number' do
-    buildfile = "NEXT_VERSION = '1.0.1'"
-    lambda { Release.extract_versions(buildfile) }.should raise_error('Looking for THIS_VERSION
= "..." in your Buildfile, none found')
-  end
-  
-  it 'should complain if no next version number' do
-    buildfile = "VERSION_NUMBER = '1.0.0-SNAPSHOT'"
-    lambda { Release.extract_versions(buildfile) }.should raise_error('Looking for NEXT_VERSION
= "..." in your Buildfile, none found')
+    write 'buildfile', 'define foo'
+    lambda { Release.extract_version }.should raise_error('Looking for THIS_VERSION = "..."
in your Buildfile, none found')
   end
 end
 
@@ -301,39 +329,29 @@
 end
 
 
-describe Buildr::Release, '#with_next_version' do
+describe Buildr::Release, '#with_release_candidate_version' do
   before do
     Buildr.application.stub!(:buildfile).and_return(file('buildfile'))
-    write 'buildfile', <<-EOF
-      THIS_VERSION = '1.1.0'
-      NEXT_VERSION = '1.2.0'
-      EOF
+    write 'buildfile', "THIS_VERSION = '1.1.0-SNAPSHOT'"
   end
   
-  it 'should yield the name of an updated buildfile' do
-    Release.send :with_next_version do |new_filename|
-      File.read(new_filename).should == <<-EOF
-      THIS_VERSION = "1.2.0"
-      NEXT_VERSION = "1.2.1"
-      EOF
+  it 'should yield the name of the release candidate buildfile' do
+    Release.send :with_release_candidate_version do |new_filename|
+      File.read(new_filename).should == %{THIS_VERSION = "1.1.0"}
     end
   end
   
   it 'should yield a name different from the original buildfile' do
-    Release.send :with_next_version do |new_filename|
+    Release.send :with_release_candidate_version do |new_filename|
       new_filename.should_not point_to_path('buildfile')
     end
   end
-  
-  it 'should return the new version number' do
-    new_version = Release.send(:with_next_version) {}
-    new_version.should == '1.2.0'
-  end
 end
 
 
-describe Buildr::Release, '#tag' do
+describe Buildr::Release, '#tag_release' do
   before do
+    write 'buildfile', "THIS_VERSION = '1.0.1'"
     Svn.stub!(:repo_url).and_return('http://my.repo.org/foo/trunk')
     Svn.stub!(:copy)
   end
@@ -341,34 +359,34 @@
   it 'should tag the working copy' do
     Svn.stub!(:remove)
     Svn.should_receive(:copy).with(Dir.pwd, 'http://my.repo.org/foo/tags/1.0.1', 'Release
1.0.1')
-    Release.send :tag, '1.0.1'
+    Release.send :tag_release
   end
   
   it 'should remove the tag if it already exists' do
     Svn.should_receive(:remove).with('http://my.repo.org/foo/tags/1.0.1', 'Removing old copy')
-    Release.send :tag, '1.0.1'
+    Release.send :tag_release
   end
   
   it 'should accept that the tag does not exist' do
     Svn.stub!(:remove).and_raise(RuntimeError)
-    Release.send :tag, '1.0.1'
+    Release.send :tag_release
   end
 end
 
 
-describe Buildr::Release, '#commit' do
+describe Buildr::Release, '#commit_new_snapshot' do
   before do
     write 'buildfile', 'THIS_VERSION = "1.0.0"'
   end
   
-  it 'should update the buildfile with the given version number' do
+  it 'should update the buildfile with a new version number' do
     Svn.stub!(:commit)
-    Release.send :commit, '1.0.1-SNAPSHOT'
+    Release.send :commit_new_snapshot
     file('buildfile').should contain('THIS_VERSION = "1.0.1-SNAPSHOT"')
   end
   
   it 'should commit the new buildfile on the trunk' do
     Svn.should_receive(:commit).with(File.expand_path('buildfile'), 'Changed version number
to 1.0.1-SNAPSHOT')
-    Release.send :commit, '1.0.1-SNAPSHOT'
+    Release.send :commit_new_snapshot
   end
 end
\ No newline at end of file



Mime
View raw message