logstash-core 1.5.0.rc3.snapshot6-java → 1.5.0.rc4-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of logstash-core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/logstash-core.rb +2 -0
- data/lib/logstash/agent.rb +0 -33
- data/lib/logstash/config/config_ast.rb +1 -1
- data/lib/logstash/environment.rb +8 -30
- data/lib/logstash/filters/base.rb +19 -0
- data/lib/logstash/namespace.rb +0 -1
- data/lib/logstash/runner.rb +3 -51
- data/lib/logstash/version.rb +1 -1
- data/logstash-core.gemspec +54 -0
- data/spec/core/conditionals_spec.rb +428 -0
- data/spec/core/config_mixin_spec.rb +99 -0
- data/spec/core/config_spec.rb +108 -0
- data/spec/core/environment_spec.rb +44 -0
- data/spec/core/event_spec.rb +468 -0
- data/spec/core/pipeline_spec.rb +198 -0
- data/spec/core/plugin_spec.rb +106 -0
- data/spec/core/runner_spec.rb +39 -0
- data/spec/core/timestamp_spec.rb +83 -0
- data/spec/filters/base_spec.rb +318 -0
- data/spec/inputs/base_spec.rb +13 -0
- data/spec/lib/logstash/bundler_spec.rb +120 -0
- data/spec/lib/logstash/java_integration_spec.rb +257 -0
- data/spec/logstash/agent_spec.rb +37 -0
- data/spec/outputs/base_spec.rb +47 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/util/accessors_spec.rb +215 -0
- data/spec/util/charset_spec.rb +74 -0
- data/spec/util/fieldeval_spec.rb +96 -0
- data/spec/util/gemfile_spec.rb +212 -0
- data/spec/util/json_spec.rb +97 -0
- data/spec/util/plugin_version_spec.rb +48 -0
- data/spec/util_spec.rb +34 -0
- metadata +84 -160
- data/lib/logstash-event.rb +0 -2
- data/lib/logstash.rb +0 -4
- data/lib/logstash/bundler.rb +0 -156
- data/lib/logstash/gemfile.rb +0 -193
- data/lib/logstash/pluginmanager.rb +0 -17
- data/lib/logstash/pluginmanager/command.rb +0 -38
- data/lib/logstash/pluginmanager/install.rb +0 -141
- data/lib/logstash/pluginmanager/list.rb +0 -44
- data/lib/logstash/pluginmanager/main.rb +0 -21
- data/lib/logstash/pluginmanager/uninstall.rb +0 -43
- data/lib/logstash/pluginmanager/update.rb +0 -105
- data/lib/logstash/pluginmanager/util.rb +0 -89
data/lib/logstash-event.rb
DELETED
data/lib/logstash.rb
DELETED
data/lib/logstash/bundler.rb
DELETED
@@ -1,156 +0,0 @@
|
|
1
|
-
require "logstash/environment"
|
2
|
-
|
3
|
-
module LogStash
|
4
|
-
module Bundler
|
5
|
-
# Take a gem package and extract it to a specific target
|
6
|
-
# @param [String] Gem file, this must be a path
|
7
|
-
# @param [String, String] Return a Gem::Package and the installed path
|
8
|
-
def self.unpack(file, path)
|
9
|
-
require "rubygems/package"
|
10
|
-
require "securerandom"
|
11
|
-
|
12
|
-
# We are creating a random directory per extract,
|
13
|
-
# if we dont do this bundler will not trigger download of the dependencies.
|
14
|
-
# Use case is:
|
15
|
-
# - User build his own gem with a fix
|
16
|
-
# - User doesnt increment the version
|
17
|
-
# - User install the same version but different code or dependencies multiple times..
|
18
|
-
basename = ::File.basename(file, '.gem')
|
19
|
-
unique = SecureRandom.hex(4)
|
20
|
-
target_path = ::File.expand_path(::File.join(path, unique, basename))
|
21
|
-
|
22
|
-
package = ::Gem::Package.new(file)
|
23
|
-
package.extract_files(target_path)
|
24
|
-
|
25
|
-
return [package, target_path]
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.setup!(options = {})
|
29
|
-
options = {:without => [:development]}.merge(options)
|
30
|
-
options[:without] = Array(options[:without])
|
31
|
-
|
32
|
-
# make sure we use our own installed bundler
|
33
|
-
require "logstash/patches/rubygems" # patch rubygems before clear_paths
|
34
|
-
::Gem.clear_paths
|
35
|
-
::Gem.paths = ENV['GEM_HOME'] = ENV['GEM_PATH'] = LogStash::Environment.logstash_gem_home
|
36
|
-
|
37
|
-
# set BUNDLE_GEMFILE ENV before requiring bundler to avoid bundler recurse and load unrelated Gemfile(s)
|
38
|
-
ENV["BUNDLE_GEMFILE"] = LogStash::Environment::GEMFILE_PATH
|
39
|
-
|
40
|
-
require "bundler"
|
41
|
-
require "logstash/bundler"
|
42
|
-
require "logstash/patches/bundler"
|
43
|
-
|
44
|
-
::Bundler.settings[:path] = LogStash::Environment::BUNDLE_DIR
|
45
|
-
::Bundler.settings[:without] = options[:without].join(":")
|
46
|
-
# in the context of Bundler.setup it looks like this is useless here because Gemfile path can only be specified using
|
47
|
-
# the ENV, see https://github.com/bundler/bundler/blob/v1.8.3/lib/bundler/shared_helpers.rb#L103
|
48
|
-
::Bundler.settings[:gemfile] = LogStash::Environment::GEMFILE_PATH
|
49
|
-
|
50
|
-
::Bundler.reset!
|
51
|
-
::Bundler.setup
|
52
|
-
end
|
53
|
-
|
54
|
-
# capture any $stdout from the passed block. also trap any exception in that block, in which case the trapped exception will be returned
|
55
|
-
# @param [Proc] the code block to execute
|
56
|
-
# @return [String, Exception] the captured $stdout string and any trapped exception or nil if none
|
57
|
-
def self.capture_stdout(&block)
|
58
|
-
old_stdout = $stdout
|
59
|
-
$stdout = StringIO.new("", "w")
|
60
|
-
begin
|
61
|
-
block.call
|
62
|
-
rescue => e
|
63
|
-
return [$stdout.string, e]
|
64
|
-
end
|
65
|
-
|
66
|
-
[$stdout.string, nil]
|
67
|
-
ensure
|
68
|
-
$stdout = old_stdout
|
69
|
-
end
|
70
|
-
|
71
|
-
# execute bundle install and capture any $stdout output. any raised exception in the process will be trapped
|
72
|
-
# and returned. logs errors to $stdout.
|
73
|
-
# @param options [Hash] invoke options with default values, :max_tries => 10, :clean => false, :install => false, :update => false
|
74
|
-
# @param options[:update] must be either false or a String or an Array of String
|
75
|
-
# @return [String, Exception] the installation captured output and any raised exception or nil if none
|
76
|
-
def self.invoke_bundler!(options = {})
|
77
|
-
options = {:max_tries => 10, :clean => false, :install => false, :update => false, :without => [:development]}.merge(options)
|
78
|
-
options[:without] = Array(options[:without])
|
79
|
-
options[:update] = Array(options[:update]) if options[:update]
|
80
|
-
|
81
|
-
# make sure we use our own installed bundler
|
82
|
-
require "logstash/patches/rubygems" # patch rubygems before clear_paths
|
83
|
-
::Gem.clear_paths
|
84
|
-
::Gem.paths = ENV['GEM_HOME'] = ENV['GEM_PATH'] = LogStash::Environment.logstash_gem_home
|
85
|
-
|
86
|
-
# set BUNDLE_GEMFILE ENV before requiring bundler to avoid bundler recurse and load unrelated Gemfile(s).
|
87
|
-
# in the context of calling Bundler::CLI this is not really required since Bundler::CLI will look at
|
88
|
-
# Bundler.settings[:gemfile] unlike Bundler.setup. For the sake of consistency and defensive/future proofing, let's keep it here.
|
89
|
-
ENV["BUNDLE_GEMFILE"] = LogStash::Environment::GEMFILE_PATH
|
90
|
-
|
91
|
-
require "bundler"
|
92
|
-
require "bundler/cli"
|
93
|
-
require "logstash/patches/bundler"
|
94
|
-
|
95
|
-
# force Rubygems sources to our Gemfile sources
|
96
|
-
::Gem.sources = options[:rubygems_source] if options[:rubygems_source]
|
97
|
-
|
98
|
-
::Bundler.settings[:path] = LogStash::Environment::BUNDLE_DIR
|
99
|
-
::Bundler.settings[:gemfile] = LogStash::Environment::GEMFILE_PATH
|
100
|
-
::Bundler.settings[:without] = options[:without].join(":")
|
101
|
-
|
102
|
-
try = 0
|
103
|
-
|
104
|
-
# capture_stdout also traps any raised exception and pass them back as the function return [output, exception]
|
105
|
-
output, exception = capture_stdout do
|
106
|
-
loop do
|
107
|
-
begin
|
108
|
-
::Bundler.reset!
|
109
|
-
::Bundler::CLI.start(bundler_arguments(options))
|
110
|
-
break
|
111
|
-
rescue ::Bundler::VersionConflict => e
|
112
|
-
$stderr.puts("Plugin version conflict, aborting")
|
113
|
-
raise(e)
|
114
|
-
rescue ::Bundler::GemNotFound => e
|
115
|
-
$stderr.puts("Plugin not found, aborting")
|
116
|
-
raise(e)
|
117
|
-
rescue => e
|
118
|
-
if try >= options[:max_tries]
|
119
|
-
$stderr.puts("Too many retries, aborting, caused by #{e.class}")
|
120
|
-
$stderr.puts(e.message) if ENV["DEBUG"]
|
121
|
-
raise(e)
|
122
|
-
end
|
123
|
-
|
124
|
-
try += 1
|
125
|
-
$stderr.puts("Error #{e.class}, retrying #{try}/#{options[:max_tries]}")
|
126
|
-
$stderr.puts(e.message)
|
127
|
-
sleep(0.5)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
raise exception if exception
|
133
|
-
|
134
|
-
return output
|
135
|
-
end
|
136
|
-
|
137
|
-
# build Bundler::CLI.start arguments array from the given options hash
|
138
|
-
# @param option [Hash] the invoke_bundler! options hash
|
139
|
-
# @return [Array<String>] Bundler::CLI.start string arguments array
|
140
|
-
def self.bundler_arguments(options = {})
|
141
|
-
arguments = []
|
142
|
-
|
143
|
-
if options[:install]
|
144
|
-
arguments << "install"
|
145
|
-
arguments << "--clean" if options[:clean]
|
146
|
-
elsif options[:update]
|
147
|
-
arguments << "update"
|
148
|
-
arguments << options[:update]
|
149
|
-
elsif options[:clean]
|
150
|
-
arguments << "clean"
|
151
|
-
end
|
152
|
-
|
153
|
-
arguments.flatten
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
data/lib/logstash/gemfile.rb
DELETED
@@ -1,193 +0,0 @@
|
|
1
|
-
require "logstash/util"
|
2
|
-
module LogStash
|
3
|
-
|
4
|
-
class GemfileError < StandardError; end
|
5
|
-
|
6
|
-
class Gemfile
|
7
|
-
attr_accessor :gemset
|
8
|
-
|
9
|
-
HEADER = \
|
10
|
-
"# This is a Logstash generated Gemfile.\n" + \
|
11
|
-
"# If you modify this file manually all comments and formatting will be lost.\n\n"
|
12
|
-
|
13
|
-
# @params io [IO] any IO object that supports read, write, truncate, rewind
|
14
|
-
def initialize(io)
|
15
|
-
@io = io
|
16
|
-
@gemset = nil
|
17
|
-
end
|
18
|
-
|
19
|
-
def load
|
20
|
-
@gemset ||= DSL.parse(@io.read)
|
21
|
-
backup
|
22
|
-
self
|
23
|
-
end
|
24
|
-
|
25
|
-
def save
|
26
|
-
raise(GemfileError, "a Gemfile must first be loaded") unless @gemset
|
27
|
-
@io.truncate(0)
|
28
|
-
@io.rewind
|
29
|
-
@io.write(HEADER)
|
30
|
-
@io.write(@gemset.to_s)
|
31
|
-
@io.flush
|
32
|
-
end
|
33
|
-
|
34
|
-
def find(name)
|
35
|
-
@gemset.find_gem(name)
|
36
|
-
end
|
37
|
-
|
38
|
-
# @param name [String] gem name
|
39
|
-
# @param *requirements params following name use the same notation as the Gemfile gem DSL statement
|
40
|
-
# @raise GemfileError if gem already exists in Gemfile
|
41
|
-
def add(name, *requirements)
|
42
|
-
@gemset.add_gem(Gem.parse(name, *requirements))
|
43
|
-
end
|
44
|
-
|
45
|
-
# update existing or add new
|
46
|
-
# @param name [String] gem name
|
47
|
-
# @param *requirements params following name use the same notation as the Gemfile gem DSL statement
|
48
|
-
def update(name, *requirements)
|
49
|
-
@gemset.update_gem(Gem.parse(name, *requirements))
|
50
|
-
end
|
51
|
-
|
52
|
-
# @return [Gem] removed gem or nil if not found
|
53
|
-
def remove(name)
|
54
|
-
@gemset.remove_gem(name)
|
55
|
-
end
|
56
|
-
|
57
|
-
def backup
|
58
|
-
@original_backup = @gemset.copy
|
59
|
-
end
|
60
|
-
|
61
|
-
def restore
|
62
|
-
@gemset = @original_backup
|
63
|
-
end
|
64
|
-
|
65
|
-
def restore!
|
66
|
-
restore
|
67
|
-
save
|
68
|
-
end
|
69
|
-
|
70
|
-
def locally_installed_gems
|
71
|
-
@gemset.gems.select { |gem| gem.options.include?(:path) }
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
class Gemset
|
76
|
-
attr_accessor :sources, :gems, :gemspec
|
77
|
-
|
78
|
-
def initialize
|
79
|
-
@sources = [] # list of urls
|
80
|
-
@gems = [] # list of Gem class
|
81
|
-
@gems_by_name = {} # hash of name => Gem
|
82
|
-
@gemspec = {} # gemspec is a options hash
|
83
|
-
end
|
84
|
-
|
85
|
-
def to_s
|
86
|
-
[sources_to_s, gemspec_to_s, gems_to_s].select{|s| !s.empty?}.join("\n") + "\n"
|
87
|
-
end
|
88
|
-
|
89
|
-
# @return [Gem] found gem or nil if not found
|
90
|
-
def find_gem(name)
|
91
|
-
@gems_by_name[name.downcase]
|
92
|
-
end
|
93
|
-
|
94
|
-
# @raise GemfileError if gem already exists
|
95
|
-
def add_gem(_gem)
|
96
|
-
raise(GemfileError, "duplicate gem #{_gem.name}") if find_gem(_gem.name)
|
97
|
-
@gems << _gem
|
98
|
-
@gems_by_name[_gem.name.downcase] = _gem
|
99
|
-
end
|
100
|
-
|
101
|
-
# update existing or add new
|
102
|
-
def update_gem(_gem)
|
103
|
-
if old = find_gem(_gem.name)
|
104
|
-
@gems[@gems.index(old)] = _gem
|
105
|
-
else
|
106
|
-
@gems << _gem
|
107
|
-
end
|
108
|
-
@gems_by_name[_gem.name.downcase] = _gem
|
109
|
-
end
|
110
|
-
|
111
|
-
# @return [Gem] removed gem or nil if not found
|
112
|
-
def remove_gem(name)
|
113
|
-
if _gem = @gems_by_name.delete(name.downcase)
|
114
|
-
@gems.delete_at(@gems.index(_gem))
|
115
|
-
end
|
116
|
-
_gem
|
117
|
-
end
|
118
|
-
|
119
|
-
# deep clone self
|
120
|
-
def copy
|
121
|
-
Marshal.load(Marshal.dump(self))
|
122
|
-
end
|
123
|
-
private
|
124
|
-
|
125
|
-
def sources_to_s
|
126
|
-
return "" if @sources.empty?
|
127
|
-
@sources.map{|source| "source #{source.inspect}"}.join("\n")
|
128
|
-
end
|
129
|
-
|
130
|
-
def gems_to_s
|
131
|
-
return "" if @gems.empty?
|
132
|
-
@gems.map do |gem|
|
133
|
-
requirements = gem.requirements.empty? ? nil : gem.requirements.map{|r| r.inspect}.join(", ")
|
134
|
-
options = gem.options.empty? ? nil : gem.options.map{|k, v| "#{k.inspect} => #{v.inspect}"}.join(", ")
|
135
|
-
"gem " + [gem.name.inspect, requirements, options].compact.join(", ")
|
136
|
-
end.join("\n")
|
137
|
-
end
|
138
|
-
|
139
|
-
def gemspec_to_s
|
140
|
-
return "" if @gemspec.empty?
|
141
|
-
options = @gemspec.map{|k, v| "#{k.inspect} => #{v.inspect}"}.join(", ")
|
142
|
-
"gemspec #{options}"
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
# DSL is a minimal, incomplete Gemfile DSL subset parser, only what is currently required is implemented.
|
147
|
-
class DSL
|
148
|
-
attr_reader :gemset
|
149
|
-
|
150
|
-
def initialize
|
151
|
-
@gemset = Gemset.new
|
152
|
-
end
|
153
|
-
|
154
|
-
# @param gemfile_content [String] the Gemfile string content
|
155
|
-
# @return [Gemset] parsed Gemfile content as a Gemset
|
156
|
-
def self.parse(gemfile_content)
|
157
|
-
dsl = self.new
|
158
|
-
dsl.instance_eval(gemfile_content)
|
159
|
-
dsl.gemset
|
160
|
-
end
|
161
|
-
|
162
|
-
# DSL methods
|
163
|
-
|
164
|
-
def source(url)
|
165
|
-
@gemset.sources << url
|
166
|
-
end
|
167
|
-
|
168
|
-
def gem(name, *requirements)
|
169
|
-
parsed = Gem.parse(name, *requirements)
|
170
|
-
@gemset.add_gem(parsed)
|
171
|
-
end
|
172
|
-
|
173
|
-
def gemspec(options = {})
|
174
|
-
raise(GemfileError, "cannot declare multiple gemspec directives") unless @gemset.gemspec.empty?
|
175
|
-
@gemset.gemspec = options
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
class Gem
|
180
|
-
attr_accessor :name, :requirements, :options
|
181
|
-
|
182
|
-
def initialize(name, requirements = [], options = {})
|
183
|
-
@name = name
|
184
|
-
@requirements = requirements.map{|r| r.to_s.strip}.select{|r| !r.empty?}
|
185
|
-
@options = options
|
186
|
-
end
|
187
|
-
|
188
|
-
def self.parse(name, *requirements)
|
189
|
-
options = requirements.last.is_a?(Hash) ? requirements.pop : {}
|
190
|
-
self.new(name, requirements, options)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
$DEBUGLIST = (ENV["DEBUG"] || "").split(",")
|
2
|
-
|
3
|
-
require "logstash/environment"
|
4
|
-
|
5
|
-
ENV["GEM_HOME"] = ENV["GEM_PATH"] = LogStash::Environment.logstash_gem_home
|
6
|
-
Gem.use_paths(LogStash::Environment.logstash_gem_home)
|
7
|
-
|
8
|
-
require 'logstash/pluginmanager/main'
|
9
|
-
|
10
|
-
if __FILE__ == $0
|
11
|
-
begin
|
12
|
-
LogStash::PluginManager::Main.run("bin/plugin", ARGV)
|
13
|
-
rescue LogStash::PluginManager::Error => e
|
14
|
-
$stderr.puts(e.message)
|
15
|
-
exit(1)
|
16
|
-
end
|
17
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
class LogStash::PluginManager::Command < Clamp::Command
|
2
|
-
def gemfile
|
3
|
-
@gemfile ||= LogStash::Gemfile.new(File.new(LogStash::Environment::GEMFILE_PATH, 'r+')).load
|
4
|
-
end
|
5
|
-
|
6
|
-
# If set in debug mode we will raise an exception and display the stacktrace
|
7
|
-
def report_exception(readable_message, exception)
|
8
|
-
if ENV["DEBUG"]
|
9
|
-
raise exception
|
10
|
-
else
|
11
|
-
signal_error("#{readable_message}, message: #{exception.message}")
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def display_bundler_output(output)
|
16
|
-
if ENV['DEBUG'] && output
|
17
|
-
# Display what bundler did in the last run
|
18
|
-
$stderr.puts("Bundler output")
|
19
|
-
$stderr.puts(output)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
# Each plugin install for a gemfile create a path with a unique id.
|
25
|
-
# we must clear what is not currently used in the
|
26
|
-
def remove_unused_locally_installed_gems!
|
27
|
-
used_path = gemfile.locally_installed_gems.collect { |gem| gem.options[:path] }
|
28
|
-
|
29
|
-
Dir.glob(File.join(LogStash::Environment::LOCAL_GEM_PATH, '*')) do |path|
|
30
|
-
FileUtils.rm_rf(relative_path(path)) if used_path.none? { |p| p.start_with?(relative_path(path)) }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def relative_path(path)
|
35
|
-
require "pathname"
|
36
|
-
::Pathname.new(path).relative_path_from(::Pathname.new(LogStash::Environment::LOGSTASH_HOME)).to_s
|
37
|
-
end
|
38
|
-
end
|
@@ -1,141 +0,0 @@
|
|
1
|
-
require "clamp"
|
2
|
-
require "logstash/namespace"
|
3
|
-
require "logstash/environment"
|
4
|
-
require "logstash/pluginmanager/util"
|
5
|
-
require "logstash/pluginmanager/command"
|
6
|
-
require "jar-dependencies"
|
7
|
-
require "jar_install_post_install_hook"
|
8
|
-
require "file-dependencies/gem"
|
9
|
-
require "logstash/gemfile"
|
10
|
-
require "logstash/bundler"
|
11
|
-
require "fileutils"
|
12
|
-
|
13
|
-
class LogStash::PluginManager::Install < LogStash::PluginManager::Command
|
14
|
-
parameter "[PLUGIN] ...", "plugin name(s) or file", :attribute_name => :plugins_arg
|
15
|
-
option "--version", "VERSION", "version of the plugin to install"
|
16
|
-
option "--[no-]verify", :flag, "verify plugin validity before installation", :default => true
|
17
|
-
option "--development", :flag, "install all development dependencies of currently installed plugins", :default => false
|
18
|
-
|
19
|
-
# the install logic below support installing multiple plugins with each a version specification
|
20
|
-
# but the argument parsing does not support it for now so currently if specifying --version only
|
21
|
-
# one plugin name can be also specified.
|
22
|
-
def execute
|
23
|
-
validate_cli_options!
|
24
|
-
|
25
|
-
if local_gems?
|
26
|
-
gems = extract_local_gems_plugins
|
27
|
-
elsif development?
|
28
|
-
gems = plugins_development_gems
|
29
|
-
else
|
30
|
-
gems = plugins_gems
|
31
|
-
verify_remote!(gems) if verify?
|
32
|
-
end
|
33
|
-
|
34
|
-
install_gems_list!(gems)
|
35
|
-
remove_unused_locally_installed_gems!
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
def validate_cli_options!
|
40
|
-
if development?
|
41
|
-
signal_usage_error("Cannot specify plugin(s) with --development, it will add the development dependencies of the currently installed plugins") unless plugins_arg.empty?
|
42
|
-
else
|
43
|
-
signal_usage_error("No plugin specified") if plugins_arg.empty? && verify?
|
44
|
-
# TODO: find right syntax to allow specifying list of plugins with optional version specification for each
|
45
|
-
signal_usage_error("Only 1 plugin name can be specified with --version") if version && plugins_arg.size > 1
|
46
|
-
end
|
47
|
-
signal_error("File #{LogStash::Environment::GEMFILE_PATH} does not exist or is not writable, aborting") unless ::File.writable?(LogStash::Environment::GEMFILE_PATH)
|
48
|
-
end
|
49
|
-
|
50
|
-
# Check if the specified gems contains
|
51
|
-
# the logstash `metadata`
|
52
|
-
def verify_remote!(gems)
|
53
|
-
gems.each do |plugin, version|
|
54
|
-
puts("Validating #{[plugin, version].compact.join("-")}")
|
55
|
-
signal_error("Installation aborted, verification failed for #{plugin} #{version}") unless LogStash::PluginManager.logstash_plugin?(plugin, version)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def plugins_development_gems
|
60
|
-
# Get currently defined gems and their dev dependencies
|
61
|
-
specs = []
|
62
|
-
|
63
|
-
specs = LogStash::PluginManager.all_installed_plugins_gem_specs(gemfile)
|
64
|
-
|
65
|
-
# Construct the list of dependencies to add to the current gemfile
|
66
|
-
specs.each_with_object([]) do |spec, install_list|
|
67
|
-
dependencies = spec.dependencies
|
68
|
-
.select { |dep| dep.type == :development }
|
69
|
-
.map { |dep| [dep.name] + dep.requirement.as_list }
|
70
|
-
|
71
|
-
install_list.concat(dependencies)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def plugins_gems
|
76
|
-
version ? [plugins_arg << version] : plugins_arg.map { |plugin| [plugin, nil] }
|
77
|
-
end
|
78
|
-
|
79
|
-
# install_list will be an array of [plugin name, version, options] tuples, version it
|
80
|
-
# can be nil at this point we know that plugins_arg is not empty and if the
|
81
|
-
# --version is specified there is only one plugin in plugins_arg
|
82
|
-
#
|
83
|
-
def install_gems_list!(install_list)
|
84
|
-
# If something goes wrong during the installation `LogStash::Gemfile` will restore a backup version.
|
85
|
-
install_list = LogStash::PluginManager.merge_duplicates(install_list)
|
86
|
-
|
87
|
-
# Add plugins/gems to the current gemfile
|
88
|
-
puts("Installing" + (install_list.empty? ? "..." : " " + install_list.collect(&:first).join(", ")))
|
89
|
-
install_list.each { |plugin, version, options| gemfile.update(plugin, version, options) }
|
90
|
-
|
91
|
-
# Sync gemfiles changes to disk to make them available to the `bundler install`'s API
|
92
|
-
gemfile.save
|
93
|
-
|
94
|
-
bundler_options = {:install => true}
|
95
|
-
bundler_options[:without] = [] if development?
|
96
|
-
bundler_options[:rubygems_source] = gemfile.gemset.sources
|
97
|
-
|
98
|
-
output = LogStash::Bundler.invoke_bundler!(bundler_options)
|
99
|
-
|
100
|
-
puts("Installation successful")
|
101
|
-
rescue => exception
|
102
|
-
gemfile.restore!
|
103
|
-
report_exception("Installation Aborted", exception)
|
104
|
-
ensure
|
105
|
-
display_bundler_output(output)
|
106
|
-
end
|
107
|
-
|
108
|
-
# Extract the specified local gems in a predefined local path
|
109
|
-
# Update the gemfile to use a relative path to this plugin and run
|
110
|
-
# Bundler, this will mark the gem not updatable by `bin/plugin update`
|
111
|
-
# This is the most reliable way to make it work in bundler without
|
112
|
-
# hacking with `how bundler works`
|
113
|
-
#
|
114
|
-
# Bundler 2.0, will have support for plugins source we could create a .gem source
|
115
|
-
# to support it.
|
116
|
-
def extract_local_gems_plugins
|
117
|
-
plugins_arg.collect do |plugin|
|
118
|
-
# We do the verify before extracting the gem so we dont have to deal with unused path
|
119
|
-
if verify?
|
120
|
-
puts("Validating #{plugin}")
|
121
|
-
signal_error("Installation aborted, verification failed for #{plugin}") unless LogStash::PluginManager.logstash_plugin?(plugin, version)
|
122
|
-
end
|
123
|
-
|
124
|
-
package, path = LogStash::Bundler.unpack(plugin, LogStash::Environment::LOCAL_GEM_PATH)
|
125
|
-
[package.spec.name, package.spec.version, { :path => relative_path(path) }]
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
# We cannot install both .gem and normal plugin in one call of `plugin install`
|
130
|
-
def local_gems?
|
131
|
-
return false if plugins_arg.empty?
|
132
|
-
|
133
|
-
local_gem = plugins_arg.collect { |plugin| ::File.extname(plugin) == ".gem" }.uniq
|
134
|
-
|
135
|
-
if local_gem.size == 1
|
136
|
-
return local_gem.first
|
137
|
-
else
|
138
|
-
signal_usage_error("Mixed source of plugins, you can't mix local `.gem` and remote gems")
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end # class Logstash::PluginManager
|