Sha256: b63a2b40214a93872eef4c6cf529ee11ff0c63abf3c4e914029973dc76b9b1cd

Contents?: true

Size: 1.77 KB

Versions: 19

Compression:

Stored size: 1.77 KB

Contents

require "fileutils"
require "pathname"
require "rubygems"
require "set"

require "log4r"

module VagrantPlugins
  module CommandPlugin
    module Action
      # This middleware licenses a plugin by copying the license file to
      # the proper place.
      class LicensePlugin
        def initialize(app, env)
          @app    = app
          @logger = Log4r::Logger.new("vagrant::plugins::plugincommand::license")
        end

        def call(env)
          # Get the list of installed plugins according to the state file
          installed = Set.new(env[:plugin_state_file].installed_plugins)

          # If the plugin we're trying to license doesn't exist in the
          # state file, then it is an error.
          if !installed.include?(env[:plugin_name])
            raise Vagrant::Errors::PluginNotFound, :name => env[:plugin_name]
          end

          # Verify the license file exists
          license_file = Pathname.new(env[:plugin_license_path])
          if !license_file.file?
            raise Vagrant::Errors::PluginInstallLicenseNotFound,
              :name => env[:plugin_name],
              :path => license_file.to_s
          end

          # Copy it in.
          final_path = env[:home_path].join("license-#{env[:plugin_name]}.lic")
          @logger.info("Copying license from: #{license_file}")
          @logger.info("Copying license to: #{final_path}")
          env[:ui].info(I18n.t("vagrant.commands.plugin.installing_license",
                               :name => env[:plugin_name]))
          FileUtils.cp(license_file, final_path)

          # Installed!
          env[:ui].success(I18n.t("vagrant.commands.plugin.installed_license",
                                 :name => env[:plugin_name]))

          @app.call(env)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 6 rubygems

Version Path
tamtam-vagrant-reload-1.1.3 vendor/cache/vagrant-0ac2a8738841/plugins/commands/plugin/action/license_plugin.rb
tamtam-vagrant-reload-1.1.2 vendor/cache/vagrant-0ac2a8738841/plugins/commands/plugin/action/license_plugin.rb
tamtam-vagrant-reload-1.1.1 vendor/cache/vagrant-0ac2a8738841/plugins/commands/plugin/action/license_plugin.rb
tamtam-vagrant-reload-1.1 vendor/cache/vagrant-0ac2a8738841/plugins/commands/plugin/action/license_plugin.rb
tnargav-1.3.6 plugins/commands/plugin/action/license_plugin.rb
tnargav-1.3.3 plugins/commands/plugin/action/license_plugin.rb
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/commands/plugin/action/license_plugin.rb
tnargav-1.2.3 plugins/commands/plugin/action/license_plugin.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/commands/plugin/action/license_plugin.rb
vagrant-shell-0.2.6 vendor/bundle/gems/tnargav-1.2.2/plugins/commands/plugin/action/license_plugin.rb
vagrant-shell-0.2.5 vendor/bundle/gems/tnargav-1.2.2/plugins/commands/plugin/action/license_plugin.rb
tnargav-1.2.2 plugins/commands/plugin/action/license_plugin.rb
vagrantup-1.1.3 plugins/commands/plugin/action/license_plugin.rb
vagrantup-1.1.2 plugins/commands/plugin/action/license_plugin.rb
vagrantup-1.1.1 plugins/commands/plugin/action/license_plugin.rb
vagrantup-1.1.0 plugins/commands/plugin/action/license_plugin.rb
vagrantup-1.1.4 plugins/commands/plugin/action/license_plugin.rb
vagrant-actionio-0.0.9 vendor/bundle/bundler/gems/vagrant-c74251a1d9c0/plugins/commands/plugin/action/license_plugin.rb
vagrant-lxc-0.0.1 vendor/vagrant/plugins/commands/plugin/action/license_plugin.rb