Method: Java::Commands.java

Defined in:
lib/buildr/java/commands.rb

.java(*args, &block) ⇒ Object

:call-seq:

java(class, *args, options?)

Runs Java with the specified arguments.

The last argument may be a Hash with additional options:

  • :classpath – One or more file names, tasks or artifact specifications. 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.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/buildr/java/commands.rb', line 37

def java(*args, &block)
  options = Hash === args.last ? args.pop : {}
  options[:verbose] ||= Buildr.application.options.trace || false
  rake_check_options options, :classpath, :java_args, :properties, :name, :verbose

  name = options[:name] || "java #{args.first}"
  cmd_args = [path_to_bin('java')]
  classpath = classpath_from(options)
  cmd_args << '-classpath' << 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] || (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split).flatten
  cmd_args += args.flatten.compact
  unless Buildr.application.options.dryrun
    info "Running #{name}"
    block = lambda { |ok, res| fail "Failed to execute #{name}, see errors above" unless ok } unless block
    puts cmd_args.join(' ') if Buildr.application.options.trace
    cmd_args = cmd_args.map(&:inspect).join(' ') if Util.win_os?
    system(*cmd_args).tap do |ok|
      block.call ok, $?
    end
  end
end