Class: Rake::Delphi::CustomDelphiTool
- Inherits:
-
CustomExec
- Object
- BasicTask
- CustomExec
- Rake::Delphi::CustomDelphiTool
- Defined in:
- lib/rake/delphi/tool.rb
Direct Known Subclasses
Constant Summary collapse
- DelphiRegRoot =
'SOFTWARE\\Borland\\Delphi'- BDSRegRoot =
'SOFTWARE\\Borland\\BDS'- EDSRegRoot =
'SOFTWARE\\CodeGear\\BDS'- EmbarcaderoRegRoot =
'SOFTWARE\\Embarcadero\\BDS'
Class Method Summary collapse
- .checkToolFailure(toolpath) ⇒ Object
- .find(failIfNotFound = false) ⇒ Object
- .readDelphiDir(ver) ⇒ Object
- .readUserOption(key, name, ver) ⇒ Object
- .reinit ⇒ Object
- .rootForVersion(version) ⇒ Object
- .toolName ⇒ Object
- .version4version(version) ⇒ Object
Instance Method Summary collapse
- #delphidir ⇒ Object
-
#initialize(checkExistance = false) ⇒ CustomDelphiTool
constructor
A new instance of CustomDelphiTool.
- #options ⇒ Object
- #regroot ⇒ Object
- #toolpath ⇒ Object
- #version ⇒ Object
- #versionInfoClass ⇒ Object
Methods inherited from CustomExec
Methods inherited from BasicTask
Constructor Details
#initialize(checkExistance = false) ⇒ CustomDelphiTool
Returns a new instance of CustomDelphiTool.
27 28 29 |
# File 'lib/rake/delphi/tool.rb', line 27 def initialize(checkExistance = false) @@version, @@delphidir, @@toolpath, @@regroot = self.class.find(checkExistance) unless @@version end |
Class Method Details
.checkToolFailure(toolpath) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/rake/delphi/tool.rb', line 176 def self.checkToolFailure(toolpath) if toolpath.kind_of?(TrueClass) || toolpath.kind_of?(FalseClass) unless toolpath fail 'Could not detect path for %s! Check your registry and DELPHI_VERSION environment variable.' % [toolName] end cond = ! toolpath toolpath = '' else cond = File.exists?(toolpath) end fail 'Could not find %s: (%s)' % [toolName, toolpath] unless cond end |
.find(failIfNotFound = false) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/rake/delphi/tool.rb', line 137 def self.find(failIfNotFound = false) v = EnvVariables.delphi_version.to_s if ENV['DELPHI_DIR'] Logger.trace(Logger::DEBUG, 'DELPHI_DIR is set: ' + ENV['DELPHI_DIR']) # append trailing path delimiter ENV['DELPHI_DIR'] = ENV['DELPHI_DIR'].gsub(/[^\/]$/, '\&/') tool = ENV['DELPHI_DIR'] + toolName checkToolFailure(tool) if failIfNotFound return v, ENV['DELPHI_DIR'], tool, ENV['DELPHI_REG_ROOT'] end if v.to_s.empty? v = [] (4..21).each { |n| v << n.to_s } v.reverse! else Logger.trace(Logger::DEBUG, 'DELPHI_VERSION is set: ' + v) v = [v] end tool_was_found = false v.each do |ver| path, regroot = readDelphiDir(ver) next unless path tool = path + toolName tool_was_found = true Logger.trace(Logger::DEBUG, "Got tool: '#{tool}'") if File.exists?(tool) # found it ! ENV['DELPHI_VERSION'] = ver ENV['DELPHI_DIR'] = path ENV['DELPHI_REG_ROOT'] = regroot Logger.trace(Logger::DEBUG, "Set: DELPHI_VERSION=#{ver}; DELPHI_DIR='#{path}'; DELPHI_REG_ROOT='#{regroot}'") return ver, path, tool, regroot else Logger.trace(Logger::DEBUG, 'But file does not exist!') end end checkToolFailure(tool_was_found) if failIfNotFound return nil end |
.readDelphiDir(ver) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/rake/delphi/tool.rb', line 113 def self.readDelphiDir(ver) begin require 'win32/registry' [::Win32::Registry::HKEY_LOCAL_MACHINE, \ # for local/manual installations ::Win32::Registry::HKEY_CURRENT_USER].each do |regRoot| begin Logger.trace(Logger::DEBUG, "Finding Delphi dir for #{ver}") reg_root = rootForVersion(ver) regRoot.open(reg_root) do |reg| reg_typ, reg_val = reg.read('RootDir') return reg_val.unix2dos_separator, reg_root end rescue ::Win32::Registry::Error Logger.trace(Logger::DEBUG, "No reg key '#{regRoot}'?!") end end return nil, nil rescue LoadError Logger.trace(Logger::DEBUG, 'No `win32/registry` gem?!') return nil, nil end end |
.readUserOption(key, name, ver) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rake/delphi/tool.rb', line 61 def self.readUserOption(key, name, ver) begin require 'win32/registry' root = rootForVersion(ver) + '\\' + key key_exists = false begin Logger.trace(Logger::DEBUG, "Reading user option '#{name}' in '#{root}'") ::Win32::Registry::HKEY_CURRENT_USER.open(root) do |reg| key_exists = true reg_typ, reg_val = reg.read(name) Logger.trace(Logger::TRACE, "Value: #{reg_val}") return reg_val.dos2unix_separator end rescue ::Win32::Registry::Error => e Logger.trace(Logger::DEBUG, "No reg key '%s'?! %s" % \ [(key_exists ? "#{root}\\#{name}" : root), e.]) return '' end rescue LoadError Logger.trace(Logger::DEBUG, 'No `win32/registry` gem?!') return '' end end |
.reinit ⇒ Object
21 22 23 |
# File 'lib/rake/delphi/tool.rb', line 21 def self.reinit @@version, @@delphidir, @@toolpath, @@regroot = nil, nil, nil, nil end |
.rootForVersion(version) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rake/delphi/tool.rb', line 95 def self.rootForVersion(version) if version.to_f < DELPHI_VERSION_7 regRoot = DelphiRegRoot else if version.to_f <= DELPHI_VERSION_2006 regRoot = BDSRegRoot elsif version.to_f < DELPHI_VERSION_XE regRoot = EDSRegRoot else regRoot = EmbarcaderoRegRoot end end version = version4version(version) regRoot = regRoot + '\\' + version Logger.trace(Logger::DEBUG, "Root for version #{version}: '#{regRoot}'") return regRoot end |
.toolName ⇒ Object
31 32 33 |
# File 'lib/rake/delphi/tool.rb', line 31 def self.toolName raise 'Abstract method "toolName". Override it' end |
.version4version(version) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/rake/delphi/tool.rb', line 85 def self.version4version(version) if version.to_f >= DELPHI_VERSION_7 version = format('%.1f', version.to_f - 6) end if !version["."] version << ".0" end return version end |
Instance Method Details
#delphidir ⇒ Object
43 44 45 |
# File 'lib/rake/delphi/tool.rb', line 43 def delphidir @@delphidir end |
#options ⇒ Object
51 52 53 |
# File 'lib/rake/delphi/tool.rb', line 51 def '' end |
#regroot ⇒ Object
47 48 49 |
# File 'lib/rake/delphi/tool.rb', line 47 def regroot @@regroot end |
#toolpath ⇒ Object
39 40 41 |
# File 'lib/rake/delphi/tool.rb', line 39 def toolpath @@toolpath end |
#version ⇒ Object
35 36 37 |
# File 'lib/rake/delphi/tool.rb', line 35 def version @@version end |
#versionInfoClass ⇒ Object
55 56 57 58 59 |
# File 'lib/rake/delphi/tool.rb', line 55 def versionInfoClass return @@version.to_f < DELPHI_VERSION_2006 ? BDSVersionInfo : \ @@version.to_f < DELPHI_VERSION_2010 ? RAD2007VersionInfo : \ @@version.to_f < DELPHI_VERSION_XE ? RAD2010VersionInfo : XEVersionInfo end |