Module: Albacore::RunCommand

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AttrMethods

attr_array, attr_hash

Instance Attribute Details

#commandObject

Returns the value of attribute command.



7
8
9
# File 'lib/albacore/support/runcommand.rb', line 7

def command
  @command
end

#working_directoryObject

Returns the value of attribute working_directory.



7
8
9
# File 'lib/albacore/support/runcommand.rb', line 7

def working_directory
  @working_directory
end

Instance Method Details

#get_command(params) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/albacore/support/runcommand.rb', line 35

def get_command(params)
  executable = @command
  unless command.nil?
    executable = File.expand_path(@command) if File.exists?(@command)
  end
  cmd = "\"#{executable}\""
  cmd +=" #{params.join(' ')}" if params.length > 0
  cmd
end

#initializeObject



10
11
12
13
14
# File 'lib/albacore/support/runcommand.rb', line 10

def initialize
  @working_directory = Dir.pwd
  @parameters = []
  super()
end

#run_command(name = "Command Line", parameters = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/albacore/support/runcommand.rb', line 16

def run_command(name="Command Line", parameters=nil)
  begin
    params = Array.new
    params << parameters unless parameters.nil?
    params << @parameters unless (@parameters.nil? || @parameters.length==0)
    
    cmd = get_command(params)
    @logger.debug "Executing #{name}: #{cmd}"
    
    Dir.chdir(@working_directory) do
      return system(cmd)
    end

  rescue Exception => e
    puts "Error While Running Command Line Tool: #{e}"
    raise
  end
end