-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathRakefile
More file actions
66 lines (52 loc) · 1.5 KB
/
Copy pathRakefile
File metadata and controls
66 lines (52 loc) · 1.5 KB
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
# frozen_string_literal: true
task default: [:specs]
require 'bundler/gem_tasks'
require 'rake/clean'
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
rescue LoadError
# RuboCop not available; skip defining the task
end
desc 'run specs'
task :specs do
$LOAD_PATH << 'specs'
Dir['specs/*_spec.rb'].each do |f|
require File.basename(f.sub(/.rb$/, ''))
end
end
require_relative 'lib/jars/mima/version'
MIMA_VERSION = Jars::Mima::MIMA_VERSION
SLF4J_VERSION = Jars::Mima::SLF4J_VERSION
MIMA_JARS = Jars::Mima::JARS
MIMA_DIR = Jars::Mima::MIMA_DIR
MIMA_JARS.each_key { |jar| CLEAN.include(File.join(MIMA_DIR, jar)) }
desc 'download Mima (and dependent SLF4J) jars'
task :download_jars do
require 'fileutils'
require 'open-uri'
require 'digest/sha1'
FileUtils.mkdir_p(MIMA_DIR)
MIMA_JARS.each do |filename, info|
target = File.join(MIMA_DIR, filename)
if File.exist?(target)
verify_checksum(target, info[:sha1])
puts " exists: #{target}"
next
end
puts " downloading #{filename}..."
URI.open(info[:url]) do |remote| # rubocop:disable Security/Open
File.open(target, 'wb') { |f| f.write(remote.read) }
end
verify_checksum(target, info[:sha1])
puts " saved: #{target}"
end
end
def verify_checksum(path, expected_sha1)
actual = Digest::SHA1.file(path).hexdigest
return if actual == expected_sha1
File.delete(path)
raise "SHA-1 mismatch for #{path}:\n" \
" expected: #{expected_sha1}\n" \
" actual: #{actual}"
end