You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by vb...@apache.org on 2008/03/05 20:28:43 UTC

svn commit: r633990 - /incubator/buildr/trunk/lib/java/nailgun.rb

Author: vborja
Date: Wed Mar  5 11:28:41 2008
New Revision: 633990

URL: http://svn.apache.org/viewvc?rev=633990&view=rev
Log:
Redirect stdio to nailgun client.

JRuby 1.1RC2 fails at reopenning STDIN, the workaround is to
redefine the $stdin global and STDIN constants.
Also Kernel#gets, Kernel#readline, etc, must be avoided and
user must use
  $stdin.gets, $stdin.readline, etc

Modified:
    incubator/buildr/trunk/lib/java/nailgun.rb

Modified: incubator/buildr/trunk/lib/java/nailgun.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/java/nailgun.rb?rev=633990&r1=633989&r2=633990&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/java/nailgun.rb (original)
+++ incubator/buildr/trunk/lib/java/nailgun.rb Wed Mar  5 11:28:41 2008
@@ -3,6 +3,12 @@
   # To start the nailgun server run the ng:start task, this will
   # download, compile and installed nailgun if needed, afterwards
   # it will start the nailgun server.
+  #
+  # Issues:
+  #   JRuby 1.1RC2 fails at reopening STDIN, so the workaround is
+  #   to redefine the $stdin global and STDIN constant. 
+  #   Kernel#gets, readline, etc, must be avoided and you should use
+  #   $stdin#gets
   module Nailgun 
     VERSION = '0.7.1'
     NAME = "nailgun-#{VERSION}"
@@ -56,10 +62,17 @@
         cp compiled_bin.to_s, task.to_s, :verbose => false
       end
 
-      task :boot => artifact do
+      task :boot => artifact do |task|
         if $nailgun_server
           raise "Already nunning on Nailgun server: #{$nailgun_server}"
         end
+        tasks = Rake.application.instance_eval { @top_level_tasks.dup }
+        tasks.delete_if do |t| 
+          t =~ /^(buildr:initialize|(ng|nailgun):.+)$/
+        end
+        unless tasks.empty?
+          raise "Don't specify more targets when starting Nailgun server"
+        end
         BOOT.call
       end
       
@@ -77,6 +90,36 @@
   Nailgun::BOOT = lambda do
     require 'jruby'
     
+    class ::ConcreteJavaProxy
+      def self.jclass(name = nil)
+        name ||= self.java_class.name
+        Nailgun::Util.class_for_name(name)
+      end
+      
+      def self.jnew(*args)
+        objs = []
+        classes = args.map do |a|
+          case a
+          when nil
+            obj << nil
+            nil
+          when Hash
+            objs << a.keys.first
+            cls = a.values.first
+            cls = Nailgun::Util.proxy_class(cls) if String == cls
+            cls
+          else
+            objs << a
+            a.java_class
+          end
+        end
+        classes = classes.to_java(java.lang.Class)
+        ctor = jclass.getDeclaredConstructor(classes)
+        ctor.setAccessible(true)
+        ctor.newInstance(objs.to_java(java.lang.Object))
+      end
+    end
+    
     class Application
       def buildfile(dir = nil, candidates = nil)
         Nailgun::Util.find_buildfile(dir || Dir.pwd, candidates || @rakefiles)
@@ -88,35 +131,6 @@
     end
 
     module Nailgun
-      class ::ConcreteJavaProxy
-        def self.jclass(name = nil)
-          name ||= self.java_class.name
-          Util.class_for_name(name)
-        end
-        
-        def self.jnew(*args)
-          objs = []
-          classes = args.map do |a|
-            case a
-            when nil
-              obj << nil
-              nil
-            when Hash
-              objs << a.keys.first
-              cls = a.values.first
-              cls = Util.proxy_class(cls) if String == cls
-              cls
-            else
-              objs << a
-              a.java_class
-            end
-          end
-          classes = classes.to_java(java.lang.Class)
-          ctor = jclass.getDeclaredConstructor(classes)
-          ctor.setAccessible(true)
-          ctor.newInstance(objs.to_java(java.lang.Object))
-        end
-      end
       
       module Util
         extend self
@@ -176,12 +190,11 @@
           end
           
           begin
-            p nail.in
             input  = RubyIO.jnew(runtime, java.lang.System.in => java.io.InputStream)
             output = RubyIO.jnew(runtime, nail.out => java.io.OutputStream)
             error = RubyIO.jnew(runtime, nail.err => java.io.OutputStream)
             #stdin.reopen(input, 'r') # not working on jruby :(
-            #set_in.call(input)
+            set_in.call(input)
             stdout.reopen(output)
             stderr.reopen(error)
             result = yield
@@ -189,7 +202,7 @@
             input  = RubyIO.jnew(runtime, java.lang.System.in => java.io.InputStream)
             output = RubyIO.jnew(runtime, java.lang.System.out => java.io.OutputStream)
             error = RubyIO.jnew(runtime, java.lang.System.err => java.io.OutputStream)
-            #set_in.call(input)
+            set_in.call(input)
             stdout.reopen(output)
             stderr.reopen(error)
           end