Permalink
Browse files

Explicitly add javac path to classpath before loading the ant extensi…

…on. It copies the behaviour of the ant script.
  • Loading branch information...
1 parent b5ae167 commit 4ac3a7bef5692dd3c3ba559098108fc64582d74b @calavera calavera committed Jun 7, 2010
Showing with 47 additions and 2 deletions.
  1. +13 −1 lib/ruby/site_ruby/shared/ant.rb
  2. +34 −1 spec/java_integration/ant/ant_spec.rb
@@ -15,7 +15,7 @@ def self.load_from_ant
listing_path = $1
elsif line =~ /^(.*\.home): (.*)$/
home_var, path = $1, $2
- jar_path = listing_path.sub(home_var.upcase.sub('.','_'), path)
+ jar_path = listing_path.sub(home_var.upcase.sub('.','_'), path) if listing_path
elsif line =~ /^ant\.core\.lib: (.*)$/
classpath_jars << $1
elsif line =~ /^(.*\.jar) \(\d+ bytes\)/
@@ -33,7 +33,19 @@ def self.load
else
load_from_ant
end
+
+ # Explicitly add javac path to classpath
+ if ENV['JAVA_HOME'] && File.exist?(ENV['JAVA_HOME'])
+ const_set(:JAVA_HOME, ENV['JAVA_HOME'])
+ load_if_exist "#{JAVA_HOME}/lib/tools.jar"
+ load_if_exist "#{JAVA_HOME}/lib/classes.zip"
+ end
end
+
+ def self.load_if_exist(jar)
+ $CLASSPATH << jar if File.exist?(jar)
+ end
+
load
end
@@ -1,6 +1,39 @@
require File.expand_path('../../ant_spec_helper', __FILE__)
-describe Ant, "new", :type => :ant do
+describe Ant, '.load', :type => :ant do
+ before :each do
+ @previous_java_home = ENV['JAVA_HOME']
+
+ ENV['JAVA_HOME'] = '/System/Library/Frameworks/JavaVM.framework/Home'
+ @tools_jar = "#{ENV['JAVA_HOME']}/lib/tools.jar"
+ @classes_zip = "#{ENV['JAVA_HOME']}/lib/classes.zip"
+ end
+
+ after :each do
+ ENV['JAVA_HOME'] = @previous_java_home
+ end
+
+ it "adds tools.jar to the CLASSPATH when JAVA_HOME is set and it exists" do
+ stubs_file!
+ Ant.load
+ $CLASSPATH.should include("file:#{@tools_jar}")
+ end
+
+ it "adds classes.zip to the CLASSPATH when JAVA_HOME is set and it exists" do
+ stubs_file!
+ Ant.load
+ $CLASSPATH.should include("file:#{@classes_zip}")
+ end
+
+ def stubs_file!
+ File.stub!(:exist?).and_return false
+ File.should_receive(:exist?).with(ENV['JAVA_HOME']).and_return true
+ File.should_receive(:exist?).with(@tools_jar).and_return true
+ File.should_receive(:exist?).with(@classes_zip).and_return true
+ end
+end
+
+describe Ant, ".new", :type => :ant do
it "can be instantiated with a block" do
Ant.new do
self.class.should == Ant

0 comments on commit 4ac3a7b

Please sign in to comment.