3 require 'rake/testtask'
4 require 'rake/rdoctask'
5 require 'rake/packagetask'
6 require 'rake/gempackagetask'
7 require 'rake/contrib/rubyforgepublisher'
11 PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
12 RELEASE_NAME = "REL #{PKG_VERSION}"
14 RUBY_FORGE_PROJECT = "rubyvote"
15 RUBY_FORGE_USER = "mako"
18 task :default => [ :test ]
21 Rake::TestTask.new { |t|
23 t.pattern = 'test/*_test.rb'
28 # Genereate the RDoc documentation
29 Rake::RDocTask.new { |rdoc|
31 rdoc.title = "RubyVote -- Election Methods in Ruby"
32 rdoc.rdoc_files.include('README', 'ChangeLog', 'COPYING')
33 rdoc.rdoc_files.include('lib/rubyvote.rb')
34 rdoc.rdoc_files.include('lib/rubyvote/*.rb')
38 # Create compressed packages
39 spec = Gem::Specification.new do |s|
40 s.platform = Gem::Platform::RUBY
42 s.summary = "Election methods library in ruby."
43 s.description = %q{Provides a variety of different election types.}
44 s.version = PKG_VERSION
46 s.author = "Benjamin Mako Hill"
47 s.email = "mako @nospam@ atdot.cc"
48 s.rubyforge_project = RUBY_FORGE_PROJECT
49 s.homepage = "http://rubyvote.rubyforge.org"
52 s.requirements << 'none'
53 s.require_path = 'lib'
54 s.autorequire = 'rubyvote'
56 s.files = [ "Rakefile", "README", "ChangeLog", "COPYING" ]
57 s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
58 s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
61 Rake::GemPackageTask.new(spec) do |p|
67 ###TODO: Configure for api documentation login and path
68 desc "Publish the API documentation"
69 task :pgem => [:package] do
70 Rake::SshFilePublisher.new("login@foo.com", "path/to/place", "pkg", "#{PKG_FILE_NAME}.gem").upload
73 desc "Publish the release files to RubyForge."
74 task :release => [:package] do
75 files = ["gem", "tgz", "zip"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }
77 if RUBY_FORGE_PROJECT then
81 project_uri = "http://rubyforge.org/projects/#{RUBY_FORGE_PROJECT}/"
82 project_data = open(project_uri) { |data| data.read }
83 group_id = project_data[/[?&]group_id=(\d+)/, 1]
84 raise "Couldn't get group id" unless group_id
86 # This echos password to shell which is a bit sucky
87 if ENV["RUBY_FORGE_PASSWORD"]
88 password = ENV["RUBY_FORGE_PASSWORD"]
90 print "#{RUBY_FORGE_USER}@rubyforge.org's password: "
91 password = STDIN.gets.chomp
94 login_response = Net::HTTP.start("rubyforge.org", 80) do |http|
97 "form_loginname=#{RUBY_FORGE_USER}",
100 http.post("/account/login.php", data)
103 cookie = login_response["set-cookie"]
104 raise "Login failed" unless cookie
105 headers = { "Cookie" => cookie }
107 release_uri = "http://rubyforge.org/frs/admin/?group_id=#{group_id}"
108 release_data = open(release_uri, headers) { |data| data.read }
109 package_id = release_data[/[?&]package_id=(\d+)/, 1]
110 raise "Couldn't get package id" unless package_id
115 files.each do |filename|
116 basename = File.basename(filename)
117 file_ext = File.extname(filename)
118 file_data = File.open(filename, "rb") { |file| file.read }
120 puts "Releasing #{basename}..."
122 release_response = Net::HTTP.start("rubyforge.org", 80) do |http|
123 release_date = Time.now.strftime("%Y-%m-%d %H:%M")
129 }; type_map.default = "9999"
130 type = type_map[file_ext]
131 boundary = "rubyqMY6QN9bp6e4kS21H4y0zxcvoor"
133 query_hash = if first_file then
135 "group_id" => group_id,
136 "package_id" => package_id,
137 "release_name" => RELEASE_NAME,
138 "release_date" => release_date,
140 "processor_id" => "8000", # Any
141 "release_notes" => "",
142 "release_changes" => "",
143 "preformatted" => "1",
148 "group_id" => group_id,
149 "release_id" => release_id,
150 "package_id" => package_id,
153 "processor_id" => "8000", # Any
154 "submit" => "Add This File"
158 query = "?" + query_hash.map do |(name, value)|
159 [name, URI.encode(value)].join("=")
164 "Content-Disposition: form-data; name=\"userfile\"; filename=\"#{basename}\"",
165 "Content-Type: application/octet-stream",
166 "Content-Transfer-Encoding: binary",
170 release_headers = headers.merge(
171 "Content-Type" => "multipart/form-data; boundary=#{boundary}"
174 target = first_file ? "/frs/admin/qrs.php" : "/frs/admin/editrelease.php"
175 http.post(target + query, data, release_headers)
179 release_id = release_response.body[/release_id=(\d+)/, 1]
180 raise("Couldn't get release id") unless release_id