file-dependencies 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,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGQzMzBmNzkxOTg4MDdiYzkxNTRlMWZkNjUxZDVlYjNkMDBkZTg1Nw==
4
+ OGM4NTY0ZjEwMzliMWM1MTBiOGU3NzIyOTJhMGIyNDJhZTFiMmUzMg==
5
5
  data.tar.gz: !binary |-
6
- ZTUyZTRmMjIyZGM4ZjM4ZjdjODcyODc4NjQ0NTBjZmFkZDBjNmIyYg==
6
+ YTdmYTQwODE1Y2ZiZTcxZWNiZWYwMmI2OGVkNjY0MjgwMTU1ZTRlYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDBjYjlkNDQ3NzI5OGFlOGY1ZjI1NDc0MmNmMDAxNjE0NDU0ZmM5NjQ3ODY1
10
- M2Q3ZTE1ZjMwYmY5Y2IzZDhkMzNmNmNlZDYzYTViM2RlNTIwMGRiYTlhOTQ5
11
- MzBkN2E0YjlmMTU3YjJkZThmMmM2MzFkZjhhMTZmMTQ3NzYxZjE=
9
+ Y2YzMGY5ZDY1ODZiOTA5M2NhMTY5ZGMyNmI4ZWY4ODFkNzllYTA1M2FjNWY5
10
+ ZTRjYTRhYzUyNWNhNmVkMWM2YmNlMWNkMzhkMjRhYWM3ODcwOGM1ZWJkNzll
11
+ MDQwNjVjZDRiMjQ4NDI2MGJkMTcxMjg4NDMxYjA3ZTQzYjU5YzU=
12
12
  data.tar.gz: !binary |-
13
- NThmZmM1YjA4MmI2ZGZhNDgxNzZlMTFlYTJlMWQ5ZDM1M2FhNzU5ZDNjYTNl
14
- YWI5YzY0N2VhNWUxOWU1YjU4ZjU3N2QzZTljNjU1YjY0YjFhMGQzOWJkMjE5
15
- ZGY3YjRhYjY3MTNiNDIxZDhhY2FjMzYyOTkyZTI1ZmM0OTRjNWE=
13
+ MGRmOWI2YjNjOGFjY2M1NGE1OWU5MGJkNTg0NjY0ZDhhZDlkMTlhZDc3ZmNh
14
+ ZTVlZjI2NjQyYzdmYmRjNDllYjJhZmNiYTYxNzBkYWNlNjI1YWY5YmI3MzQ4
15
+ ZmZkYjllMjI3MzFjM2RlNmFiOGY2ZjZjODI2ZTdmMTJkZDA2MjU=
@@ -23,6 +23,8 @@ Gem::Specification.new do |s|
23
23
  s.add_development_dependency 'rspec'
24
24
  s.add_development_dependency 'stud'
25
25
  s.add_development_dependency 'webmock'
26
+ s.add_development_dependency 'coveralls'
27
+ s.add_development_dependency 'codeclimate-test-reporter'
26
28
  end
27
29
 
28
30
  # vim: syntax=Ruby
@@ -20,13 +20,17 @@ module FileDependencies
20
20
  def download(files, target, tmpdir)
21
21
  FileUtils.mkdir_p(target) unless ::File.directory?(target)
22
22
  files.each do |file|
23
- target = ::File.join(target, file['target']) if !file['target'].nil?
23
+ target = ::File.join(target, file['target']) unless file['target'].nil?
24
24
  download = FileDependencies::File.fetch_file(file['url'], file['sha1'], tmpdir)
25
25
  if (res = download.match(/(\S+?)(\.tar\.gz|\.tgz)/))
26
26
  prefix = res.captures.first.gsub("#{tmpdir}/", '')
27
27
  FileDependencies::Archive.untar(download) do |entry|
28
- next unless (out = FileDependencies::Archive.eval_file(entry, file['extract'], prefix))
29
- ::File.join(target, out)
28
+ if file['extract'].nil?
29
+ ::File.join(target, entry.full_name.gsub(prefix, ''))
30
+ else
31
+ next unless FileDependencies::Archive.eval_file(entry.full_name, file['extract'], prefix)
32
+ ::File.join(target, entry.full_name.split("/").last)
33
+ end
30
34
  end
31
35
  elsif download =~ /.gz/
32
36
  FileDependencies::Archive.ungzip(download, target)
@@ -22,7 +22,6 @@ module FileDependencies
22
22
 
23
23
  def untar(tarball, &block)
24
24
  tgz = Zlib::GzipReader.new(::File.open(tarball))
25
- # Pull out typesdb
26
25
  tar = ::Archive::Tar::Minitar::Input.open(tgz)
27
26
  tar.each do |entry|
28
27
  path = block.call(entry)
@@ -66,19 +65,19 @@ module FileDependencies
66
65
  module_function :untar
67
66
 
68
67
  def eval_file(entry, files, prefix)
69
- # Avoid tarball headers
70
- return false if entry.full_name =~ /PaxHeaders/
71
- return entry.full_name.gsub(prefix, '') if files.nil?
72
-
68
+ return false if tar_header?(entry)
73
69
  if files.is_a?(Array)
74
- # Extract specific files given
75
- return false unless files.include?(entry.full_name.gsub(prefix, ''))
76
- entry.full_name.split("/").last
70
+ return true if files.include?(entry.gsub(prefix, ''))
77
71
  elsif files.is_a?(String)
78
- return false unless entry.full_name =~ Regexp.new(files)
79
- entry.full_name.split("/").last
72
+ return true if entry =~ Regexp.new(files)
80
73
  end
74
+ false
81
75
  end
82
76
  module_function :eval_file
77
+
78
+ def tar_header?(entry)
79
+ entry =~ /PaxHeaders/
80
+ end
81
+ module_function :tar_header?
83
82
  end
84
83
  end
@@ -10,11 +10,11 @@ module FileDependencies
10
10
  SHA1_REGEXP = /(\b[0-9a-f]{40}\b)/
11
11
 
12
12
  def fetch_sha1(remote_sha1)
13
- unless URI(remote_sha1.to_s).scheme.nil?
13
+ if URI(remote_sha1.to_s).scheme.nil?
14
+ sha1 = remote_sha1
15
+ else
14
16
  file = download(remote_sha1, Dir.tmpdir)
15
17
  sha1 = IO.read(file).gsub("\n", '')
16
- else
17
- sha1 = remote_sha1
18
18
  end
19
19
  raise("invalid SHA1 signature. Got '#{sha1}'") unless sha1.match(SHA1_REGEXP)
20
20
  sha1
@@ -1,3 +1,3 @@
1
1
  # Note to authors: this should not include dashes because 'gem' barfs if
2
2
  # you include a dash in the version string.
3
- APP_VERSION = '0.1.0'
3
+ APP_VERSION = '0.1.1'
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'tmpdir'
3
2
  require 'file-dependencies/archive'
4
3
 
5
4
  describe FileDependencies::Archive do
@@ -12,7 +11,7 @@ describe FileDependencies::Archive do
12
11
  FileUtils.remove_entry_secure(tmpdir)
13
12
  end
14
13
  let(:gzipfile) { Assist.generate_gzip('some_content') }
15
- let(:expected_file) { gzipfile.gsub('.gz','') }
14
+ let(:expected_file) { gzipfile.gsub('.gz', '') }
16
15
  let(:tmpdir) { Stud::Temporary.directory }
17
16
 
18
17
  it 'decompresses a gzip file'do
@@ -34,11 +33,11 @@ describe FileDependencies::Archive do
34
33
  end
35
34
 
36
35
  let(:file) { Assist.generate_file('some_content') }
37
- let(:tarball) { Assist.generate_tarball({'some/file' => 'content1', 'some/other/file' => 'content2', 'other' => 'content3'}) }
36
+ let(:tarball) { Assist.generate_tarball('some/file' => 'content1', 'some/other/file' => 'content2', 'other' => 'content3') }
38
37
  let(:tmpdir) { Stud::Temporary.directory }
39
38
 
40
39
  it 'extracts a full tarball' do
41
- entries = ['some/file', 'some/other/file', 'other' ]
40
+ entries = ['some/file', 'some/other/file', 'other']
42
41
 
43
42
  FileDependencies::Archive.untar(tarball) do |entry|
44
43
  ::File.join(tmpdir, entry.full_name)
@@ -57,7 +56,7 @@ describe FileDependencies::Archive do
57
56
  end
58
57
  end
59
58
  found_files = Dir.glob(File.join(tmpdir, '**', '*')).reject { |entry| File.directory?(entry) }.sort
60
- expected_files = entries.map { |k| "#{tmpdir}/#{k}" }.sort
59
+ expected_files = entries.map { |k| ::File.join(tmpdir, k) }.sort
61
60
  expect(expected_files).to(eq(found_files))
62
61
  end
63
62
 
@@ -72,36 +71,22 @@ describe FileDependencies::Archive do
72
71
 
73
72
  describe ".eval_file" do
74
73
 
75
- # Hack to implement the full_name part
76
- class ::String
77
- def full_name
78
- return self
79
- end
80
- end
81
-
82
- let(:entries) { [ 'sometar/PaxHeaders', 'sometar/some/dir/PaxHeaders', 'sometar/some/dir/somefile', 'sometar/somefile', 'sometar/some/other/file', 'sometar/some/jars/file1.jar', 'sometar/some/jars/file2.jar', 'sometar/other/jars/file3.jar' ]}
74
+ let(:entries) { ['sometar/PaxHeaders', 'sometar/some/dir/PaxHeaders', 'sometar/some/dir/somefile', 'sometar/somefile', 'sometar/some/other/file', 'sometar/some/jars/file1.jar', 'sometar/some/jars/file2.jar', 'sometar/other/jars/file3.jar'] }
83
75
  let(:prefix) { 'sometar' }
84
76
 
85
- let(:extract1) { '.jars' } #wildcard
86
- let(:expect1) { [ 'file1.jar', 'file2.jar', 'file3.jar'] }
87
- let(:extract2) { ['/some/other/file', '/somefile', '/other/jars/file3.jar' ]}
88
- let(:expect2) { ['file', 'somefile', 'file3.jar' ]}
89
- let(:extract3) { }
90
- let(:expect3) { [ '/some/dir/somefile', '/somefile', '/some/other/file', '/some/jars/file1.jar', '/some/jars/file2.jar', '/other/jars/file3.jar' ] }
77
+ let(:extract1) { '.jars' }
78
+ let(:expect1) { ['file1.jar', 'file2.jar', 'file3.jar'] }
79
+ let(:extract2) { ['/some/other/file', '/somefile', '/other/jars/file3.jar'] }
80
+ let(:expect2) { ['file', 'somefile', 'file3.jar'] }
91
81
 
92
82
  it 'returns all files based on a wildcard' do
93
- filelist = entries.map { |entry| FileDependencies::Archive.eval_file(entry, extract1, prefix) }
94
- expect(filelist.reject{ |v| v == false}.sort).to(eq(expect1.sort))
83
+ filelist = entries.reject { |entry| FileDependencies::Archive.eval_file(entry, extract1, prefix) == false }.map { |entry| entry.gsub(prefix, '').split("/").last }
84
+ expect(filelist.sort).to(eq(expect1.sort))
95
85
  end
96
86
 
97
87
  it 'returns all files based on an array' do
98
- filelist = entries.map { |entry| FileDependencies::Archive.eval_file(entry, extract2, prefix) }
99
- expect(filelist.reject{ |v| v == false}.sort).to(eq(expect2.sort))
100
- end
101
-
102
- it 'returns all files when no extracted files are given' do
103
- filelist = entries.map { |entry| FileDependencies::Archive.eval_file(entry, extract3, prefix) }
104
- expect(filelist.reject{ |v| v == false}.sort).to(eq(expect3.sort))
88
+ filelist = entries.reject { |entry| FileDependencies::Archive.eval_file(entry, extract2, prefix) == false }.map { |entry| entry.gsub(prefix, '').split("/").last }
89
+ expect(filelist.sort).to(eq(expect2.sort))
105
90
  end
106
91
 
107
92
  end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'tmpdir'
3
2
  require 'json'
4
3
  require 'file-dependencies'
5
4
 
@@ -16,10 +15,10 @@ describe FileDependencies do
16
15
  let(:tmpdir) { Stud::Temporary.directory }
17
16
  let(:target) { Stud::Temporary.directory }
18
17
 
19
- let(:file1) { Assist.generate_tarball({'some/file' => 'content1', 'some/other/file' => 'content2', 'other' => 'content3'}) }
18
+ let(:file1) { Assist.generate_tarball('some/file' => 'content1', 'some/other/file' => 'content2', 'other' => 'content3') }
20
19
  let(:file2) { Assist.generate_file('some_content') }
21
20
  let(:file3) { Assist.generate_gzip('some_content_for_gzip') }
22
- let(:file4) { Assist.generate_tarball({'jars/some.jar' => 'content10', 'jars/someother.jar' => 'content11'}) }
21
+ let(:file4) { Assist.generate_tarball('jars/some.jar' => 'content10', 'jars/someother.jar' => 'content11') }
23
22
 
24
23
  let(:sha1) { FileDependencies::File.calc_sha1(file1) }
25
24
  let(:sha2) { FileDependencies::File.calc_sha1(file2) }
@@ -33,7 +32,7 @@ describe FileDependencies do
33
32
 
34
33
  let(:entries) { ['somefile2.txt', 'somefile3', 'some/file', 'some/other/file', 'other', 'jars/some.jar', 'jars/someother.jar'] }
35
34
 
36
- let(:files) { [ { 'url' => url1, 'sha1' => sha1 }, { 'url' => url2, 'sha1' => sha2 }, { 'url' => url3, 'sha1' => sha3 }, { 'url' => url4, 'sha1' => sha4, 'extract' => '.jar', 'target' => 'jars' } ] }
35
+ let(:files) { [{ 'url' => url1, 'sha1' => sha1 }, { 'url' => url2, 'sha1' => sha2 }, { 'url' => url3, 'sha1' => sha3 }, { 'url' => url4, 'sha1' => sha4, 'extract' => '.jar', 'target' => 'jars' }] }
37
36
 
38
37
  it 'processes file list' do
39
38
  stub_request(:get, url1).to_return(:body => File.new(file1), :status => 200)
@@ -42,7 +41,7 @@ describe FileDependencies do
42
41
  stub_request(:get, url4).to_return(:body => File.new(file4), :status => 200)
43
42
 
44
43
  # we should not have any errors
45
- expect{ FileDependencies.download(files, target, tmpdir) }.to_not(raise_error)
44
+ expect { FileDependencies.download(files, target, tmpdir) }.to_not(raise_error)
46
45
 
47
46
  # check if we got all the expected files
48
47
  found_files = Dir.glob(File.join(target, '**', '*')).reject { |entry| File.directory?(entry) }.sort
@@ -62,10 +61,10 @@ describe FileDependencies do
62
61
  let(:tmpdir) { Stud::Temporary.directory }
63
62
  let(:target) { Stud::Temporary.directory }
64
63
 
65
- let(:file1) { Assist.generate_tarball({'some/file' => 'content1', 'some/other/file' => 'content2', 'other' => 'content3'}) }
64
+ let(:file1) { Assist.generate_tarball('some/file' => 'content1', 'some/other/file' => 'content2', 'other' => 'content3') }
66
65
  let(:file2) { Assist.generate_file('some_content') }
67
66
  let(:file3) { Assist.generate_gzip('some_content_for_gzip') }
68
- let(:file4) { Assist.generate_tarball({'jars/some.jar' => 'content10', 'jars/someother.jar' => 'content11'}) }
67
+ let(:file4) { Assist.generate_tarball('jars/some.jar' => 'content10', 'jars/someother.jar' => 'content11') }
69
68
 
70
69
  let(:sha1) { FileDependencies::File.calc_sha1(file1) }
71
70
  let(:sha2) { FileDependencies::File.calc_sha1(file2) }
@@ -77,7 +76,7 @@ describe FileDependencies do
77
76
  let(:url3) { 'http://www.example.com/somefile3.gz' }
78
77
  let(:url4) { 'http://www.example.com/somefile4.tar.gz' }
79
78
 
80
- let(:files) { [ { 'url' => url1, 'sha1' => sha1 }, { 'url' => url2, 'sha1' => sha2 }, { 'url' => url3, 'sha1' => sha3 }, { 'url' => url4, 'sha1' => sha4, 'extract' => '.jar', 'target' => 'jars' } ].to_json }
79
+ let(:files) { [{ 'url' => url1, 'sha1' => sha1 }, { 'url' => url2, 'sha1' => sha2 }, { 'url' => url3, 'sha1' => sha3 }, { 'url' => url4, 'sha1' => sha4, 'extract' => '.jar', 'target' => 'jars' }].to_json }
81
80
  let(:vendorfile) { File.write(File.join(target, 'vendor.json'), files) }
82
81
  let(:entries) { ['somefile2.txt', 'somefile3', 'some/file', 'some/other/file', 'other', 'jars/some.jar', 'jars/someother.jar'] }
83
82
 
@@ -89,7 +88,7 @@ describe FileDependencies do
89
88
  File.write(File.join(target, 'vendor.json'), files)
90
89
 
91
90
  # we should not have any errors
92
- expect{ FileDependencies.process_vendor(target, 'vendor', tmpdir) }.to_not(raise_error)
91
+ expect { FileDependencies.process_vendor(target, 'vendor', tmpdir) }.to_not(raise_error)
93
92
 
94
93
  # check if we got all the expected files
95
94
  found_files = Dir.glob(File.join(target, 'vendor', '**', '*')).reject { |entry| File.directory?(entry) }.sort
@@ -1,10 +1,8 @@
1
1
  require 'spec_helper'
2
- require 'tmpdir'
3
2
  require 'file-dependencies/file'
4
3
  include WebMock::API
5
4
  describe FileDependencies::File do
6
5
 
7
-
8
6
  describe ".calc_sha1" do
9
7
 
10
8
  after do
@@ -17,7 +15,7 @@ describe FileDependencies::File do
17
15
  end
18
16
 
19
17
  it 'raises an error when the file doesnt exist' do
20
- expect { FileDependencies::File.calc_sha1('dont_exist')}.to(raise_error(Errno::ENOENT))
18
+ expect { FileDependencies::File.calc_sha1('dont_exist') }.to(raise_error(Errno::ENOENT))
21
19
  end
22
20
  end
23
21
 
@@ -80,7 +78,7 @@ describe FileDependencies::File do
80
78
  describe ".fetch_sha1" do
81
79
 
82
80
  describe "With a sha1 string" do
83
- let (:remote_sha1) { '778164c23fae5935176254d2550619cba8abc262' }
81
+ let(:remote_sha1) { '778164c23fae5935176254d2550619cba8abc262' }
84
82
  it 'returns sha1 string when valid' do
85
83
  expect(FileDependencies::File.fetch_sha1(remote_sha1)).to(eq(remote_sha1))
86
84
  end
@@ -1,7 +1,7 @@
1
1
  require 'stud/temporary'
2
2
 
3
+ # :nodoc:
3
4
  module Assist
4
-
5
5
  def self.generate_tarball(files)
6
6
  tarpath = "#{Stud::Temporary.pathname}.tar.gz"
7
7
  tarfile = File.new(tarpath, "wb")
@@ -22,7 +22,6 @@ module Assist
22
22
  end
23
23
 
24
24
  def self.generate_gzip(content)
25
-
26
25
  file = "#{Stud::Temporary.pathname}.gz"
27
26
  Zlib::GzipWriter.open(file) do |gz|
28
27
  gz.write(content)
@@ -1,5 +1,10 @@
1
1
  require 'spec_assist'
2
2
  require 'webmock/rspec'
3
+ require 'coveralls'
4
+ require 'codeclimate-test-reporter'
5
+
6
+ CodeClimate::TestReporter.start
7
+ Coveralls.wear!
3
8
 
4
9
  RSpec.configure do |config|
5
10
  config.extend Assist
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: file-dependencies
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
  - Richard Pijnenburg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-13 00:00:00.000000000 Z
11
+ date: 2014-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitar
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: codeclimate-test-reporter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description: manage file dependencies for gems
84
112
  email:
85
113
  - richard.pijnenburg@elasticsearch.com
@@ -126,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
154
  version: '0'
127
155
  requirements: []
128
156
  rubyforge_project:
129
- rubygems_version: 2.4.2
157
+ rubygems_version: 2.4.5
130
158
  signing_key:
131
159
  specification_version: 4
132
160
  summary: manage file dependencies for gems