Author: lacton
Date: Sat Sep 13 12:03:13 2008
New Revision: 695005
URL: http://svn.apache.org/viewvc?rev=695005&view=rev
Log:
Fixed defect that would prevent compilation on OS X because of lack of
tools.jar. Centralized the tools.jar conditional logic.
Modified:
incubator/buildr/trunk/lib/buildr/java/compilers.rb
incubator/buildr/trunk/lib/buildr/java/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/compilers.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/java/compilers.rb?rev=695005&r1=695004&r2=695005&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/java/compilers.rb (original)
+++ incubator/buildr/trunk/lib/buildr/java/compilers.rb Sat Sep 13 12:03:13 2008
@@ -54,13 +54,8 @@
def compile(sources, target, dependencies) #:nodoc:
check_options options, OPTIONS
cmd_args = []
- # 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) }
- dependencies << tools_jar if File.exist?(tools_jar)
+ # tools.jar contains the Java compiler.
+ Java.tools_jar { |tools_jar| dependencies << tools_jar }
cmd_args << '-classpath' << dependencies.join(File::PATH_SEPARATOR)
unless dependencies.empty?
source_paths = sources.select { |source| File.directory?(source) }
cmd_args << '-sourcepath' << source_paths.join(File::PATH_SEPARATOR)
unless source_paths.empty?
Modified: incubator/buildr/trunk/lib/buildr/java/java.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/java/java.rb?rev=695005&r1=695004&r2=695005&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/java/java.rb (original)
+++ incubator/buildr/trunk/lib/buildr/java/java.rb Sat Sep 13 12:03:13 2008
@@ -57,8 +57,11 @@
# 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. Return nil if not found.
+ # If given a block, it yields the path to tools.jar, if tools.jar was
found.
def 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) }
+ 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) }
+ yield tools_jar if block_given? && !tools_jar.nil?
+ tools_jar
end
end
end
Modified: incubator/buildr/trunk/lib/buildr/java/jruby.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/java/jruby.rb?rev=695005&r1=695004&r2=695005&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/java/jruby.rb (original)
+++ incubator/buildr/trunk/lib/buildr/java/jruby.rb Sat Sep 13 12:03:13 2008
@@ -90,7 +90,7 @@
add_path = lambda { |path| add_url_method.invoke(sysloader,
[java.io.File.new(path).toURI.toURL].to_java(java.net.URL)) }
# Most platforms requires tools.jar to be on the classpath.
- add_path[tools_jar] if tools_jar
+ tools_jar { |tools_jar| add_path[tools_jar] }
Buildr.artifacts(classpath).map(&:to_s).each do |path|
file(path).invoke
Modified: incubator/buildr/trunk/lib/buildr/java/rjb.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/java/rjb.rb?rev=695005&r1=695004&r2=695005&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/java/rjb.rb (original)
+++ incubator/buildr/trunk/lib/buildr/java/rjb.rb Sat Sep 13 12:03:13 2008
@@ -98,7 +98,7 @@
def load
return self if @loaded
ENV['JAVA_HOME'] or fail 'Are we forgetting something? JAVA_HOME not
set.'
- classpath << Java.tools_jar if Java.tools_jar
+ tools_jar { |tools_jar| classpath << tools_jar }
cp = Buildr.artifacts(classpath).map(&:to_s).each { |path|
file(path).invoke }
java_opts = (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split
Modified: incubator/buildr/trunk/spec/java_spec.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/trunk/spec/java_spec.rb?rev=695005&r1=695004&r2=695005&view=diff
==============================================================================
--- incubator/buildr/trunk/spec/java_spec.rb (original)
+++ incubator/buildr/trunk/spec/java_spec.rb Sat Sep 13 12:03:13 2008
@@ -42,26 +42,59 @@
end
-describe Java, 'tools_jar' do
+describe Java, '#tools_jar' do
before do
@old_home = ENV['JAVA_HOME']
end
- it 'should return $JAVA_HOME/lib/tools.jar if JAVA_HOME points to JDK' do
- write 'jdk/lib/tools.jar'
- ENV['JAVA_HOME'] = File.expand_path('jdk')
- Java.tools_jar.should point_to_path('jdk/lib/tools.jar')
+ describe 'when JAVA_HOME points to a JDK' do
+ before do
+ write 'jdk/lib/tools.jar'
+ ENV['JAVA_HOME'] = File.expand_path('jdk')
+ end
+
+ it 'should return the path to tools.jar' do
+ Java.tools_jar.should point_to_path('jdk/lib/tools.jar')
+ end
+
+ it 'should accept a block and yield the path to tools.jar' do
+ tools_jar_received_by_block = nil
+ Java.tools_jar { |tools_jar| tools_jar_received_by_block = tools_jar }
+ tools_jar_received_by_block.should point_to_path('jdk/lib/tools.jar')
+ end
end
- it 'should return $JAVA_HOME/../lib/tools.jar if JAVA_HOME points to a JRE
inside a JDK' do
- write 'jdk/lib/tools.jar'
- ENV['JAVA_HOME'] = File.expand_path('jdk/jre')
- Java.tools_jar.should point_to_path('jdk/lib/tools.jar')
+ describe 'when JAVA_HOME points to a JRE inside a JDK' do
+ before do
+ write 'jdk/lib/tools.jar'
+ ENV['JAVA_HOME'] = File.expand_path('jdk/jre')
+ end
+
+ it 'should return the path to tools.jar' do
+ Java.tools_jar.should point_to_path('jdk/lib/tools.jar')
+ end
+
+ it 'should accept a block and yield the path to tools.jar' do
+ tools_jar_received_by_block = nil
+ Java.tools_jar { |tools_jar| tools_jar_received_by_block = tools_jar }
+ tools_jar_received_by_block.should point_to_path('jdk/lib/tools.jar')
+ end
end
- it 'should return nil if tools.jar not found' do
- ENV['JAVA_HOME'] = File.expand_path('jdk')
- Java.tools_jar.should be(nil)
+ describe 'when there is no tools.jar' do
+ before do
+ ENV['JAVA_HOME'] = File.expand_path('jdk')
+ end
+
+ it 'should return nil' do
+ Java.tools_jar.should be(nil)
+ end
+
+ it 'should accept a block and not yield to it' do
+ block_called = false
+ Java.tools_jar { block_called = true }
+ block_called.should be(false)
+ end
end
after do