Class: Guard::Gradle

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/gradle.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Gradle

Returns a new instance of Gradle.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/guard/gradle.rb', line 8

def initialize(options = {})
  @command = './gradlew'
  @task = 'test'
  @multi_projs = false
  @flags = false

  if options.has_key? :multi_project
    @multi_projs = options[:multi_project]
  end
  if options.has_key? :command
    @command = options[:command]
  end
  if options.has_key? :task
    @task = options[:task]
  end
  if options.has_key? :flags
    @flags = options[:flags]
  end

  @DEF_CMD = "#{@command} #{@task}"
  if @flags
    @DEF_CMD = "#{@DEF_CMD} #{@flags}"
  end

  super
end

Instance Method Details

#fire_command(command) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/guard/gradle.rb', line 55

def fire_command(command)
  UI.info "running #{command}"
  result = system command
  summary = result ? 'Success' : 'Failure'
  image = result ? :success : :failed
  notify(summary, image)
end

#notify(summary, image) ⇒ Object



63
64
65
# File 'lib/guard/gradle.rb', line 63

def notify(summary, image)
  ::Guard::Notifier.notify(summary, title: 'Gradle Test Results', image: image)
end

#run_allObject



51
52
53
# File 'lib/guard/gradle.rb', line 51

def run_all
  fire_command @DEF_CMD
end

#run_on_changes(paths) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/guard/gradle.rb', line 35

def run_on_changes(paths)
  if paths.size == 1 && @multi_projs
    project = paths[0].split('/')[0]
    file = paths[0].split('/')[1]    
    if Dir.glob("#{project}/src/test/**/#{file}*").size > 0
      fire_command("#{@DEF_CMD} -p #{project} -Dtest.single=#{file} --daemon")
    else
      run_all
    end
  elsif(paths.size == 1) && (Dir.glob("src/test/**/#{paths[0]}*").size > 0)
    fire_command("#{@DEF_CMD} -Dtest.single=#{paths[0]} --daemon")
  else
    run_all
  end
end

#startObject



67
68
69
# File 'lib/guard/gradle.rb', line 67

def start
  fire_command @DEF_CMD
end