zip_content_comparator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +10 -0
- data/.gitignore +1 -0
- data/LICENSE +22 -0
- data/README.rdoc +30 -0
- data/Rakefile +73 -0
- data/VERSION +1 -0
- data/lib/zip_content_comparator.rb +137 -0
- data/nbproject/project.properties +10 -0
- data/nbproject/project.xml +17 -0
- data/test/data/zip_content_comparator/identical_to_reference_test_file.zip +0 -0
- data/test/data/zip_content_comparator/modified_class_file.zip +0 -0
- data/test/data/zip_content_comparator/one_file_added.zip +0 -0
- data/test/data/zip_content_comparator/one_file_added_deleted_and_changed.zip +0 -0
- data/test/data/zip_content_comparator/one_file_changed.zip +0 -0
- data/test/data/zip_content_comparator/one_file_deleted.zip +0 -0
- data/test/data/zip_content_comparator/reference_test_file.zip +0 -0
- data/test/test_suite.rb +5 -0
- data/test/test_zip_content_comparator.rb +136 -0
- data/zip_content_comparator.gemspec +67 -0
- metadata +100 -0
data/.autotest
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# configuration file for autotest from ZenTest
|
3
|
+
|
4
|
+
#require 'test_notifier/runner/autotest' # gem install test_notifier
|
5
|
+
begin
|
6
|
+
require 'test_notifier/autotest' # gem install test_notifier -v 0.1.4
|
7
|
+
rescue LoadError
|
8
|
+
puts "Test Notifier (or a dependency) not available. Install it with: gem install test_notifier -v 0.1.4"
|
9
|
+
end
|
10
|
+
# Autotest::TestNotifier.preferred_notification_system = 'osd_cat'
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
nbproject/private
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2009 Szymon Jeż
|
2
|
+
|
3
|
+
MIT license
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
= Zip File Content Comparator
|
2
|
+
An utility for comparing content of ZIP files.
|
3
|
+
It does not extract the files anywhere, its's using instead ZIP::ZipFile class
|
4
|
+
from rubyzip gem which enables to access ZIP files like a file system.
|
5
|
+
It uses MD5 to compare files.
|
6
|
+
|
7
|
+
== Use Case
|
8
|
+
It was written to compare JAR files to determine if it is necessary to
|
9
|
+
deploy (upload) them to a Java Webstart directory. Specific files, which changed
|
10
|
+
every build, contained in JAR files where ignored, which allowed to spot JAR files
|
11
|
+
which are the same for the end user and chose not to deploy them. This saved the
|
12
|
+
end user some downloading and reduced the server load.
|
13
|
+
|
14
|
+
For more info see documentation for #compare and #identical? methods.
|
15
|
+
|
16
|
+
== Example:
|
17
|
+
# using the #compare method:
|
18
|
+
identical_files, different_files = ZipContentComparator.compare('old_build/myapp.jar','new_build/myapp.jar')
|
19
|
+
list_of_changed_class_files = different_files.detect{ |file| file =~ /.class$/ } || []
|
20
|
+
# using the #identical? method:
|
21
|
+
ZipContentComparator.identical?('old_build/myapp.jar','new_build/myapp.jar', :detect_pattern => /.class$/)
|
22
|
+
|
23
|
+
See the source code if you want to use other methods of this class.
|
24
|
+
|
25
|
+
Author:: Szymon (jeznet) Jeż <szymon[at]jez[dot]net[dot]pl>
|
26
|
+
|
27
|
+
== Hints
|
28
|
+
- To generate the documentation for this project use: rake rdoc
|
29
|
+
- All test files which have real test should be included in the test_suite.rb file
|
30
|
+
- The test_suite.rb is the default Test suite and is tested in `rake test` command
|
data/Rakefile
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "zip_content_comparator"
|
9
|
+
gem.summary = %Q{An utility for comparing content of ZIP files.}
|
10
|
+
gem.description = <<-TEXT
|
11
|
+
An utility for comparing content of ZIP files.
|
12
|
+
It does not extract the files anywhere, its's using instead ZIP::ZipFile class
|
13
|
+
from rubyzip gem which enables to access ZIP files like a file system.
|
14
|
+
It uses MD5 to compare files.
|
15
|
+
TEXT
|
16
|
+
gem.email = "szymon@jez.net.pl"
|
17
|
+
gem.homepage = "http://github.com/jeznet/zip_content_comparator"
|
18
|
+
gem.authors = ["Szymon (jeznet) Jeż"]
|
19
|
+
gem.add_dependency('rubyzip', '>= 0.9.1')
|
20
|
+
# gem.requirements << ''
|
21
|
+
# gem.add_development_dependency "thoughtbot-shoulda"
|
22
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for additional settings
|
23
|
+
end
|
24
|
+
rescue LoadError
|
25
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
# test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.test_files = FileList['test/**/*suite.rb']
|
33
|
+
test.verbose = true
|
34
|
+
# require 'test_notifier/test_unit'
|
35
|
+
end
|
36
|
+
|
37
|
+
begin
|
38
|
+
require 'rcov/rcovtask'
|
39
|
+
Rcov::RcovTask.new do |test|
|
40
|
+
test.libs << 'test'
|
41
|
+
test.pattern = 'test/**/*_test.rb'
|
42
|
+
test.verbose = true
|
43
|
+
end
|
44
|
+
rescue LoadError
|
45
|
+
task :rcov do
|
46
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
task :test => :check_dependencies
|
51
|
+
|
52
|
+
task :default => :test
|
53
|
+
|
54
|
+
require 'rake/rdoctask'
|
55
|
+
Rake::RDocTask.new do |rdoc|
|
56
|
+
if File.exist?('VERSION')
|
57
|
+
version = File.read('VERSION')
|
58
|
+
else
|
59
|
+
version = ""
|
60
|
+
end
|
61
|
+
|
62
|
+
rdoc.rdoc_dir = 'rdoc'
|
63
|
+
files =['README.rdoc', 'LICENSE', 'lib/**/*.rb']
|
64
|
+
rdoc.rdoc_files.add(files)
|
65
|
+
rdoc.main = "README" # page to start on
|
66
|
+
rdoc.title = "Zip File Content Comparator #{version}"
|
67
|
+
rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
|
68
|
+
rdoc.options << '--line-numbers'
|
69
|
+
rdoc.options << '--charset=utf-8'
|
70
|
+
end
|
71
|
+
|
72
|
+
# load tasks
|
73
|
+
Dir['tasks/**/*.rake'].each { |rake| load rake }
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,137 @@
|
|
1
|
+
#!/usr/bin/env -w ruby
|
2
|
+
begin
|
3
|
+
require 'rubygems'
|
4
|
+
require 'zip/zipfilesystem' # from gem: rubyzip
|
5
|
+
require 'md5'
|
6
|
+
rescue LoadError => e
|
7
|
+
$stderr.puts <<-STR
|
8
|
+
Problem loading gems. Please check if you have:
|
9
|
+
* rubygems (gem),
|
10
|
+
* rubyzip (gem),
|
11
|
+
* md5 (library),
|
12
|
+
in your load paths installed.
|
13
|
+
STR
|
14
|
+
$stderr.puts e
|
15
|
+
exit!
|
16
|
+
end
|
17
|
+
|
18
|
+
# == Zip File Content Comparator
|
19
|
+
# An utility for comparing content of ZIP files.
|
20
|
+
#
|
21
|
+
# It does not extract the files anywhere, its's using instead ZIP::ZipFile class
|
22
|
+
# from RubyGem: rubyzip which enables to access ZIP files like a file system.
|
23
|
+
# It uses MD5 to compare files.
|
24
|
+
# For more info see documentation for #compare and #identical? methods.
|
25
|
+
#
|
26
|
+
# === Example:
|
27
|
+
# # using the #compare method:
|
28
|
+
# identical_files, different_files = ZipContentComparator.compare('old_build/myapp.jar','new_build/myapp.jar')
|
29
|
+
# list_of_changed_class_files = different_files.detect{ |file| file =~ /.class$/ } || []
|
30
|
+
# # using the #identical? method:
|
31
|
+
# ZipContentComparator.identical?('old_build/myapp.jar','new_build/myapp.jar', :detect_pattern => /.class$/)
|
32
|
+
#
|
33
|
+
# See the source code if you want to use other methods of this class.
|
34
|
+
#
|
35
|
+
# Author:: Szymon (jeznet) Jeż <szymon@jez.net.pl>
|
36
|
+
class ZipContentComparator
|
37
|
+
def self.read_in_files(path_to_zipfile1, path_to_zipfile2)
|
38
|
+
zip_file1 = Zip::ZipFile.open(path_to_zipfile1) #{
|
39
|
+
zip_file2 = Zip::ZipFile.open(path_to_zipfile2)
|
40
|
+
return zip_file1, zip_file2
|
41
|
+
end
|
42
|
+
|
43
|
+
# recurrently builds and returns a list of all files and directories in a given path of the given ZIP file
|
44
|
+
def self.get_files_and_dirs_list(zip_file, path)
|
45
|
+
dirs = []
|
46
|
+
files = []
|
47
|
+
zip_file.dir.foreach(path) do |file_system_node|
|
48
|
+
path_to_node = (path == '.' ? file_system_node : File.join(path, file_system_node))
|
49
|
+
if zip_file.file.file?(path_to_node)
|
50
|
+
files << path_to_node
|
51
|
+
elsif zip_file.file.directory?(path_to_node)
|
52
|
+
dirs << path_to_node
|
53
|
+
end
|
54
|
+
end
|
55
|
+
unless dirs.empty?
|
56
|
+
dirs.each do |dir|
|
57
|
+
d,f = get_files_and_dirs_list(zip_file, dir) # Why is there no multi assign += operator? :'(
|
58
|
+
dirs += d
|
59
|
+
files += f
|
60
|
+
end
|
61
|
+
end
|
62
|
+
return dirs.sort, files.sort
|
63
|
+
end
|
64
|
+
|
65
|
+
# compare files in ZIP files using MD5
|
66
|
+
def self.compare_files(zip_file1, file_list1, zip_file2, file_list2)
|
67
|
+
different_files = []
|
68
|
+
identical_files = []
|
69
|
+
file_list1.each do |file1|
|
70
|
+
if zip_file2.file.exists?(file1)
|
71
|
+
hash1 = MD5.md5(zip_file1.file.read(file1))
|
72
|
+
hash2 = MD5.md5(zip_file2.file.read(file1))
|
73
|
+
if hash1 != hash2
|
74
|
+
#add files with different hashes
|
75
|
+
different_files << file1
|
76
|
+
else
|
77
|
+
identical_files << file1
|
78
|
+
end
|
79
|
+
else
|
80
|
+
# add files not existing in zip_file2
|
81
|
+
different_files << file1
|
82
|
+
end
|
83
|
+
end
|
84
|
+
file_list2.each do |file2|
|
85
|
+
# add files not existing in zip_file1 (new in zip_file2)
|
86
|
+
unless zip_file1.file.exists?(file2)
|
87
|
+
different_files << file2
|
88
|
+
end
|
89
|
+
end
|
90
|
+
return identical_files, different_files
|
91
|
+
end
|
92
|
+
|
93
|
+
# Compares two ZIP files. Takes two paths to ZIP files. Compares them and
|
94
|
+
# returns a list of files (exactly paths + file names) which are identical in both
|
95
|
+
# of them and a list of files which are different (changed, added, deleted).
|
96
|
+
def self.compare(path_to_zipfile1, path_to_zipfile2)
|
97
|
+
zipfile1, zipfile2 = read_in_files(path_to_zipfile1, path_to_zipfile2)
|
98
|
+
directory_list1, file_list1 = get_files_and_dirs_list(zipfile1, '.')
|
99
|
+
directory_list2, file_list2 = get_files_and_dirs_list(zipfile2, '.')
|
100
|
+
identical_files, different_files = compare_files(zipfile1, file_list1, zipfile2, file_list2)
|
101
|
+
return identical_files, different_files
|
102
|
+
end
|
103
|
+
|
104
|
+
# Checks if the content of two given ZIP files is identical.
|
105
|
+
# It compares the files contained in them. Regular Expression patterns can be used to
|
106
|
+
# select which files will be compared to determine if the ZIP files are identical.
|
107
|
+
#
|
108
|
+
# optional arguments are:
|
109
|
+
# Regexp :detect_pattern - used to select those files which will be used to determine if
|
110
|
+
# the ZIP files are identical. Default is /.*/
|
111
|
+
# Regexp :ignore_patter - used to ignore files which will be used to determine if
|
112
|
+
# the ZIP files are identical
|
113
|
+
def self.identical?(path_to_zipfile1, path_to_zipfile2, options = {})
|
114
|
+
options = {:detect_pattern => /.*/, :ignore_patter => nil}.merge(options)
|
115
|
+
identical_files, different_files = self.compare(path_to_zipfile1, path_to_zipfile2)
|
116
|
+
if options[:detect_pattern].is_a?(Regexp)
|
117
|
+
different_files = different_files.detect{ |file| file =~ options[:detect_pattern] } || []
|
118
|
+
end
|
119
|
+
if options[:ignore_patter].is_a?(Regexp)
|
120
|
+
different_files = different_files.delete_if{ |file| file =~ options[:ignore_patter] } || []
|
121
|
+
end
|
122
|
+
return different_files.empty?
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# when ran as a script
|
127
|
+
if $0 == __FILE__
|
128
|
+
if ARGV[0] and ARGV[1]
|
129
|
+
identical_files, different_files = ZipContentComparator.compare(ARGV[0].strip.to_s, ARGV[1].strip.to_s)
|
130
|
+
puts "Identical files:"
|
131
|
+
puts identical_files.inspect
|
132
|
+
puts "Different files:"
|
133
|
+
puts different_files.inspect
|
134
|
+
else
|
135
|
+
puts 'Error. Please provide arguments 1 and 2 (paths to files to compare)'
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.tab-size=8
|
2
|
+
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width=80
|
3
|
+
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.usedProfile=default
|
4
|
+
javac.classpath=
|
5
|
+
platform.active=default
|
6
|
+
source.encoding=UTF-8
|
7
|
+
spec.src.dir=spec
|
8
|
+
src.dir=lib
|
9
|
+
src.tasks.dir=tasks
|
10
|
+
test.src.dir=test
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project xmlns="http://www.netbeans.org/ns/project/1">
|
3
|
+
<type>org.netbeans.modules.ruby.rubyproject</type>
|
4
|
+
<configuration>
|
5
|
+
<data xmlns="http://www.netbeans.org/ns/ruby-project/1">
|
6
|
+
<name>Zip File Content Comparator</name>
|
7
|
+
<source-roots>
|
8
|
+
<root id="src.dir"/>
|
9
|
+
<root id="src.tasks.dir" name="Rake Tasks"/>
|
10
|
+
</source-roots>
|
11
|
+
<test-roots>
|
12
|
+
<root id="test.src.dir"/>
|
13
|
+
<root id="spec.src.dir"/>
|
14
|
+
</test-roots>
|
15
|
+
</data>
|
16
|
+
</configuration>
|
17
|
+
</project>
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/test_suite.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'zip_content_comparator'
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
class Test_zip_content_comparator < Test::Unit::TestCase
|
8
|
+
TEST_DATA_PATH = 'test/data/zip_content_comparator'
|
9
|
+
def setup
|
10
|
+
# HOOK: improve test file names (reference file, the same as reference file,
|
11
|
+
# totally diferent file, a bit different file)
|
12
|
+
@reference = File.join(TEST_DATA_PATH, 'reference_test_file.zip')
|
13
|
+
@identical = File.join(TEST_DATA_PATH, 'identical_to_reference_test_file.zip')
|
14
|
+
@one_file_added = File.join(TEST_DATA_PATH, 'one_file_added.zip')
|
15
|
+
@one_file_changed = File.join(TEST_DATA_PATH, 'one_file_changed.zip')
|
16
|
+
@one_file_deleted = File.join(TEST_DATA_PATH, 'one_file_deleted.zip')
|
17
|
+
@one_file_added_deleted_and_changed = File.join(TEST_DATA_PATH, 'one_file_added_deleted_and_changed.zip')
|
18
|
+
@modified_class_file = File.join(TEST_DATA_PATH, 'modified_class_file.zip')
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_001_read_in_zipfiles
|
22
|
+
zip_file1, zip_file2 = ZipContentComparator.read_in_files(@reference, @one_file_added)
|
23
|
+
assert zip_file1
|
24
|
+
assert zip_file2
|
25
|
+
assert_kind_of Zip::ZipFile, zip_file1
|
26
|
+
assert_kind_of Zip::ZipFile, zip_file2
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_002_get_files_and_dirs_list
|
30
|
+
zip_file1, zip_file2 = ZipContentComparator.read_in_files(@reference, @reference)
|
31
|
+
directory_list, file_list = ZipContentComparator.get_files_and_dirs_list(zip_file1, '.')
|
32
|
+
assert ! directory_list.empty?
|
33
|
+
assert ! file_list.empty?
|
34
|
+
assert_not_equal directory_list, file_list
|
35
|
+
assert_equal ["prime", "even", "even/moultiplicityof6"].sort, directory_list
|
36
|
+
assert_equal ["1", "3", "5.class", "even/2", "even/4", "even/moultiplicityof6/6",
|
37
|
+
"even/moultiplicityof6/12.class", "prime/1", "prime/2", "prime/3", "prime/5.class"].sort,
|
38
|
+
file_list
|
39
|
+
end
|
40
|
+
|
41
|
+
# Tests if the MD5 digest is equal for identical files placed in two separate ZIP files
|
42
|
+
# systems (ZIP files). Every test file is in a different ZIP file.
|
43
|
+
def test_003_md5_in_zipfilesystem_works
|
44
|
+
file1 = Zip::ZipFile.open(@reference)
|
45
|
+
file2 = Zip::ZipFile.open(@identical)
|
46
|
+
directory_list1, file_list1 = ZipContentComparator.get_files_and_dirs_list(file1, '.')
|
47
|
+
directory_list2, file_list2 = ZipContentComparator.get_files_and_dirs_list(file2, '.')
|
48
|
+
assert_equal MD5.md5(file1.file.read(file_list1[0])),
|
49
|
+
MD5.md5(file2.file.read(file_list2[0]))
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_004_compare_identical_zip_files
|
53
|
+
zip_file1, zip_file2 = ZipContentComparator.read_in_files(@reference, @identical)
|
54
|
+
directory_list1, file_list1 = ZipContentComparator.get_files_and_dirs_list(zip_file1, '.')
|
55
|
+
directory_list2, file_list2 = ZipContentComparator.get_files_and_dirs_list(zip_file2, '.')
|
56
|
+
identical_files, different_files = ZipContentComparator.compare_files(zip_file1, file_list1, zip_file2, file_list2)
|
57
|
+
assert different_files.empty?
|
58
|
+
assert ! identical_files.empty?
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_012_compare_identical_zip_files
|
62
|
+
identical_files, different_files = ZipContentComparator.compare(@reference, @identical)
|
63
|
+
assert different_files.empty?
|
64
|
+
assert !identical_files.empty?
|
65
|
+
assert_equal 11, identical_files.size
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_013_compare_different_zip_files
|
69
|
+
identical_files, different_files = ZipContentComparator.compare(@reference, @one_file_changed)
|
70
|
+
assert ! different_files.empty?
|
71
|
+
assert ! identical_files.empty?
|
72
|
+
assert_equal 1, different_files.size
|
73
|
+
assert_equal 10, identical_files.size
|
74
|
+
assert_equal ['3'], different_files
|
75
|
+
end
|
76
|
+
def test_014_compare_different_zip_files
|
77
|
+
identical_files, different_files = ZipContentComparator.compare(@reference, @one_file_added)
|
78
|
+
assert ! different_files.empty?
|
79
|
+
assert ! identical_files.empty?
|
80
|
+
assert_equal 1, different_files.size
|
81
|
+
assert_equal 11, identical_files.size
|
82
|
+
assert_equal ['prime/7'], different_files
|
83
|
+
end
|
84
|
+
def test_015_compare_different_zip_files
|
85
|
+
identical_files, different_files = ZipContentComparator.compare(@reference, @one_file_deleted)
|
86
|
+
assert ! different_files.empty?
|
87
|
+
assert ! identical_files.empty?
|
88
|
+
assert_equal 1, different_files.size
|
89
|
+
assert_equal 10, identical_files.size
|
90
|
+
assert_equal ['1'], different_files
|
91
|
+
end
|
92
|
+
def test_016_compare_different_zip_files
|
93
|
+
identical_files, different_files = ZipContentComparator.compare(@reference, @one_file_added_deleted_and_changed)
|
94
|
+
assert ! different_files.empty?
|
95
|
+
assert ! identical_files.empty?
|
96
|
+
assert_equal 3, different_files.size
|
97
|
+
assert_equal 9, identical_files.size
|
98
|
+
assert different_files.include?('1')
|
99
|
+
assert different_files.include?('prime/7')
|
100
|
+
assert different_files.include?('3')
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_021_identical?
|
104
|
+
assert ZipContentComparator.identical?(@reference, @identical)
|
105
|
+
end
|
106
|
+
def test_022_not_identical
|
107
|
+
assert ! ZipContentComparator.identical?(@reference, @one_file_changed)
|
108
|
+
end
|
109
|
+
def test_023_identical_with_detect_pattern
|
110
|
+
assert ZipContentComparator.identical?(@reference, @identical,
|
111
|
+
:detect_pattern => /.class$/)
|
112
|
+
end
|
113
|
+
def test_024_not_identical_with_detect_pattern
|
114
|
+
assert ! ZipContentComparator.identical?(@reference, @modified_class_file,
|
115
|
+
:detect_pattern => /.class$/)
|
116
|
+
end
|
117
|
+
def test_025_identical_with_ignore_pattern
|
118
|
+
assert ZipContentComparator.identical?(@reference, @identical,
|
119
|
+
:ignore_pattern => /.class$/)
|
120
|
+
end
|
121
|
+
def test_026_not_identical_with_ignore_pattern
|
122
|
+
assert ! ZipContentComparator.identical?(@reference, @modified_class_file,
|
123
|
+
:ignore_pattern => /.class$/)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_041_example_from_doku_string
|
127
|
+
identical_files, different_files = ZipContentComparator.compare(@reference, @identical)
|
128
|
+
list_of_changed_class_files = different_files.detect{ |file| file =~ /.class$/ } || []
|
129
|
+
assert list_of_changed_class_files.empty?
|
130
|
+
end
|
131
|
+
def test_042_example_from_doku_string
|
132
|
+
identical_files, different_files = ZipContentComparator.compare(@reference, @modified_class_file)
|
133
|
+
list_of_changed_class_files = different_files.detect{ |file| file =~ /.class$/ } || []
|
134
|
+
assert ! list_of_changed_class_files.empty?
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{zip_content_comparator}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Szymon (jeznet) Je\305\274"]
|
12
|
+
s.date = %q{2010-08-17}
|
13
|
+
s.description = %q{An utility for comparing content of ZIP files.
|
14
|
+
It does not extract the files anywhere, its's using instead ZIP::ZipFile class
|
15
|
+
from rubyzip gem which enables to access ZIP files like a file system.
|
16
|
+
It uses MD5 to compare files.
|
17
|
+
}
|
18
|
+
s.email = %q{szymon@jez.net.pl}
|
19
|
+
s.extra_rdoc_files = [
|
20
|
+
"LICENSE",
|
21
|
+
"README.rdoc"
|
22
|
+
]
|
23
|
+
s.files = [
|
24
|
+
".autotest",
|
25
|
+
".gitignore",
|
26
|
+
"LICENSE",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"lib/zip_content_comparator.rb",
|
31
|
+
"nbproject/project.properties",
|
32
|
+
"nbproject/project.xml",
|
33
|
+
"test/data/zip_content_comparator/identical_to_reference_test_file.zip",
|
34
|
+
"test/data/zip_content_comparator/modified_class_file.zip",
|
35
|
+
"test/data/zip_content_comparator/one_file_added.zip",
|
36
|
+
"test/data/zip_content_comparator/one_file_added_deleted_and_changed.zip",
|
37
|
+
"test/data/zip_content_comparator/one_file_changed.zip",
|
38
|
+
"test/data/zip_content_comparator/one_file_deleted.zip",
|
39
|
+
"test/data/zip_content_comparator/reference_test_file.zip",
|
40
|
+
"test/test_suite.rb",
|
41
|
+
"test/test_zip_content_comparator.rb",
|
42
|
+
"zip_content_comparator.gemspec"
|
43
|
+
]
|
44
|
+
s.homepage = %q{http://github.com/jeznet/zip_content_comparator}
|
45
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
46
|
+
s.require_paths = ["lib"]
|
47
|
+
s.rubygems_version = %q{1.3.6}
|
48
|
+
s.summary = %q{An utility for comparing content of ZIP files.}
|
49
|
+
s.test_files = [
|
50
|
+
"test/test_suite.rb",
|
51
|
+
"test/test_zip_content_comparator.rb"
|
52
|
+
]
|
53
|
+
|
54
|
+
if s.respond_to? :specification_version then
|
55
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
56
|
+
s.specification_version = 3
|
57
|
+
|
58
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
59
|
+
s.add_runtime_dependency(%q<rubyzip>, [">= 0.9.1"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<rubyzip>, [">= 0.9.1"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<rubyzip>, [">= 0.9.1"])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zip_content_comparator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- "Szymon (jeznet) Je\xC5\xBC"
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-08-17 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rubyzip
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 9
|
30
|
+
- 1
|
31
|
+
version: 0.9.1
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: |
|
35
|
+
An utility for comparing content of ZIP files.
|
36
|
+
It does not extract the files anywhere, its's using instead ZIP::ZipFile class
|
37
|
+
from rubyzip gem which enables to access ZIP files like a file system.
|
38
|
+
It uses MD5 to compare files.
|
39
|
+
|
40
|
+
email: szymon@jez.net.pl
|
41
|
+
executables: []
|
42
|
+
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
extra_rdoc_files:
|
46
|
+
- LICENSE
|
47
|
+
- README.rdoc
|
48
|
+
files:
|
49
|
+
- .autotest
|
50
|
+
- .gitignore
|
51
|
+
- LICENSE
|
52
|
+
- README.rdoc
|
53
|
+
- Rakefile
|
54
|
+
- VERSION
|
55
|
+
- lib/zip_content_comparator.rb
|
56
|
+
- nbproject/project.properties
|
57
|
+
- nbproject/project.xml
|
58
|
+
- test/data/zip_content_comparator/identical_to_reference_test_file.zip
|
59
|
+
- test/data/zip_content_comparator/modified_class_file.zip
|
60
|
+
- test/data/zip_content_comparator/one_file_added.zip
|
61
|
+
- test/data/zip_content_comparator/one_file_added_deleted_and_changed.zip
|
62
|
+
- test/data/zip_content_comparator/one_file_changed.zip
|
63
|
+
- test/data/zip_content_comparator/one_file_deleted.zip
|
64
|
+
- test/data/zip_content_comparator/reference_test_file.zip
|
65
|
+
- test/test_suite.rb
|
66
|
+
- test/test_zip_content_comparator.rb
|
67
|
+
- zip_content_comparator.gemspec
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://github.com/jeznet/zip_content_comparator
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options:
|
74
|
+
- --charset=UTF-8
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.3.6
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: An utility for comparing content of ZIP files.
|
98
|
+
test_files:
|
99
|
+
- test/test_suite.rb
|
100
|
+
- test/test_zip_content_comparator.rb
|