Author: assaf
Date: Mon Dec 10 11:42:03 2007
New Revision: 603012

URL: http://svn.apache.org/viewvc?rev=603012&view=rev
Log:
More patches towards JRuby support, courtesy of Vic Borja

Modified:
    incubator/buildr/trunk/CHANGELOG
    incubator/buildr/trunk/Rakefile
    incubator/buildr/trunk/lib/java/java.rb

Modified: incubator/buildr/trunk/CHANGELOG
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/CHANGELOG?rev=603012&r1=603011&r2=603012&view=diff
==============================================================================
--- incubator/buildr/trunk/CHANGELOG (original)
+++ incubator/buildr/trunk/CHANGELOG Mon Dec 10 11:42:03 2007
@@ -1,5 +1,6 @@
 1.2.11 (Pending)
 * Fixed: Artifact.pom resolves artifact without classifier, i.e 
org.testng:testng:jar:jdk15:5.1 uses org.testng:testng:pom:5.1 (Tommy).
+* Fixed: More patches towards JRuby support, courtesy of Vic Borja.
 
 1.2.10 (11/26/2007)
 * Changed: Resources sets permission on copied files to make them 
read/write-able.

Modified: incubator/buildr/trunk/Rakefile
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/Rakefile?rev=603012&r1=603011&r2=603012&view=diff
==============================================================================
--- incubator/buildr/trunk/Rakefile (original)
+++ incubator/buildr/trunk/Rakefile Mon Dec 10 11:42:03 2007
@@ -13,7 +13,8 @@
     spec.email        = "[EMAIL PROTECTED]"
     spec.homepage     = "http://incubator.apache.org/#{spec.name}/";
     spec.summary      = "A build system that doesn't suck"
-    spec.files        = FileList["lib/**/*", "CHANGELOG", "README", "LICENSE", 
"NOTICE", "DISCLAIMER", "Rakefile"].collect
+    spec.files        = FileList["lib/**/*", "CHANGELOG", "README", "LICENSE", 
"NOTICE", "DISCLAIMER",
+                                 "Rakefile", "test/**/*", "doc/**/*"].collect
     spec.require_path = "lib"
     spec.autorequire  = "buildr.rb"
     spec.has_rdoc     = true

Modified: incubator/buildr/trunk/lib/java/java.rb
URL: 
http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/java.rb?rev=603012&r1=603011&r2=603012&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/java.rb (original)
+++ incubator/buildr/trunk/lib/java/java.rb Mon Dec 10 11:42:03 2007
@@ -28,7 +28,7 @@
 
       def initialize() #:nodoc:
         @classpath = [Java.tools_jar].compact
-        if RUBY_PLATFORM == 'java'
+        if Java.jruby?
           # in order to get a complete picture, we need to add a few jars to 
the list.
           @classpath += 
java.lang.System.getProperty('java.class.path').split(':').compact
         end
@@ -39,7 +39,7 @@
             cp = Buildr.artifacts(@classpath).map(&:to_s)
             cp.each { |path| file(path).invoke }
 
-            if RUBY_PLATFORM == 'java'
+            if Java.jruby?
               cp.each do |jlib|
                 require jlib
               end
@@ -68,8 +68,8 @@
       end
 
       def import(jlib)
-        if RUBY_PLATFORM == 'java'
-          ::Java.send(jlib)
+        if Java.jruby?
+          ::Java.instance_eval(jlib)
         else
           ::Rjb.import jlib
         end
@@ -78,7 +78,7 @@
       def method_missing(sym, *args, &block) #:nodoc:
         # these aren't the same, but depending on method_missing while
         # supporting two unrelated systems is asking for trouble anyways.
-        if RUBY_PLATFORM == 'java'
+        if Java.jruby?
           ::Java.send sym, *args, &block
         else
           ::Rjb.send sym, *args, &block
@@ -184,6 +184,7 @@
           puts "Running apt" if verbose
           puts (["apt"] + cmd_args).join(" ") if Rake.application.options.trace
           Java.wrapper do |jw|
+            cmd_args = cmd_args.to_java_array(::Java.java.lang.String) if 
Java.jruby?
             jw.import("com.sun.tools.apt.Main").process(cmd_args) == 0 or
               fail "Failed to process annotations, see errors above"
           end
@@ -221,7 +222,8 @@
           puts "Compiling #{files.size} source files in #{name}" if verbose
           puts (["javac"] + cmd_args).join(" ") if 
Rake.application.options.trace
           Java.wrapper do |jw|
-            jw.import("com.sun.tools.javac.Main").compile(cmd_args) == 0 or
+            cmd_args = cmd_args.to_java_array(::Java.java.lang.String) if 
Java.jruby?
+            jw.import("com.sun.tools.javac.Main").compile(cmd_args) == 0 or 
               fail "Failed to compile, see errors above"
           end
         end
@@ -272,6 +274,7 @@
           puts "Generating Javadoc for #{name}" if verbose
           puts (["javadoc"] + cmd_args).join(" ") if 
Rake.application.options.trace
           Java.wrapper do |jw|
+            cmd_args = cmd_args.to_java_array(::Java.java.lang.String) if 
Java.jruby?
             jw.import("com.sun.tools.javadoc.Main").execute(cmd_args) == 0 or
               fail "Failed to generate Javadocs, see errors above"
           end
@@ -356,6 +359,11 @@
         File.join(home, "bin", name)
       end
 
+      # return true if we a running on c-ruby and must use rjb
+      def rjb?; RUBY_PLATFORM != "java"; end
+      # return true if we are running on jruby
+      def jruby?; RUBY_PLATFORM == "java"; end
+
   protected
 
       # :call-seq:
@@ -427,6 +435,20 @@
       @java_args = args.to_a
     end
 
+  end
+
+end
+
+
+if Buildr::Java.jruby?
+  
+  # Convert a RubyArray to a Java Object[] array of the specified element_type
+  class Array
+    def to_java_array(element_type)
+      java_array = ::Java.java.lang.reflect.Array.newInstance(element_type, 
self.size)
+      self.each_index { |i| java_array[i] = self[i] }
+      return java_array
+    end
   end
 
 end


Reply via email to