2013-02-03 02:42:04 +00:00
|
|
|
require "log4r"
|
2014-01-05 22:54:50 +00:00
|
|
|
require "vagrant/plugin/manager"
|
2014-08-29 19:16:40 +00:00
|
|
|
require "vagrant/util/platform"
|
2013-02-03 02:42:04 +00:00
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module CommandPlugin
|
|
|
|
module Action
|
|
|
|
# This action takes the `:plugin_name` variable in the environment
|
|
|
|
# and installs it using the RubyGems API.
|
|
|
|
class InstallGem
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
@logger = Log4r::Logger.new("vagrant::plugins::plugincommand::installgem")
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2014-01-06 04:47:02 +00:00
|
|
|
entrypoint = env[:plugin_entry_point]
|
2013-02-03 02:42:04 +00:00
|
|
|
plugin_name = env[:plugin_name]
|
2014-01-06 07:13:49 +00:00
|
|
|
sources = env[:plugin_sources]
|
2013-03-21 05:30:31 +00:00
|
|
|
version = env[:plugin_version]
|
2013-02-03 02:42:04 +00:00
|
|
|
|
2013-02-03 07:31:53 +00:00
|
|
|
# Install the gem
|
2013-03-20 06:02:32 +00:00
|
|
|
plugin_name_label = plugin_name
|
2013-03-21 05:30:31 +00:00
|
|
|
plugin_name_label += " --version '#{version}'" if version
|
2013-02-03 07:31:53 +00:00
|
|
|
env[:ui].info(I18n.t("vagrant.commands.plugin.installing",
|
2014-05-22 16:35:12 +00:00
|
|
|
name: plugin_name_label))
|
2013-02-03 02:42:04 +00:00
|
|
|
|
2014-01-05 22:54:50 +00:00
|
|
|
manager = Vagrant::Plugin::Manager.instance
|
2014-01-06 04:47:02 +00:00
|
|
|
plugin_spec = manager.install_plugin(
|
2014-01-06 07:13:49 +00:00
|
|
|
plugin_name,
|
|
|
|
version: version,
|
|
|
|
require: entrypoint,
|
2014-01-06 17:27:37 +00:00
|
|
|
sources: sources,
|
|
|
|
verbose: !!env[:plugin_verbose],
|
|
|
|
)
|
2013-02-03 21:59:43 +00:00
|
|
|
|
2014-01-06 05:08:55 +00:00
|
|
|
# Record it so we can uninstall if something goes wrong
|
|
|
|
@installed_plugin_name = plugin_spec.name
|
|
|
|
|
2013-02-03 21:59:43 +00:00
|
|
|
# Tell the user
|
|
|
|
env[:ui].success(I18n.t("vagrant.commands.plugin.installed",
|
2014-05-22 16:35:12 +00:00
|
|
|
name: plugin_spec.name,
|
|
|
|
version: plugin_spec.version.to_s))
|
2013-02-03 02:42:04 +00:00
|
|
|
|
2013-07-26 05:53:53 +00:00
|
|
|
# If the plugin's spec includes a post-install message display it
|
2013-08-09 18:26:39 +00:00
|
|
|
post_install_message = plugin_spec.post_install_message
|
|
|
|
if post_install_message
|
|
|
|
if post_install_message.is_a?(Array)
|
|
|
|
post_install_message = post_install_message.join(" ")
|
|
|
|
end
|
2013-07-26 05:53:53 +00:00
|
|
|
|
|
|
|
env[:ui].info(I18n.t("vagrant.commands.plugin.post_install",
|
2014-05-22 16:35:12 +00:00
|
|
|
name: plugin_spec.name,
|
|
|
|
message: post_install_message.to_s))
|
2013-07-26 05:53:53 +00:00
|
|
|
end
|
|
|
|
|
2013-02-03 02:42:04 +00:00
|
|
|
# Continue
|
|
|
|
@app.call(env)
|
|
|
|
end
|
2013-02-03 21:59:43 +00:00
|
|
|
|
|
|
|
def recover(env)
|
|
|
|
# If any error happens, we uninstall it and remove it from
|
|
|
|
# the state file. We can only do this if we successfully installed
|
|
|
|
# the gem in the first place.
|
|
|
|
if @installed_plugin_name
|
|
|
|
new_env = env.dup
|
|
|
|
new_env.delete(:interrupted)
|
|
|
|
new_env[:plugin_name] = @installed_plugin_name
|
|
|
|
new_env[:action_runner].run(Action.action_uninstall, new_env)
|
|
|
|
end
|
|
|
|
end
|
2013-02-03 02:42:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|