Method: Java::Commands.java
- Defined in:
- lib/buildr/java/commands.rb
.java(*args, &block) ⇒ Object
:call-seq:
java(class, *args, )
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) = Hash === args.last ? args.pop : {} [:verbose] ||= Buildr.application..trace || false , :classpath, :java_args, :properties, :name, :verbose name = [:name] || "java #{args.first}" cmd_args = [path_to_bin('java')] classpath = classpath_from() cmd_args << '-classpath' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty? [:properties].each { |k, v| cmd_args << "-D#{k}=#{v}" } if [:properties] cmd_args += ([:java_args] || (ENV['JAVA_OPTS'] || ENV['JAVA_OPTIONS']).to_s.split).flatten cmd_args += args.flatten.compact unless Buildr.application..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..trace cmd_args = cmd_args.map(&:inspect).join(' ') if Util.win_os? system(*cmd_args).tap do |ok| block.call ok, $? end end end |