Author: boisvert
Date: Fri Sep 18 19:09:01 2009
New Revision: 816748

URL: http://svn.apache.org/viewvc?rev=816748&view=rev
Log:
BUILDR-289: Improve error message when JAVA_HOME points to an invalid JRE/JDK 
installation

Modified:
    buildr/trunk/CHANGELOG
    buildr/trunk/lib/buildr/java/commands.rb
    buildr/trunk/spec/java/java_spec.rb

Modified: buildr/trunk/CHANGELOG
URL: 
http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=816748&r1=816747&r2=816748&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Fri Sep 18 19:09:01 2009
@@ -1,4 +1,5 @@
 1.3.5 (Pending)
+* Fixed:  BUILDR-289 Improved error message when JAVA_HOME points to an 
invalid JRE/JDK installation
 * Fixed:  BUILDR-301 TestNG doesn't report failure if more than one test fails
 * Fixed:  BUILDR-313 Prevent release with uncommitted_files on Git 1.4.3+ 
(Alexis Midon)
 * Fixed:  BUILDR-315 Fix Eclipse .classpath for local libraries (Mat Schaffer)

Modified: buildr/trunk/lib/buildr/java/commands.rb
URL: 
http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/java/commands.rb?rev=816748&r1=816747&r2=816748&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/java/commands.rb (original)
+++ buildr/trunk/lib/buildr/java/commands.rb Fri Sep 18 19:09:01 2009
@@ -190,7 +190,9 @@
       # Returns the path to the specified Java command (with no argument to 
java itself).
       def path_to_bin(name = nil)
         home = ENV['JAVA_HOME'] or fail 'Are we forgetting something? 
JAVA_HOME not set.'
-        File.expand_path(File.join(home, 'bin', name.to_s))
+        bin = File.expand_path(File.join(home, 'bin'))
+        fail 'JAVA_HOME environment variable does not point to a valid JRE/JDK 
installation.' unless File.exist? bin
+        File.expand_path(File.join(bin, name.to_s))
       end
 
       # :call-seq:

Modified: buildr/trunk/spec/java/java_spec.rb
URL: 
http://svn.apache.org/viewvc/buildr/trunk/spec/java/java_spec.rb?rev=816748&r1=816747&r2=816748&view=diff
==============================================================================
--- buildr/trunk/spec/java/java_spec.rb (original)
+++ buildr/trunk/spec/java/java_spec.rb Fri Sep 18 19:09:01 2009
@@ -89,6 +89,32 @@
   end
 end
 
+describe Java, '#java' do
+  before do
+    @old_home = ENV['JAVA_HOME']
+  end
+  
+  describe 'when JAVA_HOME points to an invalid JRE/JDK installation' do
+    before do
+      write 'jdk'
+      ENV['JAVA_HOME'] = File.expand_path('jdk')
+    end
+  
+    it 'should fail with an error message mentioning JAVA_HOME' do
+      begin
+        Java.java ['-version']
+        fail 'Java.java did not fail with JAVA_HOME pointing to invalid 
JRE/JDK installation'
+      rescue => error
+        error.message.to_s.should match(/JAVA_HOME/)
+      end
+    end
+  end
+  
+  after do
+    ENV['JAVA_HOME'] = @old_home
+  end
+end
+
 
 describe Java::JavaWrapper do
   it 'should be removed in version 1.5 since it was deprecated in version 1.3' 
do


Reply via email to