#!/usr/bin/env ruby DOWNLOADS_FILE = 'pages/download.md' def need_pages_submodule unless File.exists?(DOWNLOADS_FILE) raise "Robolectric pages submodule isn't present. Run git submodule update --init" end end def fill_index_downloads require 'digest/sha1' download_html = "\n" Dir.glob('pages/downloads/*.jar').sort.reverse.each do |f| sha1 = Digest::SHA1.hexdigest File.read(f) fn = f.sub(/^pages\//, '') match = /robolectric-?([0-9]\.[0-9](\.[0-9])?)?(-all)?(-src)?\.jar/.match(f) version = match[1] if match version = "SNAPSHOT" unless version prerelease = /\.rc/.match(f) download_html += prerelease ? "\n" : "\n" download_html += " #{fn.sub(/downloads\//, '')}\n" download_html += " #{version}\n" download_html += " #{File.size(f) / 1024}k\n" download_html += " #{File.mtime(f).strftime("%Y/%m/%d %H:%M:%S %Z")}\n" download_html += " #{sha1}\n" download_html += "\n" end download_html += "" downloads_page = File.read(DOWNLOADS_FILE) matcher = /.*/m downloads_page = downloads_page.sub(matcher, download_html) File.open(DOWNLOADS_FILE, 'w') {|f| f.write(downloads_page)} puts "rewrote " + DOWNLOADS_FILE end fill_index_downloads