lib/java/java.rb in buildr-1.0.0 vs lib/java/java.rb in buildr-1.1.0

- old
+ new

@@ -24,11 +24,11 @@ class RjbWrapper include Singleton def initialize() #:nodoc: - @classpath = [Java.tools_jar] + @classpath = [Java.tools_jar].compact @onload = [] onload do onload do Rjb.load(Buildr.artifacts(classpath).each { |task| task.invoke if task.respond_to?(:invoke) }. map(&:to_s).join(File::PATH_SEPARATOR)) @@ -38,11 +38,11 @@ # The classpath used when loading RJB. attr_accessor :classpath # :call-seq: - # onload { ... } + # onload { |rjb| ... } # # Adds a block to call when loading RJB and returns self. # # You can only load RJB once, and you may need to do some tasks after the initial load. # For example, the Ant module requires Antwrap which can only be loaded after RJB. @@ -54,11 +54,11 @@ # :call-seq: # load() # # Loads RJB. You can also call Java#ejb with a block to get the same effect. def load() - @onload.each(&:call) + @onload.each { |block| block.call self } @onload.clear end def method_missing(sym, *args, &block) #:nodoc: Rjb.send sym, *args, &block @@ -80,25 +80,24 @@ end # :call-seq: # tools_jar() => path # - # Returns a path to tools.jar. + # Returns a path to tools.jar. Returns nil if tools.jar not found, which may be a problem, + # unless you're running OS/X. def tools_jar() - unless @tools - tools = File.join(home, "lib/tools.jar") - @tools = tools if File.exist?(tools) - end - @tools + return nil if darwin? + @tools ||= File.join(home, "lib/tools.jar") or raise "I need tools.jar to compile, can't find it in #{home}/lib" end # :call-seq: # home() => path # - # Returns JAVA_HOME. + # Returns JAVA_HOME, fails if JAVA_HOME not set. Returns nil for OS/X, we just assume Java is in the path. def home() - @home ||= ENV["JAVA_HOME"] or fail "Are we forgetting something? JAVA_HOME not set?" + return nil if darwin? + @home ||= ENV["JAVA_HOME"] or fail "Are we forgetting something? JAVA_HOME not set." end # :call-seq: # java(class, *args, options?) # @@ -300,13 +299,12 @@ # This method can be used in two ways. Without a block, returns the RjbWrapper # object which you can use to configure the RJB classpath or call other RJB methods. # With a block, loads RJB and yields to the block, returning its result. # # For example: - # Java.rjb.classpath += REQUIRES + # Java.rjb.classpath << REQUIRES # Java.rjb.onload { require "antwrap" } - # . . . # # def execute(name, options) # options = options.merge(:name=>name, :base_dir=>Dir.pwd, :declarative=>true) # Java.rjb { AntProject.new(options) } # end @@ -323,11 +321,11 @@ # path_to_bin(cmd?) => path # # Returns the path to the specified Java command (with no argument to java itself). # Uses JAVA_HOME if set, otherwise assumes the command is accessible from the path. def path_to_bin(name = "java") - File.join(home, "bin", name) + home ? File.join(home, "bin", name) : File.join("bin", name) end protected # :call-seq: @@ -346,10 +344,14 @@ # Returns the JUnit artifacts as paths, after downloading and installing them (if necessary). def junit_artifacts() @junit_artifacts ||= Buildr.artifacts(JUNIT_REQUIRES).each { |task| task.invoke }.map(&:to_s) end + def darwin?() #:nodoc: + RUBY_PLATFORM =~ /darwin/i + end + end # See Java#java. def java(*args) Java.java(*args) @@ -364,10 +366,10 @@ # # For example: # def apt(*sources) sources = compile.sources if sources.empty? - file(path_to("target/generated/apt")=>sources) do |task| + file(path_to(:target, "generated/apt")=>sources) do |task| Java.apt(sources.map(&:to_s) - [task.name], :output=>task.name, :classpath=>compile.classpath, :source=>compile.options.source) end end