Executes the RubyGems gem install process, using the RubyGems options @param [Array] sub_argv Options passed to the gem_install command from the user input @return [Fixnum] Return status
(sub_argv)
| 1306 | # @return [Fixnum] Return status |
| 1307 | # |
| 1308 | def execute(sub_argv) |
| 1309 | require 'rubygems' |
| 1310 | require 'rubygems/commands/install_command' |
| 1311 | |
| 1312 | $logger.info "InstallGem, sub_argv = #{sub_argv}" |
| 1313 | |
| 1314 | options = {} |
| 1315 | |
| 1316 | # Parse the options |
| 1317 | opts = OptionParser.new do |o| |
| 1318 | o.banner = 'Usage: openstudio gem_install gem_name gem_version' |
| 1319 | o.separator '' |
| 1320 | o.separator 'Options:' |
| 1321 | o.separator '' |
| 1322 | end |
| 1323 | |
| 1324 | # Parse the options |
| 1325 | argv = parse_options(opts, sub_argv) |
| 1326 | return 0 if argv == nil |
| 1327 | |
| 1328 | $logger.debug("InstallGem command: #{argv.inspect} #{options.inspect}") |
| 1329 | |
| 1330 | if argv == [] |
| 1331 | $logger.error 'No gem name provided' |
| 1332 | return 1 |
| 1333 | end |
| 1334 | gem_name = argv[0] |
| 1335 | gem_version = argv[1] |
| 1336 | |
| 1337 | cmd = Gem::Commands::InstallCommand.new |
| 1338 | cmd.handle_options ["--no-ri", "--no-rdoc", 'rake', '--version', '0.9'] # or omit --version and the following option to install the latest |
| 1339 | |
| 1340 | ARGV.clear |
| 1341 | ARGV << gem_name |
| 1342 | if gem_version |
| 1343 | ARGV << '--version' |
| 1344 | ARGV << gem_version |
| 1345 | end |
| 1346 | |
| 1347 | $logger.info "Installing gem to #{ENV['GEM_HOME']}" |
| 1348 | |
| 1349 | begin |
| 1350 | cmd.execute |
| 1351 | rescue => e |
| 1352 | $logger.error "Error installing gem: #{e.message} in #{e.backtrace.join("\n")}" |
| 1353 | exit e.exit_code |
| 1354 | rescue LoadError => e |
| 1355 | # DLM: gem install tries to load a Windows dll to access network functionality in win32/resolv |
| 1356 | # Ruby must be built with libffi to enable fiddle extension to enable win32 extension |
| 1357 | $logger.error "gem_install command not yet implemented, requires fiddle extension" |
| 1358 | #$logger.error "#{e.message} in #{e.backtrace.join("\n")}" |
| 1359 | return 1 |
| 1360 | end |
| 1361 | |
| 1362 | $logger.info 'The gem was successfully installed' |
| 1363 | |
| 1364 | 0 |
| 1365 | end |