require 'rake/clean' require 'rbconfig' WARNING = <<-EOS WARNING: you may not have curl installed, you could just download the correct version of jruby-complete and/or examples to the vendors folder, and re-run k9 setup install instead of installing curl. Some systems may also require 'sudo' access to install jruby-complete, NB: this is untested.... EOS JRUBYC_VERSION = '1.7.20' EXAMPLES = '0.0.6-pre' HOME_DIR = ENV['HOME'] MAC_OR_LINUX = /linux|mac|darwin/ =~ RbConfig::CONFIG['host_os'] CLOBBER.include("jruby-complete-#{JRUBYC_VERSION}.jar", "#{EXAMPLES}.tar.gz", "video.zip") desc "download, and copy to ruby-processing" task :default => [:install_ruby, :install_video, :config, :install_examples] desc "install jruby" task :install_ruby => [:download, :copy_ruby] desc "install video library" task :install_video => [:download_video, :copy_video] desc "install examples" task :install_examples => [:download_examples, :copy_examples] desc "download JRuby upstream sources" task :download => ["jruby-complete-#{JRUBYC_VERSION}.jar"] file "jruby-complete-#{JRUBYC_VERSION}.jar" do begin sh "curl -O https://s3.amazonaws.com/jruby.org/downloads/#{JRUBYC_VERSION}/jruby-complete-#{JRUBYC_VERSION}.jar" rescue warn(WARNING) end check_sha1("jruby-complete-#{JRUBYC_VERSION}.jar", "0f784b3d9d760b80b2f9d78ede80ee1d8d85e786") end desc "download processing video-library" task :download_video => ["video.zip"] file "video.zip" do begin sh "curl -O https://github.com/processing/processing-video/releases/download/latest/video.zip" rescue warn(WARNING) end end directory "../lib/ruby" desc "copy jruby-complete" task :copy_ruby => ["../lib/ruby"] do sh "cp -v jruby-complete-#{JRUBYC_VERSION}.jar ../lib/ruby/jruby-complete.jar" end desc "download, and copy to JRubyArt" task :unpack_samples => [:download_examples, :copy_examples] desc 'download and copy examples to user home' task :download_examples file_name = (MAC_OR_LINUX.nil?) ? "#{EXAMPLES}.zip" : "#{EXAMPLES}.tar.gz" file file_name do begin if MAC_OR_LINUX.nil? sh "curl -Lo examples.zip https://github.com/ruby-processing/JRubyArt-examples/archive/#{EXAMPLES}.zip" else sh "curl -Lo examples.tar.gz https://github.com/ruby-processing/JRubyArt-examples/archive/#{EXAMPLES}.tar.gz" end rescue warn(WARNING) end end desc "copy video library" task :copy_video => ["../library/video/lib"] do sh "unzip video.zip" Dir["video/library/*.jar"].each do |f| sh "cp #{f} ../library/video/lib" end sh "cp -r video/library/windows32 ../library/video/lib" sh "cp -r video/library/windows64 ../library/video/lib" sh "cp -r video/library/macosx64 ../library/video/lib" end desc "copy examples" task :copy_examples => file_name do if MAC_OR_LINUX.nil? sh "unzip examples.zip" else sh "tar xzvf examples.tar.gz" end sh "cp -r JRubyArt-examples-#{EXAMPLES} #{HOME_DIR}/examples" sh "rm -r JRubyArt-examples-#{EXAMPLES}" end desc "config" task :config => file_name do next if FileTest.exist?("#{HOME_DIR}/.jruby_art/config.yml") sh "tar xzvf config.tar.gz" sh "cp -r .jruby_art #{HOME_DIR}" end def check_sha1(filename, expected_hash) require "digest/sha1" sha1 = Digest::SHA1.new File.open(filename, "r") do |f| while buf = f.read(4096) sha1.update(buf) end end if sha1.hexdigest != expected_hash raise "bad sha1 checksum for #{filename} (expected #{expected_hash} got #{sha1.hexdigest})" end end