59: def execute
60: if options[:include_dependencies] then
61: alert "`gem install -y` is now default and will be removed"
62: alert "use --ignore-dependencies to install only the gems you list"
63: end
64:
65: installed_gems = []
66:
67: ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9'
68:
69: install_options = {
70: :env_shebang => options[:env_shebang],
71: :domain => options[:domain],
72: :force => options[:force],
73: :format_executable => options[:format_executable],
74: :ignore_dependencies => options[:ignore_dependencies],
75: :install_dir => options[:install_dir],
76: :security_policy => options[:security_policy],
77: :wrappers => options[:wrappers],
78: :bin_dir => options[:bin_dir],
79: :development => options[:development],
80: }
81:
82: exit_code = 0
83:
84: get_all_gem_names.each do |gem_name|
85: begin
86: inst = Gem::DependencyInstaller.new install_options
87: inst.install gem_name, options[:version]
88:
89: inst.installed_gems.each do |spec|
90: say "Successfully installed #{spec.full_name}"
91: end
92:
93: installed_gems.push(*inst.installed_gems)
94: rescue Gem::InstallError => e
95: alert_error "Error installing #{gem_name}:\n\t#{e.message}"
96: exit_code |= 1
97: rescue Gem::GemNotFoundException => e
98: alert_error e.message
99: exit_code |= 2
100:
101:
102:
103:
104:
105:
106:
107: end
108: end
109:
110: unless installed_gems.empty? then
111: gems = installed_gems.length == 1 ? 'gem' : 'gems'
112: say "#{installed_gems.length} #{gems} installed"
113: end
114:
115:
116:
117:
118:
119: if options[:generate_ri] then
120: installed_gems.each do |gem|
121: Gem::DocManager.new(gem, options[:rdoc_args]).generate_ri
122: end
123:
124: Gem::DocManager.update_ri_cache
125: end
126:
127: if options[:generate_rdoc] then
128: installed_gems.each do |gem|
129: Gem::DocManager.new(gem, options[:rdoc_args]).generate_rdoc
130: end
131: end
132:
133: if options[:test] then
134: installed_gems.each do |spec|
135: gem_spec = Gem::SourceIndex.from_installed_gems.search(spec.name, spec.version.version).first
136: result = Gem::Validator.new.unit_test(gem_spec)
137: if result and not result.passed?
138: unless ask_yes_no("...keep Gem?", true) then
139: Gem::Uninstaller.new(spec.name, :version => spec.version.version).uninstall
140: end
141: end
142: end
143: end
144:
145: raise Gem::SystemExitException, exit_code
146: end