From a2b1dbb747289ac122b146f971193cfc9f7a2f97 Mon Sep 17 00:00:00 2001 From: Joao Duarte Date: Fri, 14 Jun 2019 17:49:25 +0100 Subject: [PATCH] avoid clashes between Environment class methods Fixes #10860 --- lib/bootstrap/environment.rb | 2 +- lib/pluginmanager/pack.rb | 4 ++-- lib/pluginmanager/unpack.rb | 4 ++-- logstash-core/lib/logstash/environment.rb | 8 ++++++-- logstash-core/spec/logstash/environment_spec.rb | 8 ++++---- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/bootstrap/environment.rb b/lib/bootstrap/environment.rb index 71d99b8ad02..513ef771144 100644 --- a/lib/bootstrap/environment.rb +++ b/lib/bootstrap/environment.rb @@ -42,7 +42,7 @@ def oss_only? !File.exists?(File.join(LogStash::Environment::LOGSTASH_HOME, "x-pack")) end - def windows? + def win_platform? ::Gem.win_platform? end diff --git a/lib/pluginmanager/pack.rb b/lib/pluginmanager/pack.rb index 2f00728199d..925216a3633 100644 --- a/lib/pluginmanager/pack.rb +++ b/lib/pluginmanager/pack.rb @@ -2,8 +2,8 @@ require_relative "pack_command" class LogStash::PluginManager::Pack < LogStash::PluginManager::PackCommand - option "--tgz", :flag, "compress package as a tar.gz file", :default => !LogStash::Environment.windows? - option "--zip", :flag, "compress package as a zip file", :default => LogStash::Environment.windows? + option "--tgz", :flag, "compress package as a tar.gz file", :default => !LogStash::Environment.win_platform? + option "--zip", :flag, "compress package as a zip file", :default => LogStash::Environment.win_platform? option "--[no-]clean", :flag, "clean up the generated dump of plugins", :default => true option "--overwrite", :flag, "Overwrite a previously generated package file", :default => false diff --git a/lib/pluginmanager/unpack.rb b/lib/pluginmanager/unpack.rb index f1f7221e171..c42f1ba2504 100644 --- a/lib/pluginmanager/unpack.rb +++ b/lib/pluginmanager/unpack.rb @@ -2,8 +2,8 @@ require_relative "pack_command" class LogStash::PluginManager::Unpack < LogStash::PluginManager::PackCommand - option "--tgz", :flag, "unpack a packaged tar.gz file", :default => !LogStash::Environment.windows? - option "--zip", :flag, "unpack a packaged zip file", :default => LogStash::Environment.windows? + option "--tgz", :flag, "unpack a packaged tar.gz file", :default => !LogStash::Environment.win_platform? + option "--zip", :flag, "unpack a packaged zip file", :default => LogStash::Environment.win_platform? parameter "file", "the package file name", :attribute_name => :package_file, :required => true diff --git a/logstash-core/lib/logstash/environment.rb b/logstash-core/lib/logstash/environment.rb index 31df098fafc..8e8dd22ec9d 100644 --- a/logstash-core/lib/logstash/environment.rb +++ b/logstash-core/lib/logstash/environment.rb @@ -164,11 +164,15 @@ def ruby_bin end def windows? - RbConfig::CONFIG['host_os'] =~ WINDOW_OS_RE + host_os =~ WINDOW_OS_RE end def linux? - RbConfig::CONFIG['host_os'] =~ LINUX_OS_RE + host_os =~ LINUX_OS_RE + end + + def host_os + RbConfig::CONFIG['host_os'] end def locales_path(path) diff --git a/logstash-core/spec/logstash/environment_spec.rb b/logstash-core/spec/logstash/environment_spec.rb index d64ed39412b..79d05fbea79 100644 --- a/logstash-core/spec/logstash/environment_spec.rb +++ b/logstash-core/spec/logstash/environment_spec.rb @@ -57,14 +57,14 @@ context "windows" do windows_host_os.each do |host| it "#{host} returns true" do - expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host) + allow(LogStash::Environment).to receive(:host_os).and_return(host) expect(LogStash::Environment.windows?).to be_truthy end end linux_host_os.each do |host| it "#{host} returns false" do - expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host) + allow(LogStash::Environment).to receive(:host_os).and_return(host) expect(LogStash::Environment.windows?).to be_falsey end end @@ -73,14 +73,14 @@ context "Linux" do windows_host_os.each do |host| it "#{host} returns true" do - expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host) + allow(LogStash::Environment).to receive(:host_os).and_return(host) expect(LogStash::Environment.linux?).to be_falsey end end linux_host_os.each do |host| it "#{host} returns false" do - expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host) + allow(LogStash::Environment).to receive(:host_os).and_return(host) expect(LogStash::Environment.linux?).to be_truthy end end