Sha256: 7efd4ec8dc29e74732a3658b3d232ace02d3d537d4b25d554a9bc0942f021761

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

require 'clamp'
require 'logstash/namespace'
require 'logstash/pluginmanager/util'
require 'jar-dependencies'
require 'jar_install_post_install_hook'
require 'file-dependencies/gem'

require "logstash/gemfile"
require "logstash/bundler"

class LogStash::PluginManager::Update < Clamp::Command
  parameter "[PLUGIN] ...", "Plugin name(s) to upgrade to latest version"

  def execute
    gemfile = LogStash::Gemfile.new(File.new(LogStash::Environment::GEMFILE_PATH, "r+")).load
    # keep a copy of the gemset to revert on error
    original_gemset = gemfile.gemset.copy

    # create list of plugins to update
    plugins = unless plugin_list.empty?
      not_installed = plugin_list.find{|plugin| !LogStash::PluginManager.installed_plugin?(plugin, gemfile)}
      raise(LogStash::PluginManager::Error, "Plugin #{not_installed} has not been previously installed, aborting") if not_installed
      plugin_list
    else
      LogStash::PluginManager.all_installed_plugins_gem_specs(gemfile).map{|spec| spec.name}
    end

    # remove any version constrain from the Gemfile so the plugin(s) can be updated to latest version
    # calling update without requiremend will remove any previous requirements
    plugins.each{|plugin| gemfile.update(plugin)}
    gemfile.save

    puts("Updating " + plugins.join(", "))

    # any errors will be logged to $stderr by invoke_bundler!
    output, exception = LogStash::Bundler.invoke_bundler!(:update => plugins)

    if ENV["DEBUG"]
      $stderr.puts(output)
      $stderr.puts("Error: #{exception.class}, #{exception.message}") if exception
    end

    if exception
      # revert to original Gemfile content
      gemfile.gemset = original_gemset
      gemfile.save
      raise(LogStash::PluginManager::Error, "Update aborted")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logstash-core-1.5.0.beta2-java lib/logstash/pluginmanager/update.rb