lib/java/java.rb in buildr-0.22.0 vs lib/java/java.rb in buildr-1.0.0
- old
+ new
@@ -74,25 +74,32 @@
#
# For example:
# puts Java.version
# => 1.5.0_10
def version()
- @version ||= `#{path_to_bin("java")} -version 2>&1`.scan(/java version "(.*)"/)[0][0]
+ @version ||= `"#{path_to_bin("java")}" -version 2>&1`.scan(/java version "(.*)"/)[0][0]
end
# :call-seq:
# tools_jar() => path
#
# Returns a path to tools.jar.
def tools_jar()
unless @tools
- home = ENV["JAVA_HOME"] || File.dirname(File.dirname(`which java`.split.first))
tools = File.join(home, "lib/tools.jar")
@tools = tools if File.exist?(tools)
end
@tools
end
+
+ # :call-seq:
+ # home() => path
+ #
+ # Returns JAVA_HOME.
+ def home()
+ @home ||= ENV["JAVA_HOME"] or fail "Are we forgetting something? JAVA_HOME not set?"
+ end
# :call-seq:
# java(class, *args, options?)
#
# Runs Java with the specified arguments.
@@ -102,26 +109,29 @@
# These are all expanded into artifacts, and all tasks are invoked.
# * :java_args -- Any additional arguments to pass (e.g. -hotspot, -xms)
# * :properties -- Hash of system properties (e.g. "path"=>base_dir).
# * :name -- Shows this name, otherwise shows the first argument (the class name).
# * :verbose -- If true, prints the command and all its argument.
- def java(*args)
+ def java(*args, &block)
options = Hash === args.last ? args.pop : {}
options[:verbose] ||= Rake.application.options.trace || false
- fu_check_options options, *JAVA_OPTIONS
+ rake_check_options options, *JAVA_OPTIONS
name = options[:name] || "java #{args.first}"
- cmd_args = []
+ cmd_args = [path_to_bin("java")]
classpath = classpath_from(options)
cmd_args << "-cp" << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
options[:properties].each { |k, v| cmd_args << "-D#{k}=#{v}" } if options[:properties]
cmd_args += options[:java_args].flatten if options[:java_args]
cmd_args += args.flatten.compact
- cmd_args << { :verbose=>options[:verbose] }
unless Rake.application.options.dryrun
puts "Running #{name}" if verbose
- sh(path_to_bin("java"), *cmd_args) { |ok, res| fail "Failed to execute #{name}, see errors above" unless ok }
+ block = lambda { |ok, res| fail "Failed to execute #{name}, see errors above" unless ok } unless block
+ puts cmd_args.join(" ") if Rake.application.options.trace
+ system(cmd_args.map { |arg| %Q{"#{arg}"} }.join(" ")).tap do |ok|
+ block.call ok, $?
+ end
end
end
# :call-seq:
# apt(*files, options)
@@ -135,11 +145,11 @@
# generated class files when compiling.
# * :classpath -- One or more file names, tasks or artifact specifications.
# These are all expanded into artifacts, and all tasks are invoked.
def apt(*args)
options = Hash === args.last ? args.pop : {}
- fu_check_options options, :compile, :source, :output, :classpath
+ rake_check_options options, :compile, :source, :output, :classpath
files = args.flatten.map(&:to_s).
collect { |arg| File.directory?(arg) ? FileList["#{arg}/**/*.java"] : arg }.flatten
cmd_args = [ Rake.application.options.trace ? "-verbose" : "-nowarn" ]
if options[:compile]
@@ -173,11 +183,11 @@
# * :sourcepath -- Additional source paths to use.
# * :javac_args -- Any additional arguments to pass (e.g. -extdirs, -encoding)
# * :name -- Shows this name, otherwise shows the working directory.
def javac(*args)
options = Hash === args.last ? args.pop : {}
- fu_check_options options, :classpath, :sourcepath, :output, :javac_args, :name
+ rake_check_options options, :classpath, :sourcepath, :output, :javac_args, :name
files = args.flatten.each { |f| f.invoke if f.respond_to?(:invoke) }.map(&:to_s).
collect { |arg| File.directory?(arg) ? FileList["#{arg}/**/*.java"] : arg }.flatten
name = options[:name] || Dir.pwd
@@ -265,11 +275,11 @@
# * :properties -- Hash of system properties (e.g. "path"=>base_dir).
# * :verbose -- If true, prints the command and all its argument.
def junit(*args)
options = Hash === args.last ? args.pop : {}
options[:verbose] ||= Rake.application.options.trace || false
- fu_check_options options, :verbose, :classpath, :properties
+ rake_check_options options, :verbose, :classpath, :properties
classpath = classpath_from(options) + junit_artifacts
tests = args.flatten
failed = tests.inject([]) do |failed, test|
begin
@@ -313,10 +323,10 @@
# 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")
- ENV["JAVA_HOME"] ? File.join(ENV["JAVA_HOME"], "bin", name) : name
+ File.join(home, "bin", name)
end
protected
# :call-seq: