You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by as...@apache.org on 2008/09/08 23:31:59 UTC

svn commit: r693281 - in /incubator/buildr/trunk: lib/buildr/java.rb lib/buildr/java/jruby.rb lib/buildr/java/rjb.rb spec/java_spec.rb

Author: assaf
Date: Mon Sep  8 14:31:58 2008
New Revision: 693281

URL: http://svn.apache.org/viewvc?rev=693281&view=rev
Log:
Only use tools.jar on platforms that require it; don't break on platforms that don't (e.g OS X).

Modified:
    incubator/buildr/trunk/lib/buildr/java.rb
    incubator/buildr/trunk/lib/buildr/java/jruby.rb
    incubator/buildr/trunk/lib/buildr/java/rjb.rb
    incubator/buildr/trunk/spec/java_spec.rb

Modified: incubator/buildr/trunk/lib/buildr/java.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/java.rb?rev=693281&r1=693280&r2=693281&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/java.rb (original)
+++ incubator/buildr/trunk/lib/buildr/java.rb Mon Sep  8 14:31:58 2008
@@ -14,23 +14,7 @@
 # the License.
 
 
-ENV['JAVA_HOME'] ||= '/System/Library/Frameworks/JavaVM.framework/Home' if Config::CONFIG['host_os'] =~ /darwin/i
 require RUBY_PLATFORM == 'java' ? 'buildr/java/jruby' : 'buildr/java/rjb'
-
-module Java
-  class << self
-    # Returns the path to the tools.jar in JAVA_HOME
-    def tools_jar
-      home = java_home
-      tools_jar = File.expand_path('lib/tools.jar', home)
-      # if java_home is a jre inside jdk...
-      tools_jar = File.expand_path('../lib/tools.jar', home) unless File.exist?(tools_jar)
-      raise "I need tools.jar, can't find it in #{home}/lib" unless File.exist?(tools_jar)
-      tools_jar
-    end
-  end
-end
-
 require 'buildr/java/compilers'
 require 'buildr/java/test_frameworks'
 require 'buildr/java/bdd_frameworks'

Modified: incubator/buildr/trunk/lib/buildr/java/jruby.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/java/jruby.rb?rev=693281&r1=693280&r2=693281&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/java/jruby.rb (original)
+++ incubator/buildr/trunk/lib/buildr/java/jruby.rb Mon Sep  8 14:31:58 2008
@@ -56,12 +56,10 @@
 # 4. Check on a clean build with empty local repository.
 module Java
 
-  class << self
+  # Since we already have a JVM loaded, we can use it to guess where JAVA_HOME is.
+  ENV['JAVA_HOME'] ||= java.lang.System.getProperty("java.home")
 
-    # Returns the path to JAVA_HOME
-    def java_home
-      ENV['JAVA_HOME'] || java.lang.System.getProperty("java.home")
-    end
+  class << self
 
     # Returns the classpath, an array listing directories, JAR files and
     # artifacts.  Use when loading the extension to add any additional
@@ -79,7 +77,6 @@
     # that append to the classpath and specify which remote repositories to use.
     def load
       return self if @loaded
-      cp = Buildr.artifacts(classpath).map(&:to_s).each { |path| file(path).invoke }
 
       # Adding jars to the jruby's $CLASSPATH should be the correct thing, however it
       # seems like some tools require their jars on system class loader (javadoc, junit, etc)
@@ -92,8 +89,18 @@
       add_url_method.setAccessible(true)
       add_path = lambda { |path| add_url_method.invoke(sysloader, [java.io.File.new(path).toURI.toURL].to_java(java.net.URL)) }
 
-      add_path[tools_jar]
-      cp.each(&add_path)
+      # Most platforms requires tools.jar to be on the classpath, tools.jar contains the
+      # Java compiler (OS X and AIX are two exceptions we know about, may be more).
+      # Guess where tools.jar is from JAVA_HOME, which hopefully points to the JDK,
+      # but maybe the JRE.
+      tools_jar = [File.expand_path('lib/tools.jar', ENV['JAVA_HOME']), File.expand_path('../lib/tools.jar', ENV['JAVA_HOME'])].
+        find { |path| File.exist?(path) }
+      add_path[tools_jar] if tools_jar
+      
+      Buildr.artifacts(classpath).map(&:to_s).each do |path|
+        file(path).invoke
+        add_path[path]
+        end
       
       @loaded = true
       self

Modified: incubator/buildr/trunk/lib/buildr/java/rjb.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/java/rjb.rb?rev=693281&r1=693280&r2=693281&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/java/rjb.rb (original)
+++ incubator/buildr/trunk/lib/buildr/java/rjb.rb Mon Sep  8 14:31:58 2008
@@ -72,14 +72,15 @@
 
   end
 
+
+  # On OS X we know where the default JDK is. We can try to guess for other OS.
+  case Config::CONFIG['host_os']
+  when /darwin/i ; ENV['JAVA_HOME'] ||= '/System/Library/Frameworks/JavaVM.framework/Home'
+  end
+
+
   class << self
     
-    # Returns the path to JAVA_HOME on environment. 
-    # Raises an exception if no JAVA_HOME is set.
-    def java_home
-      ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.'
-    end
-
     # Returns the classpath, an array listing directories, JAR files and
     # artifacts.  Use when loading the extension to add any additional
     # libraries used by that extension.
@@ -96,8 +97,16 @@
     # that append to the classpath and specify which remote repositories to use.
     def load
       return self if @loaded
+      # Most platforms requires tools.jar to be on the classpath, tools.jar contains the
+      # Java compiler (OS X and AIX are two exceptions we know about, may be more).
+      # Guess where tools.jar is from JAVA_HOME, which hopefully points to the JDK,
+      # but maybe the JRE.
+      ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not set.'
+      tools = [File.expand_path('lib/tools.jar', ENV['JAVA_HOME']), File.expand_path('../lib/tools.jar', ENV['JAVA_HOME'])].
+        find { |path| File.exist?(path) }
+      classpath << tools if tools
+      
       cp = Buildr.artifacts(classpath).map(&:to_s).each { |path| file(path).invoke }
-      cp << tools_jar
       java_opts = (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split
       ::Rjb.load cp.join(File::PATH_SEPARATOR), java_opts
 

Modified: incubator/buildr/trunk/spec/java_spec.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/java_spec.rb?rev=693281&r1=693280&r2=693281&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/java_spec.rb (original)
+++ incubator/buildr/trunk/spec/java_spec.rb Mon Sep  8 14:31:58 2008
@@ -15,24 +15,26 @@
 
 require File.join(File.dirname(__FILE__), 'spec_helpers')
 
-describe ENV, 'JAVA_HOME on OS X' do
-  before do
-    @old_home, ENV['JAVA_HOME'] = ENV['JAVA_HOME'], nil
-    Config::CONFIG.should_receive(:[]).with('host_os').and_return('darwin0.9')
-  end
+unless RUBY_PLATFORM =~ /java/
+  describe ENV, 'JAVA_HOME on OS X' do
+    before do
+      @old_home, ENV['JAVA_HOME'] = ENV['JAVA_HOME'], nil
+      Config::CONFIG.should_receive(:[]).with('host_os').and_return('darwin0.9')
+    end
 
-  it 'should point to default JVM' do
-    load File.expand_path('../lib/buildr/java.rb')
-    ENV['JAVA_HOME'].should == '/System/Library/Frameworks/JavaVM.framework/Home'
-  end
+    it 'should point to default JVM' do
+      load File.expand_path('../lib/buildr/java/rjb.rb')
+      ENV['JAVA_HOME'].should == '/System/Library/Frameworks/JavaVM.framework/Home'
+    end
 
-  it 'should use value of environment variable if specified' do
-    ENV['JAVA_HOME'] = '/System/Library/Frameworks/JavaVM.specified'
-    load File.expand_path('../lib/buildr/java.rb')
-    ENV['JAVA_HOME'].should == '/System/Library/Frameworks/JavaVM.specified'
-  end
+    it 'should use value of environment variable if specified' do
+      ENV['JAVA_HOME'] = '/System/Library/Frameworks/JavaVM.specified'
+      load File.expand_path('../lib/buildr/java/rjb.rb')
+      ENV['JAVA_HOME'].should == '/System/Library/Frameworks/JavaVM.specified'
+    end
 
-  after do
-    ENV['JAVA_HOME'] = @old_home
+    after do
+      ENV['JAVA_HOME'] = @old_home
+    end
   end
-end
+end
\ No newline at end of file