lib/java/java.rb in buildr-1.2.8 vs lib/java/java.rb in buildr-1.2.9
- old
+ new
@@ -26,65 +26,62 @@
include Singleton
def initialize() #:nodoc:
@classpath = [Java.tools_jar].compact
+ if RUBY_PLATFORM == 'java'
+ # 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
@setup = []
+
setup do
setup do
- classpath = Buildr.artifacts(@classpath).
- each { |task| task.invoke if task.respond_to?(:invoke) }.
- map(&:to_s)
+ cp = Buildr.artifacts(@classpath).map(&:to_s)
+ cp.each { |path| file(path).invoke }
- if RUBY_PLATFORM != 'java'
- ::Rjb.load classpath.join(File::PATH_SEPARATOR),
- Buildr.options.java_args.flatten
- else
- classpath.each do |jlib|
+ if RUBY_PLATFORM == 'java'
+ cp.each do |jlib|
require jlib
end
+ else
+ ::Rjb.load cp.join(File::PATH_SEPARATOR), Buildr.options.java_args.flatten
end
end
end
end
- def classpath
- if RUBY_PLATFORM == 'java'
- # in order to get a complete picture, we need to add a few jars to the
- # list.
- java.lang.System.getProperty('java.class.path').split(':') +
- @classpath
- else
- @classpath
- end
- end
+ attr_accessor :classpath
- attr_writer :classpath
-
def setup(&block)
@setup << block
self
end
+
+ def onload(&block)
+ warn_deprecated "use setup { |wrapper| ... } instead"
+ setup &block
+ end
- def load()
+ def load(&block)
@setup.each { |block| block.call self }
@setup.clear
end
def import(jlib)
if RUBY_PLATFORM == 'java'
- Java.send(jlib)
+ ::Java.send(jlib)
else
::Rjb.import jlib
end
end
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'
- Java.send sym, *args, &block
+ ::Java.send sym, *args, &block
else
::Rjb.send sym, *args, &block
end
end
end
@@ -325,23 +322,31 @@
# JavaWrapper object which you can use to configure the classpath or call
# other methods. With a block, loads RJB or sets up JRuby and yields to
# the block, returning its result.
#
# For example:
+ # # Add class path dependency.
# Java.wrapper.classpath << REQUIRES
+ # # Require AntWrap when loading RJB/JRuby.
# Java.wrapper.setup { require "antwrap" }
#
# def execute(name, options)
# options = options.merge(:name=>name, :base_dir=>Dir.pwd, :declarative=>true)
+ # # Load RJB/JRuby and run AntWrap.
# Java.wrapper { AntProject.new(options) }
# end
def wrapper()
if block_given?
JavaWrapper.instance.load
yield JavaWrapper.instance
else
JavaWrapper.instance
end
+ end
+
+ def rjb(&block)
+ warn_deprecated "please use Java.wrapper() instead"
+ wrapper &block
end
# :call-seq:
# path_to_bin(cmd?) => path
#