logstash-filter-mutate 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MmZhMDNmZDM5MGVmMGEwNTM4N2ZlMTlmZmIyNmZkODU5MmRiNzliMA==
5
- data.tar.gz: !binary |-
6
- MjE0Mzc3M2QyOTczN2Q3NDIyM2EyZGUwMmEzZTM5M2FjOWZhNjc3Mw==
2
+ SHA1:
3
+ metadata.gz: e1a18fa5b241d8d58dd013933b60a702dcfdc288
4
+ data.tar.gz: d33b112ef930d1000bbaf69be4b7cc323855aa95
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NGVlZWVmNjcwNWI0NTA2YWEzOGZiZmJmYjUzNGU0ODQ3NjFhMTFlZjBlZGNm
10
- MTE4NjAxYzU2YTUwY2JjMGE2NmNmZjUzNWU5ZmI0MWQzMjM3ZGMyYWZmMGI3
11
- YTU5NTAwNjcyOGNjZjE1ZDI2OTMxY2ExOTA3MzRjMzNlZTUyOWE=
12
- data.tar.gz: !binary |-
13
- M2JiODBlMzk1YTdhYzJjNGZmOGZhYzllNTQxZTNlNWIwYzNhYzE2YmZmMDA1
14
- ZDJmYjk2ZWU5M2JiNzA0OWQyOGE0OTBjNGRiMDdjMTM2NGRlMTUyNzY4Zjkz
15
- YzNlOTJjZTlkYzYxZDZlN2RmZTFjZDIxMzYwNzYxNDg3ODQ0M2I=
6
+ metadata.gz: f292e896bf3cf0ab5a13c0870193e1a77cc2dc55bb35b3502d36a3b38f2d445472cb531deaa6cece61647e2465038a444fd570860986f74f5d9740a59b7d5e44
7
+ data.tar.gz: 7ad094fff3b4c5212dff464f314a67f2fe6d3e85e312464bbd427561702cf63cbe2e1c0130f330bde9597200a7cc05bd936c547914d4eca26774f491ab9c9a06
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source 'http://rubygems.org'
2
- gem 'rake'
3
- gem 'gem_publisher'
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012-2014 Elasticsearch <http://www.elasticsearch.org>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/Rakefile CHANGED
@@ -4,3 +4,4 @@ task :default do
4
4
  system("rake -T")
5
5
  end
6
6
 
7
+ require "logstash/devutils/rake"
@@ -5,7 +5,7 @@ require "logstash/namespace"
5
5
  # The mutate filter allows you to perform general mutations on fields. You
6
6
  # can rename, remove, replace, and modify fields in your events.
7
7
  #
8
- # TODO(sissel): Support regexp replacements like String#gsub ?
8
+ # TODO(sissel): Support regexp replacements like `String#gsub` ?
9
9
  class LogStash::Filters::Mutate < LogStash::Filters::Base
10
10
  config_name "mutate"
11
11
  milestone 3
@@ -13,7 +13,7 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
13
13
  # Rename one or more fields.
14
14
  #
15
15
  # Example:
16
- #
16
+ # [source,ruby]
17
17
  # filter {
18
18
  # mutate {
19
19
  # # Renames the 'HOSTORIP' field to 'client_ip'
@@ -25,14 +25,14 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
25
25
  # Remove one or more fields.
26
26
  #
27
27
  # Example:
28
- #
28
+ # [source,ruby]
29
29
  # filter {
30
30
  # mutate {
31
31
  # remove => [ "client" ] # Removes the 'client' field
32
32
  # }
33
33
  # }
34
34
  #
35
- # This option is deprecated, instead use remove_field option available in all
35
+ # This option is deprecated, instead use `remove_field` option available in all
36
36
  # filters.
37
37
  config :remove, :validate => :array, :deprecated => true
38
38
 
@@ -40,7 +40,7 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
40
40
  # to help you build a new value from other parts of the event.
41
41
  #
42
42
  # Example:
43
- #
43
+ # [source,ruby]
44
44
  # filter {
45
45
  # mutate {
46
46
  # replace => { "message" => "%{source_host}: My new message" }
@@ -52,7 +52,7 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
52
52
  # then no action will be taken.
53
53
  #
54
54
  # Example:
55
- #
55
+ # [source,ruby]
56
56
  # filter {
57
57
  # mutate {
58
58
  # update => { "sample" => "My new message" }
@@ -67,7 +67,7 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
67
67
  # Valid conversion targets are: integer, float, string.
68
68
  #
69
69
  # Example:
70
- #
70
+ # [source,ruby]
71
71
  # filter {
72
72
  # mutate {
73
73
  # convert => { "fieldname" => "integer" }
@@ -84,7 +84,7 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
84
84
  # Be aware of escaping any backslash in the config file.
85
85
  #
86
86
  # Example:
87
- #
87
+ # [source,ruby]
88
88
  # filter {
89
89
  # mutate {
90
90
  # gsub => [
@@ -103,7 +103,7 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
103
103
  # Convert a string to its uppercase equivalent.
104
104
  #
105
105
  # Example:
106
- #
106
+ # [source,ruby]
107
107
  # filter {
108
108
  # mutate {
109
109
  # uppercase => [ "fieldname" ]
@@ -114,7 +114,7 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
114
114
  # Convert a string to its lowercase equivalent.
115
115
  #
116
116
  # Example:
117
- #
117
+ # [source,ruby]
118
118
  # filter {
119
119
  # mutate {
120
120
  # lowercase => [ "fieldname" ]
@@ -126,7 +126,7 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
126
126
  # fields.
127
127
  #
128
128
  # Example:
129
- #
129
+ # [source,ruby]
130
130
  # filter {
131
131
  # mutate {
132
132
  # split => { "fieldname" => "," }
@@ -137,7 +137,7 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
137
137
  # Join an array with a separator character. Does nothing on non-array fields.
138
138
  #
139
139
  # Example:
140
- #
140
+ # [source,ruby]
141
141
  # filter {
142
142
  # mutate {
143
143
  # join => { "fieldname" => "," }
@@ -148,7 +148,7 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
148
148
  # Strip whitespace from field. NOTE: this only works on leading and trailing whitespace.
149
149
  #
150
150
  # Example:
151
- #
151
+ # [source,ruby]
152
152
  # filter {
153
153
  # mutate {
154
154
  # strip => ["field1", "field2"]
@@ -158,12 +158,13 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
158
158
 
159
159
  # Merge two fields of arrays or hashes.
160
160
  # String fields will be automatically be converted into an array, so:
161
- # array + string will work
162
- # string + string will result in an 2 entry array in dest_field
163
- # array and hash will not work
164
- #
161
+ # ==========================
162
+ # `array` + `string` will work
163
+ # `string` + `string` will result in an 2 entry array in `dest_field`
164
+ # `array` and `hash` will not work
165
+ # ==========================
165
166
  # Example:
166
- #
167
+ # [source,ruby]
167
168
  # filter {
168
169
  # mutate {
169
170
  # merge => { "dest_field" => "added_field" }
@@ -390,21 +391,19 @@ class LogStash::Filters::Mutate < LogStash::Filters::Base
390
391
  private
391
392
  def merge(event)
392
393
  @merge.each do |dest_field, added_fields|
393
- #When multiple calls, added_field is an array
394
- added_fields = [ added_fields ] if ! added_fields.is_a?(Array)
395
- added_fields.each do |added_field|
394
+ # When multiple calls, added_field is an array
395
+ Array(added_fields).each do |added_field|
396
396
  if event[dest_field].is_a?(Hash) ^ event[added_field].is_a?(Hash)
397
- @logger.error("Not possible to merge an array and a hash: ",
398
- :dest_field => dest_field,
399
- :added_field => added_field )
397
+ @logger.error("Not possible to merge an array and a hash: ", :dest_field => dest_field, :added_field => added_field )
400
398
  next
401
399
  end
402
- if event[dest_field].is_a?(Hash) #No need to test the other
400
+
401
+ if event[dest_field].is_a?(Hash)
402
+ # No need to test the other
403
403
  event[dest_field].update(event[added_field])
404
404
  else
405
- event[dest_field] = [event[dest_field]] if ! event[dest_field].is_a?(Array)
406
- event[added_field] = [event[added_field]] if ! event[added_field].is_a?(Array)
407
- event[dest_field].concat(event[added_field])
405
+ event[dest_field] = Array(event[dest_field])
406
+ event[dest_field].concat(Array(event[added_field]))
408
407
  end
409
408
  end
410
409
  end
@@ -1,13 +1,13 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-mutate'
4
- s.version = '0.1.0'
4
+ s.version = '0.1.1'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "The mutate filter allows you to perform general mutations on fields. You can rename, remove, replace, and modify fields in your events."
7
- s.description = "The mutate filter allows you to perform general mutations on fields. You can rename, remove, replace, and modify fields in your events."
7
+ s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
8
8
  s.authors = ["Elasticsearch"]
9
- s.email = 'richard.pijnenburg@elasticsearch.com'
10
- s.homepage = "http://logstash.net/"
9
+ s.email = 'info@elasticsearch.com'
10
+ s.homepage = "http://www.elasticsearch.org/guide/en/logstash/current/index.html"
11
11
  s.require_paths = ["lib"]
12
12
 
13
13
  # Files
@@ -17,10 +17,12 @@ Gem::Specification.new do |s|
17
17
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
18
 
19
19
  # Special flag to let us know this is actually a logstash plugin
20
- s.metadata = { "logstash_plugin" => "true", "group" => "filter" }
20
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
21
21
 
22
22
  # Gem dependencies
23
23
  s.add_runtime_dependency 'logstash', '>= 1.4.0', '< 2.0.0'
24
-
24
+ s.add_runtime_dependency 'logstash-patterns-core'
25
+ s.add_runtime_dependency 'logstash-filter-grok'
26
+ s.add_development_dependency 'logstash-devutils'
25
27
  end
26
28
 
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "spec_helper"
3
+ require "logstash/devutils/rspec/spec_helper"
4
4
  require "logstash/filters/mutate"
5
5
 
6
6
  describe LogStash::Filters::Mutate do
@@ -254,5 +254,104 @@ describe LogStash::Filters::Mutate do
254
254
  ]
255
255
  end
256
256
  end
257
+
258
+ describe "merge string field into inexisting field" do
259
+ config '
260
+ filter {
261
+ mutate {
262
+ merge => [ "list", "foo" ]
263
+ }
264
+ }'
265
+
266
+ sample("foo" => "bar") do
267
+ insist { subject["list"] } == ["bar"]
268
+ insist { subject["foo"] } == "bar"
269
+ end
270
+ end
271
+
272
+ describe "merge string field into empty array" do
273
+ config '
274
+ filter {
275
+ mutate {
276
+ merge => [ "list", "foo" ]
277
+ }
278
+ }'
279
+
280
+ sample("foo" => "bar", "list" => []) do
281
+ insist { subject["list"] } == ["bar"]
282
+ insist { subject["foo"] } == "bar"
283
+ end
284
+ end
285
+
286
+ describe "merge string field into existing array" do
287
+ config '
288
+ filter {
289
+ mutate {
290
+ merge => [ "list", "foo" ]
291
+ }
292
+ }'
293
+
294
+ sample("foo" => "bar", "list" => ["baz"]) do
295
+ insist { subject["list"] } == ["baz", "bar"]
296
+ insist { subject["foo"] } == "bar"
297
+ end
298
+ end
299
+
300
+ describe "merge non empty array field into existing array" do
301
+ config '
302
+ filter {
303
+ mutate {
304
+ merge => [ "list", "foo" ]
305
+ }
306
+ }'
307
+
308
+ sample("foo" => ["bar"], "list" => ["baz"]) do
309
+ insist { subject["list"] } == ["baz", "bar"]
310
+ insist { subject["foo"] } == ["bar"]
311
+ end
312
+ end
313
+
314
+ describe "merge empty array field into existing array" do
315
+ config '
316
+ filter {
317
+ mutate {
318
+ merge => [ "list", "foo" ]
319
+ }
320
+ }'
321
+
322
+ sample("foo" => [], "list" => ["baz"]) do
323
+ insist { subject["list"] } == ["baz"]
324
+ insist { subject["foo"] } == []
325
+ end
326
+ end
327
+
328
+ describe "merge array field into string field" do
329
+ config '
330
+ filter {
331
+ mutate {
332
+ merge => [ "list", "foo" ]
333
+ }
334
+ }'
335
+
336
+ sample("foo" => ["bar"], "list" => "baz") do
337
+ insist { subject["list"] } == ["baz", "bar"]
338
+ insist { subject["foo"] } == ["bar"]
339
+ end
340
+ end
341
+
342
+ describe "merge string field into string field" do
343
+ config '
344
+ filter {
345
+ mutate {
346
+ merge => [ "list", "foo" ]
347
+ }
348
+ }'
349
+
350
+ sample("foo" => "bar", "list" => "baz") do
351
+ insist { subject["list"] } == ["baz", "bar"]
352
+ insist { subject["foo"] } == "bar"
353
+ end
354
+ end
355
+
257
356
  end
258
357
 
metadata CHANGED
@@ -1,76 +1,115 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-mutate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elasticsearch
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-25 00:00:00.000000000 Z
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
15
23
  requirement: !ruby/object:Gem::Requirement
16
24
  requirements:
17
- - - ! '>='
25
+ - - '>='
18
26
  - !ruby/object:Gem::Version
19
27
  version: 1.4.0
20
28
  - - <
21
29
  - !ruby/object:Gem::Version
22
30
  version: 2.0.0
31
+ prerelease: false
32
+ type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-patterns-core
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ prerelease: false
23
46
  type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: logstash-filter-grok
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
24
59
  prerelease: false
60
+ type: :runtime
61
+ - !ruby/object:Gem::Dependency
62
+ name: logstash-devutils
25
63
  version_requirements: !ruby/object:Gem::Requirement
26
64
  requirements:
27
- - - ! '>='
65
+ - - '>='
28
66
  - !ruby/object:Gem::Version
29
- version: 1.4.0
30
- - - <
67
+ version: '0'
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
31
71
  - !ruby/object:Gem::Version
32
- version: 2.0.0
33
- description: The mutate filter allows you to perform general mutations on fields.
34
- You can rename, remove, replace, and modify fields in your events.
35
- email: richard.pijnenburg@elasticsearch.com
72
+ version: '0'
73
+ prerelease: false
74
+ type: :development
75
+ description: This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program
76
+ email: info@elasticsearch.com
36
77
  executables: []
37
78
  extensions: []
38
79
  extra_rdoc_files: []
39
80
  files:
40
81
  - .gitignore
41
82
  - Gemfile
83
+ - LICENSE
42
84
  - Rakefile
43
85
  - lib/logstash/filters/mutate.rb
44
86
  - logstash-filter-mutate.gemspec
45
- - rakelib/publish.rake
46
- - rakelib/vendor.rake
47
87
  - spec/filters/mutate_spec.rb
48
- homepage: http://logstash.net/
88
+ homepage: http://www.elasticsearch.org/guide/en/logstash/current/index.html
49
89
  licenses:
50
90
  - Apache License (2.0)
51
91
  metadata:
52
92
  logstash_plugin: 'true'
53
- group: filter
54
- post_install_message:
93
+ logstash_group: filter
94
+ post_install_message:
55
95
  rdoc_options: []
56
96
  require_paths:
57
97
  - lib
58
98
  required_ruby_version: !ruby/object:Gem::Requirement
59
99
  requirements:
60
- - - ! '>='
100
+ - - '>='
61
101
  - !ruby/object:Gem::Version
62
102
  version: '0'
63
103
  required_rubygems_version: !ruby/object:Gem::Requirement
64
104
  requirements:
65
- - - ! '>='
105
+ - - '>='
66
106
  - !ruby/object:Gem::Version
67
107
  version: '0'
68
108
  requirements: []
69
- rubyforge_project:
70
- rubygems_version: 2.4.1
71
- signing_key:
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.4
111
+ signing_key:
72
112
  specification_version: 4
73
- summary: The mutate filter allows you to perform general mutations on fields. You
74
- can rename, remove, replace, and modify fields in your events.
113
+ summary: The mutate filter allows you to perform general mutations on fields. You can rename, remove, replace, and modify fields in your events.
75
114
  test_files:
76
115
  - spec/filters/mutate_spec.rb
data/rakelib/publish.rake DELETED
@@ -1,9 +0,0 @@
1
- require "gem_publisher"
2
-
3
- desc "Publish gem to RubyGems.org"
4
- task :publish_gem do |t|
5
- gem_file = Dir.glob(File.expand_path('../*.gemspec',File.dirname(__FILE__))).first
6
- gem = GemPublisher.publish_if_updated(gem_file, :rubygems)
7
- puts "Published #{gem}" if gem
8
- end
9
-
data/rakelib/vendor.rake DELETED
@@ -1,169 +0,0 @@
1
- require "net/http"
2
- require "uri"
3
- require "digest/sha1"
4
-
5
- def vendor(*args)
6
- return File.join("vendor", *args)
7
- end
8
-
9
- directory "vendor/" => ["vendor"] do |task, args|
10
- mkdir task.name
11
- end
12
-
13
- def fetch(url, sha1, output)
14
-
15
- puts "Downloading #{url}"
16
- actual_sha1 = download(url, output)
17
-
18
- if actual_sha1 != sha1
19
- fail "SHA1 does not match (expected '#{sha1}' but got '#{actual_sha1}')"
20
- end
21
- end # def fetch
22
-
23
- def file_fetch(url, sha1)
24
- filename = File.basename( URI(url).path )
25
- output = "vendor/#{filename}"
26
- task output => [ "vendor/" ] do
27
- begin
28
- actual_sha1 = file_sha1(output)
29
- if actual_sha1 != sha1
30
- fetch(url, sha1, output)
31
- end
32
- rescue Errno::ENOENT
33
- fetch(url, sha1, output)
34
- end
35
- end.invoke
36
-
37
- return output
38
- end
39
-
40
- def file_sha1(path)
41
- digest = Digest::SHA1.new
42
- fd = File.new(path, "r")
43
- while true
44
- begin
45
- digest << fd.sysread(16384)
46
- rescue EOFError
47
- break
48
- end
49
- end
50
- return digest.hexdigest
51
- ensure
52
- fd.close if fd
53
- end
54
-
55
- def download(url, output)
56
- uri = URI(url)
57
- digest = Digest::SHA1.new
58
- tmp = "#{output}.tmp"
59
- Net::HTTP.start(uri.host, uri.port, :use_ssl => (uri.scheme == "https")) do |http|
60
- request = Net::HTTP::Get.new(uri.path)
61
- http.request(request) do |response|
62
- fail "HTTP fetch failed for #{url}. #{response}" if [200, 301].include?(response.code)
63
- size = (response["content-length"].to_i || -1).to_f
64
- count = 0
65
- File.open(tmp, "w") do |fd|
66
- response.read_body do |chunk|
67
- fd.write(chunk)
68
- digest << chunk
69
- if size > 0 && $stdout.tty?
70
- count += chunk.bytesize
71
- $stdout.write(sprintf("\r%0.2f%%", count/size * 100))
72
- end
73
- end
74
- end
75
- $stdout.write("\r \r") if $stdout.tty?
76
- end
77
- end
78
-
79
- File.rename(tmp, output)
80
-
81
- return digest.hexdigest
82
- rescue SocketError => e
83
- puts "Failure while downloading #{url}: #{e}"
84
- raise
85
- ensure
86
- File.unlink(tmp) if File.exist?(tmp)
87
- end # def download
88
-
89
- def untar(tarball, &block)
90
- require "archive/tar/minitar"
91
- tgz = Zlib::GzipReader.new(File.open(tarball))
92
- # Pull out typesdb
93
- tar = Archive::Tar::Minitar::Input.open(tgz)
94
- tar.each do |entry|
95
- path = block.call(entry)
96
- next if path.nil?
97
- parent = File.dirname(path)
98
-
99
- mkdir_p parent unless File.directory?(parent)
100
-
101
- # Skip this file if the output file is the same size
102
- if entry.directory?
103
- mkdir path unless File.directory?(path)
104
- else
105
- entry_mode = entry.instance_eval { @mode } & 0777
106
- if File.exists?(path)
107
- stat = File.stat(path)
108
- # TODO(sissel): Submit a patch to archive-tar-minitar upstream to
109
- # expose headers in the entry.
110
- entry_size = entry.instance_eval { @size }
111
- # If file sizes are same, skip writing.
112
- next if stat.size == entry_size && (stat.mode & 0777) == entry_mode
113
- end
114
- puts "Extracting #{entry.full_name} from #{tarball} #{entry_mode.to_s(8)}"
115
- File.open(path, "w") do |fd|
116
- # eof? check lets us skip empty files. Necessary because the API provided by
117
- # Archive::Tar::Minitar::Reader::EntryStream only mostly acts like an
118
- # IO object. Something about empty files in this EntryStream causes
119
- # IO.copy_stream to throw "can't convert nil into String" on JRuby
120
- # TODO(sissel): File a bug about this.
121
- while !entry.eof?
122
- chunk = entry.read(16384)
123
- fd.write(chunk)
124
- end
125
- #IO.copy_stream(entry, fd)
126
- end
127
- File.chmod(entry_mode, path)
128
- end
129
- end
130
- tar.close
131
- File.unlink(tarball) if File.file?(tarball)
132
- end # def untar
133
-
134
- def ungz(file)
135
-
136
- outpath = file.gsub('.gz', '')
137
- tgz = Zlib::GzipReader.new(File.open(file))
138
- begin
139
- File.open(outpath, "w") do |out|
140
- IO::copy_stream(tgz, out)
141
- end
142
- File.unlink(file)
143
- rescue
144
- File.unlink(outpath) if File.file?(outpath)
145
- raise
146
- end
147
- tgz.close
148
- end
149
-
150
- desc "Process any vendor files required for this plugin"
151
- task "vendor" do |task, args|
152
-
153
- @files.each do |file|
154
- download = file_fetch(file['url'], file['sha1'])
155
- if download =~ /.tar.gz/
156
- prefix = download.gsub('.tar.gz', '').gsub('vendor/', '')
157
- untar(download) do |entry|
158
- if !file['files'].nil?
159
- next unless file['files'].include?(entry.full_name.gsub(prefix, ''))
160
- out = entry.full_name.split("/").last
161
- end
162
- File.join('vendor', out)
163
- end
164
- elsif download =~ /.gz/
165
- ungz(download)
166
- end
167
- end
168
-
169
- end