2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/command'
|
|
|
|
require 'rubygems/builder'
|
|
|
|
|
|
|
|
class Gem::Commands::BuildCommand < Gem::Command
|
|
|
|
|
|
|
|
def initialize
|
2012-04-17 20:04:12 -04:00
|
|
|
super 'build', 'Build a gem from a gemspec'
|
|
|
|
|
|
|
|
add_option '--force', 'skip validation of the spec' do |value, options|
|
|
|
|
options[:force] = true
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def arguments # :nodoc:
|
|
|
|
"GEMSPEC_FILE gemspec file name to build a gem for"
|
|
|
|
end
|
|
|
|
|
|
|
|
def usage # :nodoc:
|
|
|
|
"#{program_name} GEMSPEC_FILE"
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
gemspec = get_one_gem_name
|
2011-05-31 23:45:05 -04:00
|
|
|
|
|
|
|
if File.exist? gemspec
|
|
|
|
spec = load_gemspec gemspec
|
|
|
|
|
|
|
|
if spec then
|
2012-04-17 20:04:12 -04:00
|
|
|
Gem::Builder.new(spec).build options[:force]
|
2011-05-31 23:45:05 -04:00
|
|
|
else
|
|
|
|
alert_error "Error loading gemspec. Aborting."
|
|
|
|
terminate_interaction 1
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
else
|
|
|
|
alert_error "Gemspec file not found: #{gemspec}"
|
2011-05-31 23:45:05 -04:00
|
|
|
terminate_interaction 1
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def load_gemspec filename
|
2007-11-10 02:48:56 -05:00
|
|
|
if yaml?(filename)
|
|
|
|
open(filename) do |f|
|
|
|
|
begin
|
2011-05-31 23:45:05 -04:00
|
|
|
Gem::Specification.from_yaml(f)
|
2010-11-08 15:58:42 -05:00
|
|
|
rescue Gem::EndOfYAMLException
|
2011-05-31 23:45:05 -04:00
|
|
|
nil
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2011-05-31 23:45:05 -04:00
|
|
|
Gem::Specification.load(filename) # can return nil
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def yaml?(filename)
|
|
|
|
line = open(filename) { |f| line = f.gets }
|
2007-12-21 03:45:07 -05:00
|
|
|
result = line =~ %r{!ruby/object:Gem::Specification}
|
2007-11-10 02:48:56 -05:00
|
|
|
result
|
|
|
|
end
|
|
|
|
end
|