You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by to...@apache.org on 2010/06/02 23:49:30 UTC

svn commit: r950781 - in /buildr/trunk: CHANGELOG lib/buildr/core/common.rb lib/buildr/core/transports.rb lib/buildr/ide/eclipse.rb spec/core/transport_spec.rb spec/core/util_spec.rb spec/packaging/archive_spec.rb spec/packaging/packaging_spec.rb

Author: toulmean
Date: Wed Jun  2 21:49:29 2010
New Revision: 950781

URL: http://svn.apache.org/viewvc?rev=950781&view=rev
Log:
BUILDR-449 Fix failing specs on Windows (Pepijn Van Eeckhoudt)

Modified:
    buildr/trunk/CHANGELOG
    buildr/trunk/lib/buildr/core/common.rb
    buildr/trunk/lib/buildr/core/transports.rb
    buildr/trunk/lib/buildr/ide/eclipse.rb
    buildr/trunk/spec/core/transport_spec.rb
    buildr/trunk/spec/core/util_spec.rb
    buildr/trunk/spec/packaging/archive_spec.rb
    buildr/trunk/spec/packaging/packaging_spec.rb

Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=950781&r1=950780&r2=950781&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Wed Jun  2 21:49:29 2010
@@ -117,6 +117,7 @@
           correctly (Pepijn Van Eeckhoudt)
 * Fixed:  BUILDR-418 jruby exception: `ffi_libraries': no library specified
 * Fixed:  BUILDR-442 Errors while running the specs with jruby 1.5
+* Fixed:  BUILDR-449 Fix failing specs on Windows (Pepijn Van Eeckhoudt)
 * Fixed:  buildr test=all didn't run all tests as expected
 * Fixed:  Fail-fast if package.with() or include() called with nil values
 * Fixed:  Failures not reported correctly for ScalaTest (Alex Eagle)

Modified: buildr/trunk/lib/buildr/core/common.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/common.rb?rev=950781&r1=950780&r2=950781&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/common.rb (original)
+++ buildr/trunk/lib/buildr/core/common.rb Wed Jun  2 21:49:29 2010
@@ -58,17 +58,18 @@ module Buildr
   end
 
   # :call-seq:
-  #   read(name) => string
-  #   read(name) { |string| ... } => result
+  #   read(args) => string
+  #   read(args) { |string| ... } => result
   #
   # Reads and returns the contents of a file. The second form yields to the block and returns
-  # the result of the block.
+  # the result of the block. The args passed to read are passed on to File.open.
   #
   # For example:
   #   puts read('README')
   #   read('README') { |text| puts text }
-  def read(name)
-    contents = File.open(name.to_s) { |f| f.read }
+  def read(*args)
+    args[0] = args[0].to_s
+    contents = File.open(*args) { |f| f.read }
     if block_given?
       yield contents
     else

Modified: buildr/trunk/lib/buildr/core/transports.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/transports.rb?rev=950781&r1=950780&r2=950781&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/transports.rb (original)
+++ buildr/trunk/lib/buildr/core/transports.rb Wed Jun  2 21:49:29 2010
@@ -527,11 +527,12 @@ module URI
       "file://#{host}#{path}"
     end
 
-    # The URL path always starts with a backslash. On most operating systems (Linux, Darwin, BSD) it points
-    # to the absolute path on the file system. But on Windows, it comes before the drive letter, creating an
-    # unusable path, so real_path fixes that. Ugly but necessary hack.
+    # Returns the file system path based that corresponds to the URL path.
+    # On windows this method strips the leading slash off of the path.
+    # On all platforms this method unescapes the URL path.
     def real_path #:nodoc:
-      Buildr::Util.win_os? && path =~ /^\/[a-zA-Z]:\// ? path[1..-1] : path
+      real_path = Buildr::Util.win_os? && path =~ /^\/[a-zA-Z]:\// ? path[1..-1] : path
+      URI.unescape(real_path)
     end
 
   protected

Modified: buildr/trunk/lib/buildr/ide/eclipse.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/ide/eclipse.rb?rev=950781&r1=950780&r2=950781&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/ide/eclipse.rb (original)
+++ buildr/trunk/lib/buildr/ide/eclipse.rb Wed Jun  2 21:49:29 2010
@@ -360,12 +360,19 @@ module Buildr
 
       private
 
-      # Find a path relative to the project's root directory.
+      # Find a path relative to the project's root directory if possible. If the
+      # two paths do not share the same root the absolute path is returned. This
+      # can happen on Windows, for instance, when the two paths are not on the
+      # same drive.
       def relative path
         path or raise "Invalid path '#{path.inspect}'"
         msg = [:to_path, :to_str, :to_s].find { |msg| path.respond_to? msg }
         path = path.__send__(msg)
-        Util.relative_path(File.expand_path(path), @project.path_to)
+        begin
+          Util.relative_path(File.expand_path(path), @project.path_to)
+        rescue ArgumentError
+          File.expand_path(path)
+        end
       end
 
       def src_from_task task

Modified: buildr/trunk/spec/core/transport_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/core/transport_spec.rb?rev=950781&r1=950780&r2=950781&view=diff
==============================================================================
--- buildr/trunk/spec/core/transport_spec.rb (original)
+++ buildr/trunk/spec/core/transport_spec.rb Wed Jun  2 21:49:29 2010
@@ -20,7 +20,7 @@ require File.join(File.dirname(__FILE__)
 describe URI, '#download' do
   before do
     write @source = 'source', @content = 'Just a file'
-    @uri = URI("file://#{File.expand_path(@source)}")
+    @uri = URI(URI.escape("file://#{File.expand_path(@source)}"))
     @target = 'target'
   end
 
@@ -60,7 +60,7 @@ describe URI, '#upload' do
   before do
     write @source = 'source', @content = 'Just a file'
     @target = 'target'
-    @uri = URI("file://#{File.expand_path(@target)}")
+    @uri = URI(URI.escape("file://#{File.expand_path(@target)}"))
   end
 
   it 'should upload file if found' do
@@ -149,7 +149,7 @@ end
 describe URI::FILE, '#read' do
   before do
     @filename = 'readme'
-    @uri = URI("file:///#{File.expand_path(@filename)}")
+    @uri = URI(URI.escape("file:///#{File.expand_path(@filename)}"))
     @content = 'Readme. Please!'
     write 'readme', @content
   end
@@ -180,7 +180,7 @@ end
 describe URI::FILE, '#write' do
   before do
     @filename = 'readme'
-    @uri = URI("file:///#{File.expand_path(@filename)}")
+    @uri = URI(URI.escape("file:///#{File.expand_path(@filename)}"))
     @content = 'Readme. Please!'
   end
 

Modified: buildr/trunk/spec/core/util_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/core/util_spec.rb?rev=950781&r1=950780&r2=950781&view=diff
==============================================================================
--- buildr/trunk/spec/core/util_spec.rb (original)
+++ buildr/trunk/spec/core/util_spec.rb Wed Jun  2 21:49:29 2010
@@ -65,3 +65,61 @@ describe OpenObject do
     @obj.only(:a).should == { :a => 1 }
   end
 end
+
+describe File do
+  # Quite a few of the other specs depend on File#utime working correctly.
+  # These specs validate that utime is working as expected. 
+  describe "#utime" do
+    it "should update mtime of directories" do
+      mkpath 'tmp'
+      begin
+        creation_time = File.mtime('tmp')
+
+        sleep 1
+        File.utime(nil, nil, 'tmp')
+
+        File.mtime('tmp').should > creation_time
+      ensure
+        File.delete 'tmp'
+      end
+    end
+
+    it "should update mtime of files" do
+      FileUtils.touch('tmp')
+      begin
+        creation_time = File.mtime('tmp')
+
+        sleep 1
+        File.utime(nil, nil, 'tmp')
+
+        File.mtime('tmp').should > creation_time
+      ensure
+        File.delete 'tmp'
+      end
+    end
+
+    it "should be able to set mtime in the past" do
+      FileUtils.touch('tmp')
+      begin
+        time = Time.at((Time.now - 10).to_i)
+        File.utime(time, time, 'tmp')
+
+        File.mtime('tmp').should == time
+      ensure
+        File.delete 'tmp'
+      end
+    end
+
+    it "should be able to set mtime in the future" do
+      FileUtils.touch('tmp')
+      begin
+        time = Time.at((Time.now + 10).to_i)
+        File.utime(time, time, 'tmp')
+
+        File.mtime('tmp').should == time
+      ensure
+        File.delete 'tmp'
+      end
+    end
+  end
+end

Modified: buildr/trunk/spec/packaging/archive_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/packaging/archive_spec.rb?rev=950781&r1=950780&r2=950781&view=diff
==============================================================================
--- buildr/trunk/spec/packaging/archive_spec.rb (original)
+++ buildr/trunk/spec/packaging/archive_spec.rb Wed Jun  2 21:49:29 2010
@@ -403,17 +403,20 @@ describe ZipTask do
     inspect_archive { |archive| archive.keys.should include('code/') }
   end
 
-  it 'should preserve file permissions' do
-    # with JRuby it's important to use absolute paths with File.chmod()
-    # http://jira.codehaus.org/browse/JRUBY-3300
-    hello = File.expand_path('src/main/bin/hello')
-    write hello, 'echo hi'
-    File.chmod(0777,  hello) ||
-    fail("Failed to set permission on #{hello}") unless (File.stat(hello).mode & 0777) == 0777
-
-    zip('foo.zip').include('src/main/bin/*').invoke
-    unzip('target' => 'foo.zip').extract
-    (File.stat('target/hello').mode & 0777).should == 0777
+  # chmod is not reliable on Windows
+  unless Buildr::Util.win_os?
+    it 'should preserve file permissions' do
+      # with JRuby it's important to use absolute paths with File.chmod()
+      # http://jira.codehaus.org/browse/JRUBY-3300
+      hello = File.expand_path('src/main/bin/hello')
+      write hello, 'echo hi'
+      File.chmod(0777,  hello)
+      fail("Failed to set permission on #{hello}") unless (File.stat(hello).mode & 0777) == 0777
+
+      zip('foo.zip').include('src/main/bin/*').invoke
+      unzip('target' => 'foo.zip').extract
+      (File.stat('target/hello').mode & 0777).should == 0777
+    end
   end
 
 end

Modified: buildr/trunk/spec/packaging/packaging_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/packaging/packaging_spec.rb?rev=950781&r1=950780&r2=950781&view=diff
==============================================================================
--- buildr/trunk/spec/packaging/packaging_spec.rb (original)
+++ buildr/trunk/spec/packaging/packaging_spec.rb Wed Jun  2 21:49:29 2010
@@ -625,7 +625,7 @@ end
 
 describe Rake::Task, ' upload' do
   before do
-    repositories.release_to = "file://#{File.expand_path('remote')}"
+    repositories.release_to = URI.escape("file://#{File.expand_path('remote')}")
   end
 
   it 'should be local task' do
@@ -660,8 +660,8 @@ describe Rake::Task, ' upload' do
     task('upload').invoke
     { 'remote/foo/foo/1.0/foo-1.0.jar'=>project('foo').package(:jar),
       'remote/foo/foo/1.0/foo-1.0.pom'=>project('foo').package(:jar).pom }.each do |upload, package|
-      read("#{upload}.md5").split.first.should eql(Digest::MD5.hexdigest(read(package)))
-      read("#{upload}.sha1").split.first.should eql(Digest::SHA1.hexdigest(read(package)))
+      read("#{upload}.md5").split.first.should eql(Digest::MD5.hexdigest(read(package, "rb")))
+      read("#{upload}.sha1").split.first.should eql(Digest::SHA1.hexdigest(read(package, "rb")))
     end
   end
 end