Class: Guard::Java
- Inherits:
-
Guard
- Object
- Guard
- Guard::Java
- Defined in:
- lib/guard/java.rb
Instance Method Summary collapse
- #all_command ⇒ Object
- #compile(project_name, klass) ⇒ Object
- #do_shell(command) ⇒ Object
- #focused_command ⇒ Object
-
#initialize(watchers = [], options = {}) ⇒ Java
constructor
A new instance of Java.
- #notify(msg, title = '', image = nil) ⇒ Object
- #run_all ⇒ Object
- #run_focused_tests(project_name, klass) ⇒ Object
- #run_on_changes(classes) ⇒ Object
- #run_test_class(klass) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(watchers = [], options = {}) ⇒ Java
Returns a new instance of Java.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/guard/java.rb', line 5 def initialize(watchers=[], ={}) super = { :all_after_pass => true, :all_on_start => true, :focused_after_compile => true, :test_runner_class => 'org.junit.runner.JUnitCore', :project_name => 'Java Project', :focused_cli => nil, :all_cli => nil, :classpath => '.' }.merge() end |
Instance Method Details
#all_command ⇒ Object
68 69 70 |
# File 'lib/guard/java.rb', line 68 def all_command [:all_cli] end |
#compile(project_name, klass) ⇒ Object
55 56 57 58 |
# File 'lib/guard/java.rb', line 55 def compile(project_name, klass) notify "Compiling because of #{klass} change", "#{project_name} file change detected", :pending # notify any interested listeners do_shell(focused_command) end |
#do_shell(command) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/guard/java.rb', line 76 def do_shell(command) IO.popen(command) do |out| until out.eof? puts out.gets end end code = $? # Get the status code of the last-finished process (code == 0) ? :success : :failed end |
#focused_command ⇒ Object
64 65 66 |
# File 'lib/guard/java.rb', line 64 def focused_command [:focused_cli] end |
#notify(msg, title = '', image = nil) ⇒ Object
72 73 74 |
# File 'lib/guard/java.rb', line 72 def notify(msg, title='', image=nil) Notifier.notify(msg, title: title, image: image) end |
#run_all ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/guard/java.rb', line 26 def run_all project_name = [:project_name] notify project_name, "Build and run all", :pending result = do_shell(all_command) result_description = "#{project_name} build results" notify result_description, "Build #{result.to_s.capitalize}", result # Notify of success or failure end |
#run_focused_tests(project_name, klass) ⇒ Object
60 61 62 |
# File 'lib/guard/java.rb', line 60 def run_focused_tests(project_name, klass) run_test_class(klass) end |
#run_on_changes(classes) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/guard/java.rb', line 34 def run_on_changes(classes) project_name = [:project_name] klass = classes[0] result = compile(project_name, klass) result = run_focused_tests(project_name, klass) if result != :failed && [:focused_after_compile] result_description = "#{project_name}: test run for #{klass}" notify result_description, "Build #{result.to_s.capitalize}", result # Notify of success or failure if result == :success && [:all_after_pass] run_all end nil end |
#run_test_class(klass) ⇒ Object
88 89 90 91 92 |
# File 'lib/guard/java.rb', line 88 def run_test_class(klass) test_command = "java -cp #{options[:classpath]} #{options[:test_runner_class]} #{klass}" puts test_command do_shell test_command end |
#start ⇒ Object
19 20 21 22 23 24 |
# File 'lib/guard/java.rb', line 19 def start UI.info 'Guard::Java is running' raise ArgumentError, ":focused_cli and :all_cli options must be set" if [:focused_cli].nil? || [:all_cli].nil? run_all if [:all_on_start] end |
#stop ⇒ Object
52 53 |
# File 'lib/guard/java.rb', line 52 def stop end |