file-dependencies 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +1 -0
- data/file-dependencies.gemspec +1 -1
- data/lib/file-dependencies.rb +12 -12
- data/lib/file-dependencies/archive.rb +28 -6
- data/lib/file-dependencies/file.rb +3 -3
- data/lib/file-dependencies/version.rb +3 -1
- data/lib/{file-dependencies/rubygems_plugin.rb → rubygems_plugin.rb} +0 -0
- data/spec/file-dependencies/archive_spec.rb +138 -0
- data/spec/{file_spec.rb → file-dependencies/file_spec.rb} +3 -3
- data/spec/file-dependencies_spec.rb +25 -16
- metadata +5 -5
- data/spec/archive_spec.rb +0 -94
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGVkNDBkYmY4NWM4N2UxOTRiODhiM2QwN2QwZGM2ZjEwM2Q4YzFiZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmZjNmFlMWU3YWFiOGYwNWU4NjM0ZWI0Yjc5Y2U1YjBlM2JkNjlkYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWJlMmU3NmI5OTdiNTUxNjQ3Y2E2NWZjMzE0YWYwNjQxMTNlZGJkM2E1YjIw
|
10
|
+
MzdiN2IyN2Q2Y2YxNTVhNDAzODU4MWY0ZTNjZDVkZDcxNDY2NTFiZmEzMjEx
|
11
|
+
ZjAxMjY4YWQ4YzU2ZTBkZDRjZWU3MjUxMDY0YmNjMmM1ZTAyNDg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGMxMDlmMzg0MTgzNjVlYjQxM2Q0MjI1YjE4OWUzNjU4ZWQ0MGI1YjkwYTA5
|
14
|
+
NGVmMzg1MjYxYTZmNDBjYjk1YjMwZmI0MTZiMzEzMDA0MGFiNmVlY2UxMGIw
|
15
|
+
OWVlMjZlMzg5NmU0NWNmNTUwNGM5OTcwNzE0NGNlZWJiYmQ3Mzk=
|
data/.gitignore
CHANGED
data/file-dependencies.gemspec
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('../lib/file-dependencies/version', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'file-dependencies'
|
6
|
-
s.version =
|
6
|
+
s.version = FileDependencies::VERSION
|
7
7
|
s.author = 'Richard Pijnenburg'
|
8
8
|
s.email = ['richard.pijnenburg@elasticsearch.com']
|
9
9
|
s.summary = 'manage file dependencies for gems'
|
data/lib/file-dependencies.rb
CHANGED
@@ -10,34 +10,34 @@ module FileDependencies
|
|
10
10
|
if ::File.exist?(vendor_file)
|
11
11
|
vendor_file_content = IO.read(vendor_file)
|
12
12
|
file_list = JSON.load(vendor_file_content)
|
13
|
-
FileDependencies.
|
13
|
+
FileDependencies.process_downloads(file_list, ::File.join(dir, target), tmpdir)
|
14
14
|
else
|
15
15
|
puts "vendor.json not found, looked for the file at #{vendor_file}"
|
16
16
|
end
|
17
17
|
end # def process_vendor
|
18
18
|
module_function :process_vendor
|
19
19
|
|
20
|
-
def
|
20
|
+
def process_downloads(files, target, tmpdir)
|
21
21
|
FileUtils.mkdir_p(target) unless ::File.directory?(target)
|
22
22
|
files.each do |file|
|
23
|
-
|
23
|
+
full_target = file['target'] ? ::File.join(target, file['target']) : target
|
24
24
|
download = FileDependencies::File.fetch_file(file['url'], file['sha1'], tmpdir)
|
25
|
-
if (res = download.match(/(\S+?)(\.tar\.gz|\.tgz)
|
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
|
+
next unless FileDependencies::Archive.extract_file?(entry.full_name, file['extract'], file['exclude'], prefix)
|
29
|
+
if file['flatten'] == true
|
30
|
+
::File.join(full_target, entry.full_name.split("/").last)
|
30
31
|
else
|
31
|
-
|
32
|
-
::File.join(target, entry.full_name.split("/").last)
|
32
|
+
::File.join(full_target, entry.full_name.gsub(prefix, ''))
|
33
33
|
end
|
34
34
|
end
|
35
|
-
elsif download =~ /.gz
|
36
|
-
FileDependencies::Archive.ungzip(download,
|
35
|
+
elsif download =~ /.gz$/
|
36
|
+
FileDependencies::Archive.ungzip(download, full_target)
|
37
37
|
else
|
38
|
-
FileUtils.mv(download, ::File.join(
|
38
|
+
FileUtils.mv(download, ::File.join(full_target, download.split("/").last))
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end # def download
|
42
|
-
module_function :
|
42
|
+
module_function :process_downloads
|
43
43
|
end
|
@@ -64,20 +64,42 @@ module FileDependencies
|
|
64
64
|
end # def untar
|
65
65
|
module_function :untar
|
66
66
|
|
67
|
-
def
|
67
|
+
def extract_file?(entry, extract=nil, exclude=nil, prefix)
|
68
|
+
return true if extract.nil? && exclude.nil?
|
68
69
|
return false if tar_header?(entry)
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
|
71
|
+
if extract
|
72
|
+
return match?(entry, extract, prefix)
|
73
|
+
elsif exclude
|
74
|
+
return !match?(entry, exclude, prefix)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
module_function :extract_file?
|
78
|
+
|
79
|
+
def match?(entry, list, prefix)
|
80
|
+
return false if list.nil?
|
81
|
+
|
82
|
+
if list.is_a?(Array)
|
83
|
+
list.each do |pattern|
|
84
|
+
if pattern.is_a?(Regexp) or regexp_string?(pattern)
|
85
|
+
return true if entry =~ Regexp.new(pattern)
|
86
|
+
elsif pattern.is_a?(String)
|
87
|
+
return true if pattern == entry.gsub(prefix, '')
|
88
|
+
end
|
89
|
+
end
|
73
90
|
end
|
74
91
|
false
|
75
92
|
end
|
76
|
-
module_function :
|
93
|
+
module_function :match?
|
77
94
|
|
78
95
|
def tar_header?(entry)
|
79
96
|
entry =~ /PaxHeaders/
|
80
97
|
end
|
81
98
|
module_function :tar_header?
|
99
|
+
|
100
|
+
def regexp_string?(pattern)
|
101
|
+
pattern.to_s.match('^\(\?-mix:.+\)$')
|
102
|
+
end
|
103
|
+
module_function :regexp_string?
|
82
104
|
end
|
83
105
|
end
|
@@ -24,17 +24,17 @@ module FileDependencies
|
|
24
24
|
def validate_sha1(local_file, remote_sha1)
|
25
25
|
return true if remote_sha1 == 'none'
|
26
26
|
sha1 = fetch_sha1(remote_sha1)
|
27
|
-
local_sha1 =
|
27
|
+
local_sha1 = calculate_sha1(local_file)
|
28
28
|
|
29
29
|
raise("SHA1 did not match. Expected #{sha1} but computed #{local_sha1}") if sha1 != local_sha1
|
30
30
|
true
|
31
31
|
end # def validate_sha1
|
32
32
|
module_function :validate_sha1
|
33
33
|
|
34
|
-
def
|
34
|
+
def calculate_sha1(path)
|
35
35
|
Digest::SHA1.file(path).hexdigest
|
36
36
|
end # def calc__sha1
|
37
|
-
module_function :
|
37
|
+
module_function :calculate_sha1
|
38
38
|
|
39
39
|
def fetch_file(url, sha1, target)
|
40
40
|
puts "Downloading #{url}" if $DEBUG
|
File without changes
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'file-dependencies/archive'
|
3
|
+
|
4
|
+
describe FileDependencies::Archive do
|
5
|
+
|
6
|
+
describe ".ungzip" do
|
7
|
+
|
8
|
+
after do
|
9
|
+
FileUtils.remove_entry_secure(gzipfile) if ::File.exist?(gzipfile)
|
10
|
+
FileUtils.remove_entry_secure(expected_file)
|
11
|
+
FileUtils.remove_entry_secure(tmpdir)
|
12
|
+
end
|
13
|
+
let(:gzipfile) { Assist.generate_gzip('some_content') }
|
14
|
+
let(:expected_file) { gzipfile.gsub('.gz', '') }
|
15
|
+
let(:tmpdir) { Stud::Temporary.directory }
|
16
|
+
|
17
|
+
it 'decompresses a gzip file'do
|
18
|
+
expect { FileDependencies::Archive.ungzip(gzipfile, tmpdir) }.to_not(raise_error)
|
19
|
+
expect(File.exist?(expected_file))
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:expected_file) { Assist.generate_file('some_content') }
|
23
|
+
it 'raises error extracting non gzip file' do
|
24
|
+
expect { FileDependencies::Archive.ungzip(expected_file, tmpdir) }.to(raise_error(Zlib::GzipFile::Error))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe ".untar" do
|
29
|
+
|
30
|
+
after do
|
31
|
+
FileUtils.remove_entry_secure(tmpdir)
|
32
|
+
FileUtils.remove_entry_secure(file)
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:file) { Assist.generate_file('some_content') }
|
36
|
+
let(:tarball) { Assist.generate_tarball('some/file' => 'content1', 'some/other/file' => 'content2', 'other' => 'content3') }
|
37
|
+
let(:tmpdir) { Stud::Temporary.directory }
|
38
|
+
|
39
|
+
it 'extracts a full tarball' do
|
40
|
+
entries = ['some/file', 'some/other/file', 'other']
|
41
|
+
|
42
|
+
FileDependencies::Archive.untar(tarball) do |entry|
|
43
|
+
::File.join(tmpdir, entry.full_name)
|
44
|
+
end
|
45
|
+
found_files = Dir.glob(File.join(tmpdir, '**', '*')).reject { |entry| File.directory?(entry) }.sort
|
46
|
+
expected_files = entries.map { |k| ::File.join(tmpdir, k) }.sort
|
47
|
+
expect(expected_files).to(eq(found_files))
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'extracts some files' do
|
51
|
+
entries = ['some/file', 'some/other/file']
|
52
|
+
|
53
|
+
FileDependencies::Archive.untar(tarball) do |entry|
|
54
|
+
if entries.include?(entry.full_name)
|
55
|
+
::File.join(tmpdir, entry.full_name)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
found_files = Dir.glob(File.join(tmpdir, '**', '*')).reject { |entry| File.directory?(entry) }.sort
|
59
|
+
expected_files = entries.map { |k| ::File.join(tmpdir, k) }.sort
|
60
|
+
expect(expected_files).to(eq(found_files))
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'raises error when invalid file is provided' do
|
64
|
+
expect do
|
65
|
+
FileDependencies::Archive.untar(file) do |entry|
|
66
|
+
::File.join(tmpdir, entry.full_name)
|
67
|
+
end
|
68
|
+
end.to(raise_error(Zlib::GzipFile::Error))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe ".extract_file?" do
|
73
|
+
|
74
|
+
describe "with extract" do
|
75
|
+
|
76
|
+
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'] }
|
77
|
+
let(:prefix) { 'sometar' }
|
78
|
+
|
79
|
+
it 'returns all files based on a regex' do
|
80
|
+
extract1 = [/.jar/]
|
81
|
+
expect1 = ['file1.jar', 'file2.jar', 'file3.jar']
|
82
|
+
|
83
|
+
filelist = entries.reject { |entry| FileDependencies::Archive.extract_file?(entry, extract1, '', prefix) == false }.map { |entry| entry.gsub(prefix, '').split("/").last }
|
84
|
+
expect(filelist.sort).to(eq(expect1.sort))
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns all files based on an array' do
|
88
|
+
extract2 = ['/some/other/file', '/somefile', '/other/jars/file3.jar']
|
89
|
+
expect2 = ['file', 'somefile', 'file3.jar']
|
90
|
+
|
91
|
+
filelist = entries.reject { |entry| FileDependencies::Archive.extract_file?(entry, extract2, '', prefix) == false }.map { |entry| entry.gsub(prefix, '').split("/").last }
|
92
|
+
expect(filelist.sort).to(eq(expect2.sort))
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'returns all files from directories' do
|
96
|
+
extract3 = [/\/some\/jars/, /^sometar\/other/]
|
97
|
+
expect3 = ['file1.jar', 'file2.jar', 'file3.jar']
|
98
|
+
|
99
|
+
filelist = entries.reject { |entry| FileDependencies::Archive.extract_file?(entry, extract3, '', prefix) == false }.map { |entry| entry.gsub(prefix, '').split("/").last }
|
100
|
+
expect(filelist.sort).to(eq(expect3.sort))
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "with exclude" do
|
106
|
+
|
107
|
+
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'] }
|
108
|
+
let(:prefix) { 'sometar' }
|
109
|
+
|
110
|
+
it 'returns all non matching files based on a regex' do
|
111
|
+
extract1 = [/.jar/]
|
112
|
+
expect1 = ["file", "somefile", "somefile"]
|
113
|
+
|
114
|
+
filelist = entries.reject { |entry| FileDependencies::Archive.extract_file?(entry, nil, extract1, prefix) == false }.map { |entry| entry.gsub(prefix, '').split("/").last }
|
115
|
+
expect(filelist.sort).to(eq(expect1.sort))
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'returns all non matching files based on an array' do
|
119
|
+
extract2 = ['/some/other/file', '/somefile', '/other/jars/file3.jar']
|
120
|
+
expect2 = ['file1.jar', 'file2.jar', 'somefile']
|
121
|
+
|
122
|
+
filelist = entries.reject { |entry| FileDependencies::Archive.extract_file?(entry, nil, extract2, prefix) == false }.map { |entry| entry.gsub(prefix, '').split("/").last }
|
123
|
+
expect(filelist.sort).to(eq(expect2.sort))
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'returns all except the directories' do
|
127
|
+
extract3 = [/^sometar\/some\/jars/, /^sometar\/other/]
|
128
|
+
expect3 = ['somefile', 'somefile', 'file']
|
129
|
+
|
130
|
+
filelist = entries.reject { |entry| FileDependencies::Archive.extract_file?(entry, nil, extract3, prefix) == false }.map { |entry| entry.gsub(prefix, '').split("/").last }
|
131
|
+
expect(filelist.sort).to(eq(expect3.sort))
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
@@ -3,7 +3,7 @@ require 'file-dependencies/file'
|
|
3
3
|
include WebMock::API
|
4
4
|
describe FileDependencies::File do
|
5
5
|
|
6
|
-
describe ".
|
6
|
+
describe ".calculate_sha1" do
|
7
7
|
|
8
8
|
after do
|
9
9
|
::File.unlink(file)
|
@@ -11,11 +11,11 @@ describe FileDependencies::File do
|
|
11
11
|
|
12
12
|
let(:file) { Assist.generate_file('some_content') }
|
13
13
|
it 'gives back correct sha1 value' do
|
14
|
-
expect(FileDependencies::File.
|
14
|
+
expect(FileDependencies::File.calculate_sha1(file)).to(eq('778164c23fae5935176254d2550619cba8abc262'))
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'raises an error when the file doesnt exist' do
|
18
|
-
expect { FileDependencies::File.
|
18
|
+
expect { FileDependencies::File.calculate_sha1('dont_exist') }.to(raise_error(Errno::ENOENT))
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -5,7 +5,7 @@ require 'file-dependencies'
|
|
5
5
|
include WebMock::API
|
6
6
|
describe FileDependencies do
|
7
7
|
|
8
|
-
describe '.
|
8
|
+
describe '.process_downloads' do
|
9
9
|
after do
|
10
10
|
[tmpdir, target, file1, file2, file3, file4].each do |entry|
|
11
11
|
FileUtils.remove_entry_secure(entry)
|
@@ -18,30 +18,34 @@ describe FileDependencies do
|
|
18
18
|
let(:file1) { Assist.generate_tarball('some/file' => 'content1', 'some/other/file' => 'content2', 'other' => 'content3') }
|
19
19
|
let(:file2) { Assist.generate_file('some_content') }
|
20
20
|
let(:file3) { Assist.generate_gzip('some_content_for_gzip') }
|
21
|
-
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', 'somefile.txt' => 'bla') }
|
22
|
+
let(:file5) { Assist.generate_tarball('src/types.db' => 'typesdb') }
|
22
23
|
|
23
|
-
let(:sha1) { FileDependencies::File.
|
24
|
-
let(:sha2) { FileDependencies::File.
|
25
|
-
let(:sha3) { FileDependencies::File.
|
26
|
-
let(:sha4) { FileDependencies::File.
|
24
|
+
let(:sha1) { FileDependencies::File.calculate_sha1(file1) }
|
25
|
+
let(:sha2) { FileDependencies::File.calculate_sha1(file2) }
|
26
|
+
let(:sha3) { FileDependencies::File.calculate_sha1(file3) }
|
27
|
+
let(:sha4) { FileDependencies::File.calculate_sha1(file4) }
|
28
|
+
let(:sha5) { FileDependencies::File.calculate_sha1(file5) }
|
27
29
|
|
28
30
|
let(:url1) { 'http://www.example.com/somefile1.tar.gz' }
|
29
31
|
let(:url2) { 'http://www.example.com/somefile2.txt' }
|
30
32
|
let(:url3) { 'http://www.example.com/somefile3.gz' }
|
31
33
|
let(:url4) { 'http://www.example.com/somefile4.tar.gz' }
|
34
|
+
let(:url5) { 'http://www.example.com/somefile5.tar.gz' }
|
32
35
|
|
33
|
-
let(:entries) { ['somefile2.txt', 'somefile3', 'some/file', 'some/other/file', 'other', 'jars/some.jar', 'jars/someother.jar'] }
|
36
|
+
let(:entries) { ['somefile2.txt', 'somefile3', 'some/file', 'some/other/file', 'other', 'jarfiles/jars/some.jar', 'jarfiles/jars/someother.jar', 'jarfiles/somefile.txt', 'types.db'] }
|
34
37
|
|
35
|
-
let(:files) { [{ 'url' => url1, 'sha1' => sha1 }, { 'url' => url2, 'sha1' => sha2 }, { 'url' => url3, 'sha1' => sha3 }, { 'url' => url4, 'sha1' => sha4, 'extract' =>
|
38
|
+
let(:files) { [{ 'url' => url1, 'sha1' => sha1 }, { 'url' => url2, 'sha1' => sha2 }, { 'url' => url3, 'sha1' => sha3 }, { 'url' => url4, 'sha1' => sha4, 'extract' => [/\.jar/, /\.txt/], 'target' => 'jarfiles' }, { 'url' => url5, 'sha1' => sha5, 'flatten' => true }] }
|
36
39
|
|
37
40
|
it 'processes file list' do
|
38
41
|
stub_request(:get, url1).to_return(:body => File.new(file1), :status => 200)
|
39
42
|
stub_request(:get, url2).to_return(:body => File.new(file2), :status => 200)
|
40
43
|
stub_request(:get, url3).to_return(:body => File.new(file3), :status => 200)
|
41
44
|
stub_request(:get, url4).to_return(:body => File.new(file4), :status => 200)
|
45
|
+
stub_request(:get, url5).to_return(:body => File.new(file5), :status => 200)
|
42
46
|
|
43
47
|
# we should not have any errors
|
44
|
-
expect { FileDependencies.
|
48
|
+
expect { FileDependencies.process_downloads(files, target, tmpdir) }.to_not(raise_error)
|
45
49
|
|
46
50
|
# check if we got all the expected files
|
47
51
|
found_files = Dir.glob(File.join(target, '**', '*')).reject { |entry| File.directory?(entry) }.sort
|
@@ -64,27 +68,32 @@ describe FileDependencies do
|
|
64
68
|
let(:file1) { Assist.generate_tarball('some/file' => 'content1', 'some/other/file' => 'content2', 'other' => 'content3') }
|
65
69
|
let(:file2) { Assist.generate_file('some_content') }
|
66
70
|
let(:file3) { Assist.generate_gzip('some_content_for_gzip') }
|
67
|
-
let(:file4) { Assist.generate_tarball('jars/some.jar' => 'content10', 'jars/someother.jar' => 'content11') }
|
71
|
+
let(:file4) { Assist.generate_tarball('jars/some.jar' => 'content10', 'jars/someother.jar' => 'content11', 'somefile.txt' => 'bla') }
|
72
|
+
let(:file5) { Assist.generate_tarball('src/types.db' => 'typesdb') }
|
68
73
|
|
69
|
-
let(:sha1) { FileDependencies::File.
|
70
|
-
let(:sha2) { FileDependencies::File.
|
71
|
-
let(:sha3) { FileDependencies::File.
|
72
|
-
let(:sha4) { FileDependencies::File.
|
74
|
+
let(:sha1) { FileDependencies::File.calculate_sha1(file1) }
|
75
|
+
let(:sha2) { FileDependencies::File.calculate_sha1(file2) }
|
76
|
+
let(:sha3) { FileDependencies::File.calculate_sha1(file3) }
|
77
|
+
let(:sha4) { FileDependencies::File.calculate_sha1(file4) }
|
78
|
+
let(:sha5) { FileDependencies::File.calculate_sha1(file5) }
|
73
79
|
|
74
80
|
let(:url1) { 'http://www.example.com/somefile1.tar.gz' }
|
75
81
|
let(:url2) { 'http://www.example.com/somefile2.txt' }
|
76
82
|
let(:url3) { 'http://www.example.com/somefile3.gz' }
|
77
83
|
let(:url4) { 'http://www.example.com/somefile4.tar.gz' }
|
84
|
+
let(:url5) { 'http://www.example.com/somefile5.tar.gz' }
|
85
|
+
|
86
|
+
let(:files) { [{ 'url' => url1, 'sha1' => sha1 }, { 'url' => url2, 'sha1' => sha2 }, { 'url' => url3, 'sha1' => sha3 }, { 'url' => url4, 'sha1' => sha4, 'extract' => [/\.jar/, /\.txt/], 'target' => 'jarfiles' }, { 'url' => url5, 'sha1' => sha5, 'flatten' => true }].to_json }
|
78
87
|
|
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 }
|
80
88
|
let(:vendorfile) { File.write(File.join(target, 'vendor.json'), files) }
|
81
|
-
let(:entries) { ['somefile2.txt', 'somefile3', 'some/file', 'some/other/file', 'other', 'jars/some.jar', 'jars/someother.jar'] }
|
89
|
+
let(:entries) { ['somefile2.txt', 'somefile3', 'some/file', 'some/other/file', 'other', 'jarfiles/jars/some.jar', 'jarfiles/jars/someother.jar', 'jarfiles/somefile.txt', 'types.db'] }
|
82
90
|
|
83
91
|
it 'processes the vendor.json file' do
|
84
92
|
stub_request(:get, url1).to_return(:body => File.new(file1), :status => 200)
|
85
93
|
stub_request(:get, url2).to_return(:body => File.new(file2), :status => 200)
|
86
94
|
stub_request(:get, url3).to_return(:body => File.new(file3), :status => 200)
|
87
95
|
stub_request(:get, url4).to_return(:body => File.new(file4), :status => 200)
|
96
|
+
stub_request(:get, url5).to_return(:body => File.new(file5), :status => 200)
|
88
97
|
File.write(File.join(target, 'vendor.json'), files)
|
89
98
|
|
90
99
|
# we should not have any errors
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Pijnenburg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitar
|
@@ -127,11 +127,11 @@ files:
|
|
127
127
|
- lib/file-dependencies/file.rb
|
128
128
|
- lib/file-dependencies/gem.rb
|
129
129
|
- lib/file-dependencies/rake_tasks.rb
|
130
|
-
- lib/file-dependencies/rubygems_plugin.rb
|
131
130
|
- lib/file-dependencies/version.rb
|
132
|
-
-
|
131
|
+
- lib/rubygems_plugin.rb
|
132
|
+
- spec/file-dependencies/archive_spec.rb
|
133
|
+
- spec/file-dependencies/file_spec.rb
|
133
134
|
- spec/file-dependencies_spec.rb
|
134
|
-
- spec/file_spec.rb
|
135
135
|
- spec/spec_assist.rb
|
136
136
|
- spec/spec_helper.rb
|
137
137
|
homepage: https://github.com/electrical/file-dependencies
|
data/spec/archive_spec.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'file-dependencies/archive'
|
3
|
-
|
4
|
-
describe FileDependencies::Archive do
|
5
|
-
|
6
|
-
describe ".ungzip" do
|
7
|
-
|
8
|
-
after do
|
9
|
-
FileUtils.remove_entry_secure(gzipfile) if ::File.exist?(gzipfile)
|
10
|
-
FileUtils.remove_entry_secure(expected_file)
|
11
|
-
FileUtils.remove_entry_secure(tmpdir)
|
12
|
-
end
|
13
|
-
let(:gzipfile) { Assist.generate_gzip('some_content') }
|
14
|
-
let(:expected_file) { gzipfile.gsub('.gz', '') }
|
15
|
-
let(:tmpdir) { Stud::Temporary.directory }
|
16
|
-
|
17
|
-
it 'decompresses a gzip file'do
|
18
|
-
expect { FileDependencies::Archive.ungzip(gzipfile, tmpdir) }.to_not(raise_error)
|
19
|
-
expect(File.exist?(expected_file))
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:expected_file) { Assist.generate_file('some_content') }
|
23
|
-
it 'raises error extracting non gzip file' do
|
24
|
-
expect { FileDependencies::Archive.ungzip(expected_file, tmpdir) }.to(raise_error(Zlib::GzipFile::Error))
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe ".untar" do
|
29
|
-
|
30
|
-
after do
|
31
|
-
FileUtils.remove_entry_secure(tmpdir)
|
32
|
-
FileUtils.remove_entry_secure(file)
|
33
|
-
end
|
34
|
-
|
35
|
-
let(:file) { Assist.generate_file('some_content') }
|
36
|
-
let(:tarball) { Assist.generate_tarball('some/file' => 'content1', 'some/other/file' => 'content2', 'other' => 'content3') }
|
37
|
-
let(:tmpdir) { Stud::Temporary.directory }
|
38
|
-
|
39
|
-
it 'extracts a full tarball' do
|
40
|
-
entries = ['some/file', 'some/other/file', 'other']
|
41
|
-
|
42
|
-
FileDependencies::Archive.untar(tarball) do |entry|
|
43
|
-
::File.join(tmpdir, entry.full_name)
|
44
|
-
end
|
45
|
-
found_files = Dir.glob(File.join(tmpdir, '**', '*')).reject { |entry| File.directory?(entry) }.sort
|
46
|
-
expected_files = entries.map { |k| ::File.join(tmpdir, k) }.sort
|
47
|
-
expect(expected_files).to(eq(found_files))
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'extracts some files' do
|
51
|
-
entries = ['some/file', 'some/other/file']
|
52
|
-
|
53
|
-
FileDependencies::Archive.untar(tarball) do |entry|
|
54
|
-
if entries.include?(entry.full_name)
|
55
|
-
::File.join(tmpdir, entry.full_name)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
found_files = Dir.glob(File.join(tmpdir, '**', '*')).reject { |entry| File.directory?(entry) }.sort
|
59
|
-
expected_files = entries.map { |k| ::File.join(tmpdir, k) }.sort
|
60
|
-
expect(expected_files).to(eq(found_files))
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'raises error when invalid file is provided' do
|
64
|
-
expect do
|
65
|
-
FileDependencies::Archive.untar(file) do |entry|
|
66
|
-
::File.join(tmpdir, entry.full_name)
|
67
|
-
end
|
68
|
-
end.to(raise_error(Zlib::GzipFile::Error))
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe ".eval_file" do
|
73
|
-
|
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'] }
|
75
|
-
let(:prefix) { 'sometar' }
|
76
|
-
|
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'] }
|
81
|
-
|
82
|
-
it 'returns all files based on a wildcard' do
|
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))
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'returns all files based on an array' do
|
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))
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|