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 +8 -8
- data/file-dependencies.gemspec +2 -0
- data/lib/file-dependencies.rb +7 -3
- data/lib/file-dependencies/archive.rb +9 -10
- data/lib/file-dependencies/file.rb +3 -3
- data/lib/file-dependencies/version.rb +1 -1
- data/spec/archive_spec.rb +13 -28
- data/spec/file-dependencies_spec.rb +8 -9
- data/spec/file_spec.rb +2 -4
- data/spec/spec_assist.rb +1 -2
- data/spec/spec_helper.rb +5 -0
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGM4NTY0ZjEwMzliMWM1MTBiOGU3NzIyOTJhMGIyNDJhZTFiMmUzMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTdmYTQwODE1Y2ZiZTcxZWNiZWYwMmI2OGVkNjY0MjgwMTU1ZTRlYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2YzMGY5ZDY1ODZiOTA5M2NhMTY5ZGMyNmI4ZWY4ODFkNzllYTA1M2FjNWY5
|
10
|
+
ZTRjYTRhYzUyNWNhNmVkMWM2YmNlMWNkMzhkMjRhYWM3ODcwOGM1ZWJkNzll
|
11
|
+
MDQwNjVjZDRiMjQ4NDI2MGJkMTcxMjg4NDMxYjA3ZTQzYjU5YzU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGRmOWI2YjNjOGFjY2M1NGE1OWU5MGJkNTg0NjY0ZDhhZDlkMTlhZDc3ZmNh
|
14
|
+
ZTVlZjI2NjQyYzdmYmRjNDllYjJhZmNiYTYxNzBkYWNlNjI1YWY5YmI3MzQ4
|
15
|
+
ZmZkYjllMjI3MzFjM2RlNmFiOGY2ZjZjODI2ZTdmMTJkZDA2MjU=
|
data/file-dependencies.gemspec
CHANGED
@@ -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
|
data/lib/file-dependencies.rb
CHANGED
@@ -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'])
|
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
|
-
|
29
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
data/spec/archive_spec.rb
CHANGED
@@ -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(
|
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|
|
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
|
-
|
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' }
|
86
|
-
let(:expect1)
|
87
|
-
let(:extract2) { ['/some/other/file', '/somefile', '/other/jars/file3.jar'
|
88
|
-
let(:expect2)
|
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.
|
94
|
-
expect(filelist.
|
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.
|
99
|
-
expect(filelist.
|
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(
|
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(
|
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) { [
|
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(
|
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(
|
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) { [
|
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
|
data/spec/file_spec.rb
CHANGED
@@ -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
|
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
|
data/spec/spec_assist.rb
CHANGED
@@ -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)
|
data/spec/spec_helper.rb
CHANGED
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.
|
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-
|
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.
|
157
|
+
rubygems_version: 2.4.5
|
130
158
|
signing_key:
|
131
159
|
specification_version: 4
|
132
160
|
summary: manage file dependencies for gems
|