Class: PureMVCGen::AntChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/pure_m_v_c_gen/ant_checker.rb

Class Method Summary collapse

Class Method Details

.find_in_path(utility) ⇒ Object

Searches the path, looking for the given utility. If an executable file is found that matches the parameter, this returns true.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pure_m_v_c_gen/ant_checker.rb', line 11

def self.find_in_path(utility)
 path = self.get_path
 suffixes = self.on_windows? ? self.windows_executable_extensions : [""]

 path.each do |dir|
   suffixes.each do |sfx|
     file = File.join(dir, utility + sfx)
     return true if File.executable?(file)
   end
 end

 false
end

.get_pathObject



25
26
27
# File 'lib/pure_m_v_c_gen/ant_checker.rb', line 25

def self.get_path
  (ENV['PATH'] || "").split(File::PATH_SEPARATOR)
end

.get_windows_antObject

Locates the ant executable or BAT file and returns the full path to it



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pure_m_v_c_gen/ant_checker.rb', line 30

def self.get_windows_ant
  ext = %w(.exe .bat)
  path = self.get_path
  
  path.each do |dir|
    ext.each do |sfx|
      file = File.join(dir, "ant" + sfx)
      return File.expand_path(file) if File.executable?(file)
    end
  end
  
  nil
end

.has_ant_installed?Boolean

Determines if ANT is installed on the system

Returns:

  • (Boolean)


5
6
7
# File 'lib/pure_m_v_c_gen/ant_checker.rb', line 5

def self.has_ant_installed?
  AntChecker.find_in_path("ant")
end

.on_windows?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/pure_m_v_c_gen/ant_checker.rb', line 44

def self.on_windows?
 RUBY_PLATFORM =~ /mswin|mingw/
end

.windows_executable_extensionsObject



48
49
50
# File 'lib/pure_m_v_c_gen/ant_checker.rb', line 48

def self.windows_executable_extensions
 %w(.exe .bat .com .cmd)
end