blob: 308460555a2383ee5cd2b5852eb11193f58c0f8f [file] [log] [blame]
Christian Williams & Phil Goodwin7ce366c2010-11-03 10:31:04 -07001#!/usr/bin/env ruby
2
Phil Goodwin & Tyler Schultz5010e892010-11-24 12:14:01 -08003DOWNLOADS_FILE = 'pages/download.md'
Christian Williams & Phil Goodwin7ce366c2010-11-03 10:31:04 -07004
5def need_pages_submodule
6 unless File.exists?(DOWNLOADS_FILE)
Phil Goodwinec5935c2010-11-05 16:39:47 -07007 raise "Robolectric pages submodule isn't present. Run git submodule update --init"
Christian Williams & Phil Goodwin7ce366c2010-11-03 10:31:04 -07008 end
9end
10
Christian Williams & Phil Goodwin7ce366c2010-11-03 10:31:04 -070011def fill_index_downloads
12 require 'digest/sha1'
13
14 download_html = "<!-- START_DOWNLOADS -->\n"
15 Dir.glob('pages/downloads/*.jar').sort.reverse.each do |f|
16 sha1 = Digest::SHA1.hexdigest File.read(f)
17
18 fn = f.sub(/^pages\//, '')
Phil Goodwind25f4d22010-11-19 14:27:19 -080019 match = /robolectric-?([0-9]\.[0-9](\.[0-9])?)?(-all)?(-src)?\.jar/.match(f)
Christian Williams, Phil Goodwin & Tyler Schultzf74dd002010-11-17 17:30:57 -080020 version = match[1] if match
Phil Goodwin & Tyler Schultz228a1ed2010-11-23 16:42:17 -080021 version = "SNAPSHOT" unless version
Christian Williams & Phil Goodwin7ce366c2010-11-03 10:31:04 -070022 prerelease = /\.rc/.match(f)
23 download_html += prerelease ? "<tr class=\"rc\">\n" : "<tr>\n"
Phil Goodwin & Tyler Schultz7317fea2010-12-14 12:06:55 -080024 download_html += " <td class=\"link\"><a href=\"#{fn}\" onClick=\"javascript:pageTracker._trackPageView('#{fn}'); \">#{fn.sub(/downloads\//, '')}</a></td>\n"
Christian Williams & Phil Goodwin7ce366c2010-11-03 10:31:04 -070025 download_html += " <td class=\"version\">#{version}</td>\n"
26 download_html += " <td class=\"size\">#{File.size(f) / 1024}k</td>\n"
27 download_html += " <td class=\"date\">#{File.mtime(f).strftime("%Y/%m/%d %H:%M:%S %Z")}</td>\n"
28 download_html += " <td class=\"sha\">#{sha1}</td>\n"
29 download_html += "</tr>\n"
30 end
31 download_html += "<!-- END_DOWNLOADS -->"
32
33 downloads_page = File.read(DOWNLOADS_FILE)
34 matcher = /<!-- START_DOWNLOADS -->.*<!-- END_DOWNLOADS -->/m
35 downloads_page = downloads_page.sub(matcher, download_html)
36 File.open(DOWNLOADS_FILE, 'w') {|f| f.write(downloads_page)}
Christian Williams, Phil Goodwin & Tyler Schultzf74dd002010-11-17 17:30:57 -080037 puts "rewrote " + DOWNLOADS_FILE
Christian Williams & Phil Goodwin7ce366c2010-11-03 10:31:04 -070038end
39
40fill_index_downloads