lib/java/java.rb in buildr-0.19.0 vs lib/java/java.rb in buildr-0.20.0
- old
+ new
@@ -193,9 +193,65 @@
sh(path_to_bin("javac"), *cmd_args) { |ok, res| fail "Failed to compile, see errors above" unless ok }
end
end
# :call-seq:
+ # javadoc(*files, options)
+ #
+ # Runs Javadocs with the specified files and options.
+ #
+ # This method accepts the following special options:
+ # * :output -- The output directory
+ # * :classpath -- Array of classpath dependencies.
+ # * :sourcepath -- Array of sourcepaths (paths or tasks).
+ # * :name -- Shows this name, otherwise shows the working directory.
+ # * :verbose -- If you want an overload of details.
+ #
+ # All other options are passed to Javadoc as following:
+ # * true -- As is, for example, :author=>true becomes -author
+ # * false -- Prefixed, for example, :index=>false becomes -noindex
+ # * string -- Option with value, for example, :windowtitle=>"My project" becomes -windowtitle "My project"
+ # * array -- Option with set of values separated by spaces.
+ def javadoc(*args)
+ options = Hash === args.last ? args.pop : {}
+ options[:verbose] ||= Rake.application.options.trace || false
+
+ Tempfile.open("javadoc") do |opt_file|
+ options.reject { |key, value| [:output, :verbose, :name, :sourcepath, :classpath].include?(key) }.
+ each { |key, value| value.invoke if value.respond_to?(:invoke) }.
+ each do |key, value|
+ case value
+ when true, nil
+ opt_file.puts "-#{key}"
+ when false
+ opt_file.puts "-no#{key}"
+ when Array
+ opt_file.puts "-#{key} " << value.map { |val| %q{"#{val}"} }.join(" ")
+ when Hash
+ value.each { |k,v| opt_file.puts "-#{key} #{k} #{v}" }
+ else
+ opt_file.puts "-#{key} \"#{value}\""
+ end
+ end
+ [:sourcepath, :classpath].each do |option|
+ options[option].to_a.flatten.tap do |paths|
+ opt_file.puts "-#{option} " << paths.flatten.map(&:to_s).join(File::PATH_SEPARATOR) unless paths.empty?
+ end
+ end
+ opt_file.puts args.flatten.uniq.join(" ")
+ opt_file.flush
+ cmd_args = [ "-d", options[:output], options[:verbose] ? "-verbose" : "-quiet", "@#{opt_file.path}"]
+ cmd_args << { :verbose=>options[:verbose] }
+ name = options[:name] || Dir.pwd
+ unless Rake.application.options.dryrun
+ puts "Generating Javadoc for #{name}" if verbose
+ puts File.read(opt_file.path) if options[:verbose]
+ sh(path_to_bin("javadoc"), *cmd_args) { |ok, res| fail "Failed to generate Javadocs, see errors above" unless ok }
+ end
+ end
+ end
+
+ # :call-seq:
# junit(*classes, options) => [ passed, failed ]
#
# Runs JUnit test cases from the specified classes. Returns an array with two lists,
# one containing the names of all classes that passes, the other containing the names
# of all classes that failed.