mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
parent
1055121b45
commit
a473fd6a6f
4 changed files with 21 additions and 12 deletions
|
@ -15,6 +15,12 @@ module LogStash
|
||||||
@gemset = nil
|
@gemset = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.open(file_path)
|
||||||
|
gemfile = new(::File.new(file_path, "r+"))
|
||||||
|
gemfile.load
|
||||||
|
gemfile
|
||||||
|
end
|
||||||
|
|
||||||
def load
|
def load
|
||||||
@gemset ||= DSL.parse(@io.read)
|
@gemset ||= DSL.parse(@io.read)
|
||||||
self
|
self
|
||||||
|
@ -51,6 +57,11 @@ module LogStash
|
||||||
def remove(name)
|
def remove(name)
|
||||||
@gemset.remove_gem(name)
|
@gemset.remove_gem(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def close
|
||||||
|
save if @gemset
|
||||||
|
@io.close
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Gemset
|
class Gemset
|
||||||
|
|
|
@ -32,7 +32,7 @@ class LogStash::PluginManager::Install < Clamp::Command
|
||||||
end
|
end
|
||||||
raise(LogStash::PluginManager::Error, "File #{LogStash::Environment::GEMFILE_PATH} does not exist or is not writable, aborting") unless File.writable?(LogStash::Environment::GEMFILE_PATH)
|
raise(LogStash::PluginManager::Error, "File #{LogStash::Environment::GEMFILE_PATH} does not exist or is not writable, aborting") unless File.writable?(LogStash::Environment::GEMFILE_PATH)
|
||||||
|
|
||||||
gemfile = LogStash::Gemfile.new(File.new(LogStash::Environment::GEMFILE_PATH, "r+")).load
|
gemfile = LogStash::Gemfile.open(LogStash::Environment::GEMFILE_PATH)
|
||||||
# keep a copy of the gemset to revert on error
|
# keep a copy of the gemset to revert on error
|
||||||
original_gemset = gemfile.gemset.copy
|
original_gemset = gemfile.gemset.copy
|
||||||
|
|
||||||
|
@ -58,17 +58,8 @@ class LogStash::PluginManager::Install < Clamp::Command
|
||||||
end if verify?
|
end if verify?
|
||||||
|
|
||||||
# at this point we know that we either have a valid gem name & version or a valid .gem file path
|
# at this point we know that we either have a valid gem name & version or a valid .gem file path
|
||||||
|
|
||||||
# if LogStash::PluginManager.plugin_file?(plugin)
|
|
||||||
# raise(LogStash::PluginManager::Error) unless cache_gem_file(plugin)
|
|
||||||
# spec = LogStash::PluginManager.plugin_file_spec(plugin)
|
|
||||||
# gemfile.update(spec.name, spec.version.to_s)
|
|
||||||
# else
|
|
||||||
# plugins.each{|tuple| gemfile.update(*tuple)}
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
install_list = LogStash::PluginManager.merge_duplicates(install_list)
|
install_list = LogStash::PluginManager.merge_duplicates(install_list)
|
||||||
install_list.each{|plugin, version| gemfile.update(plugin, version)}
|
install_list.each{|plugin, version| gemfile.update(plugin, version)}
|
||||||
gemfile.save
|
gemfile.save
|
||||||
|
@ -94,6 +85,9 @@ class LogStash::PluginManager::Install < Clamp::Command
|
||||||
end
|
end
|
||||||
|
|
||||||
puts("Installation successful")
|
puts("Installation successful")
|
||||||
|
|
||||||
|
ensure
|
||||||
|
gemfile.close if gemfile
|
||||||
end
|
end
|
||||||
|
|
||||||
# copy .gem file into bundler cache directory, log any error to $stderr
|
# copy .gem file into bundler cache directory, log any error to $stderr
|
||||||
|
|
|
@ -15,7 +15,7 @@ class LogStash::PluginManager::Uninstall < Clamp::Command
|
||||||
def execute
|
def execute
|
||||||
raise(LogStash::PluginManager::Error, "File #{LogStash::Environment::GEMFILE_PATH} does not exist or is not writable, aborting") unless File.writable?(LogStash::Environment::GEMFILE_PATH)
|
raise(LogStash::PluginManager::Error, "File #{LogStash::Environment::GEMFILE_PATH} does not exist or is not writable, aborting") unless File.writable?(LogStash::Environment::GEMFILE_PATH)
|
||||||
|
|
||||||
gemfile = LogStash::Gemfile.new(File.new(LogStash::Environment::GEMFILE_PATH, "r+")).load
|
gemfile = LogStash::Gemfile.open(LogStash::Environment::GEMFILE_PATH)
|
||||||
# keep a copy of the gemset to revert on error
|
# keep a copy of the gemset to revert on error
|
||||||
original_gemset = gemfile.gemset.copy
|
original_gemset = gemfile.gemset.copy
|
||||||
|
|
||||||
|
@ -45,5 +45,7 @@ class LogStash::PluginManager::Uninstall < Clamp::Command
|
||||||
raise(LogStash::PluginManager::Error, "Uninstall aborted")
|
raise(LogStash::PluginManager::Error, "Uninstall aborted")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
ensure
|
||||||
|
gemfile.close if gemfile
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,7 @@ class LogStash::PluginManager::Update < Clamp::Command
|
||||||
parameter "[PLUGIN] ...", "Plugin name(s) to upgrade to latest version"
|
parameter "[PLUGIN] ...", "Plugin name(s) to upgrade to latest version"
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
gemfile = LogStash::Gemfile.new(File.new(LogStash::Environment::GEMFILE_PATH, "r+")).load
|
gemfile = LogStash::Gemfile.open(LogStash::Environment::GEMFILE_PATH)
|
||||||
# keep a copy of the gemset to revert on error
|
# keep a copy of the gemset to revert on error
|
||||||
original_gemset = gemfile.gemset.copy
|
original_gemset = gemfile.gemset.copy
|
||||||
|
|
||||||
|
@ -60,6 +60,8 @@ class LogStash::PluginManager::Update < Clamp::Command
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
puts("No plugin updated") if update_count.zero?
|
puts("No plugin updated") if update_count.zero?
|
||||||
|
ensure
|
||||||
|
gemfile.close
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue