forked from yob/pdf-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
83 lines (70 loc) · 2.37 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require "bundler/gem_tasks"
require "digest/md5"
require "rdoc/task"
require "rspec/core/rake_task"
require "yaml"
desc "Default Task"
task :default => [ :quality, :spec ]
require 'cane/rake_task'
require 'morecane'
desc "Run cane to check quality metrics"
Cane::RakeTask.new(:quality) do |cane|
cane.abc_max = 20
cane.style_measure = 100
cane.max_violations = 31
cane.use Morecane::EncodingCheck, :encoding_glob => "{app,lib,spec}/**/*.rb"
end
desc "Run all rspec files"
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = ["--color", "--format progress"]
t.ruby_opts = "-w"
end
# Generate the RDoc documentation
desc "Create documentation"
Rake::RDocTask.new("doc") do |rdoc|
rdoc.title = "pdf-reader"
rdoc.rdoc_dir = (ENV['CC_BUILD_ARTIFACTS'] || 'doc') + '/rdoc'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('TODO')
rdoc.rdoc_files.include('CHANGELOG')
rdoc.rdoc_files.include('MIT-LICENSE')
rdoc.rdoc_files.include('lib/**/*.rb')
rdoc.options << "--inline-source"
end
desc "Create a YAML file of integrity info for PDFs in the spec suite"
task :integrity_yaml do
data = {}
Dir.glob("spec/data/**/*.*").sort.each do |path|
path_without_spec = path.gsub("spec/","")
data[path_without_spec] = {
:bytes => File.size(path),
:md5 => Digest::MD5.hexdigest(File.read(path))
} if File.file?(path)
end
File.open("spec/integrity.yml","wb") { |f| f.write YAML.dump(data)}
end
desc "Remove any CRLF characters added by Git"
task :fix_integrity do
yaml_path = File.expand_path("spec/integrity.yml",File.dirname(__FILE__))
integrity = YAML.load_file(yaml_path)
Dir.glob("spec/data/**/*.pdf").each do |path|
path_relative_to_spec_folder = path[/.+(data\/.+)/,1]
item = integrity[path_relative_to_spec_folder]
if File.file?(path)
file_contents = File.open(path, "rb") { |f| f.read }
md5 = Digest::MD5.hexdigest(file_contents)
unless md5 == item[:md5]
#file md5 does not match what was checked into Git
if Digest::MD5.hexdigest(file_contents.gsub(/\r\n/, "\n")) == item[:md5]
#pdf file is fixable by swapping CRLF characters
File.open(path, "wb") do |f|
f.write(file_contents.gsub(/\r\n/, "\n"))
end
puts "Replaced CRLF characters in: #{path}"
else
puts "Failed to fix: #{path}"
end
end
end
end
end