/tools/Ruby/lib/ruby/site_ruby/1.8/rubygems/commands/build_command.rb

http://github.com/agross/netopenspace · Ruby · 53 lines · 45 code · 7 blank · 1 comment · 3 complexity · 06d86f73b22469145808dbc241363151 MD5 · raw file

  1. require 'rubygems/command'
  2. require 'rubygems/builder'
  3. class Gem::Commands::BuildCommand < Gem::Command
  4. def initialize
  5. super('build', 'Build a gem from a gemspec')
  6. end
  7. def arguments # :nodoc:
  8. "GEMSPEC_FILE gemspec file name to build a gem for"
  9. end
  10. def usage # :nodoc:
  11. "#{program_name} GEMSPEC_FILE"
  12. end
  13. def execute
  14. gemspec = get_one_gem_name
  15. if File.exist?(gemspec)
  16. specs = load_gemspecs(gemspec)
  17. specs.each do |spec|
  18. Gem::Builder.new(spec).build
  19. end
  20. else
  21. alert_error "Gemspec file not found: #{gemspec}"
  22. end
  23. end
  24. def load_gemspecs(filename)
  25. if yaml?(filename)
  26. result = []
  27. open(filename) do |f|
  28. begin
  29. while not f.eof? and spec = Gem::Specification.from_yaml(f)
  30. result << spec
  31. end
  32. rescue Gem::EndOfYAMLException
  33. # OK
  34. end
  35. end
  36. else
  37. result = [Gem::Specification.load(filename)]
  38. end
  39. result
  40. end
  41. def yaml?(filename)
  42. line = open(filename) { |f| line = f.gets }
  43. result = line =~ %r{!ruby/object:Gem::Specification}
  44. result
  45. end
  46. end