require 'rake/clean' WARNING = <<-EOS.freeze WARNING: you may not have wget installed EOS WORDCRAM_VERSION = '1.0.0' CLOBBER.include("wordcram.#{WORDCRAM_VERSION}.zip") desc "download, and copy to wordcram/lib" task :default => [:download, :unpack_library, :copy_jars] desc "download wordcram upstream sources" task :download => ["wordcram.#{WORDCRAM_VERSION}.zip"] file "wordcram.#{WORDCRAM_VERSION}.zip" do begin sh "wget http://wordcram.org/wordcram.#{WORDCRAM_VERSION}.zip" rescue warn(WARNING) end check_sha256("wordcram.#{WORDCRAM_VERSION}.zip", "d6b936db3628806099eba3f309fad81dae7f3db5e2a2846742c959b03eb0d25f") end desc "unpack wordcram library" task :unpack_library do sh "unzip wordcram.#{WORDCRAM_VERSION}.zip" end directory "../lib" desc "copy jars" task :copy_jars => ["../lib"] do sh "cp -v WordCram/library/WordCram.jar ../lib/WordCram.jar" sh "cp -v WordCram/library/cue.language.jar ../lib/cue.language.jar" sh "cp -v WordCram/library/jsoup-1.7.2.jar ../lib/jsoup-1.7.2.jar" end def check_sha256(filename, expected_hash) require "digest" sha256 = Digest::SHA256.new File.open(filename, "r") do |f| while buf = f.read(4096) sha256.update(buf) end end if sha256.hexdigest != expected_hash raise "bad sha256 checksum for #{filename} (expected #{expected_hash} got #{sha256.hexdigest})" end end