#!/usr/bin/env ruby require 'rubygems' require 'meta_project' require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'rake/gempackagetask' require 'rake/contrib/rubyforgepublisher' require 'rake/contrib/xforge' require 'rake/clean' #require 'archive/tar/minitar' #require 'zlib' $LOAD_PATH.unshift( File.join( File.dirname(__FILE__), 'lib') ) require 'masterview' RUBY_FORGE_PROJECT = "masterview" RUBY_FORGE_USER = "jeffbski" RUBY_FORGE_GROUPID = "1290" Main_dir = Dir.getwd desc "Default Task: run all tests" task :default => [ :test ] task :install => [:package] do `gem install pkg/#{PKG_FILE_NAME}.gem` end desc "Delete tar.gz / zip / gem / rdoc / tmp" task :cleanup => [ :rm_packages, 'doc:clobber_rdoc', 'dev:cleanup', 'test:cleanup' ] #============================================================================== # Test tasks #============================================================================== desc 'Run all tests' task :test do Rake::Task["test:units"].invoke rescue got_error = true #Rake::Task["test:functionals"].invoke rescue got_error = true #??Rake::Task["test:cleanup"].invoke rescue got_error = true raise "Test failures" if got_error end # Run all unit tests namespace 'test' do Rake::TestTask.new(:units) do |t| t.libs << "lib" t.libs << "test" t.pattern = 'test/unit/*_test.rb' t.verbose = false end end desc 'Clean up tmp files from running tests' namespace 'test' do task :cleanup do FileUtils.remove_dir('test/tmp', true) end end #============================================================================== # Documentation Tasks #============================================================================== # Generate the RDoc documentation namespace 'doc' do Rake::RDocTask.new { |rdoc| rdoc.rdoc_dir = 'doc/api' rdoc.title = "MasterView Template Engine" rdoc.options << '--line-numbers' << '--inline-source' rdoc.rdoc_files.include('README') rdoc.rdoc_files.include('RELEASE_NOTES') rdoc.rdoc_files.include('lib/**/*.rb') } end #============================================================================== # Development Utilities Tasks #============================================================================== desc 'Install MasterView gems locally from pkg dir' namespace 'dev' do task :install_local_gems do pkg_build = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : '' pkg_version = MasterView::VERSION::STRING + pkg_build `gem install pkg/masterview-#{pkg_version}.gem --local -f` `gem install pkg/masterview_generator-#{pkg_version}.gem --local -f` `gem install pkg/masterview_plugin_generator-#{pkg_version}.gem --local -f` `gem install pkg/masterview_gem_pack-#{pkg_version}.gem --local -f` end end desc 'Uninstall all MasterView gems' namespace 'dev' do task :uninstall_gems do `gem uninstall masterview -a -x -i` end end desc 'Run parser on masterview html templates in examples' namespace 'dev' do task :mvparse_examples do template_mio_tree = MasterView::FileMIOTree.new('examples', '.html', :logging => true ) output_mio_tree = MasterView::FileMIOTree.new('tmp/views', '.rhtml', :logging => true ) template_mio_tree.find(:pattern => '*.html') do |mio| MasterView::Parser.parse_mio( mio, output_mio_tree ) end end end # Run syntax check on all ruby code files desc 'Run syntax check on all ruby code files' namespace 'dev' do task :check_syntax do #WAS: filelist = Dir.glob('**/*.rb') #skip: generators - erb-ized code templates confuse the parser filelist = [ 'init.rb', 'lib/masterview.rb' ] filelist.concat Dir.glob('lib/**/*.rb') filelist.concat Dir.glob('test/**/*.rb') filelist.each do |file| output = `ruby -c #{file}` unless output =~ /Syntax OK/ puts "#{file}:" puts " #{output}" return end end puts "#{filelist.length} files checked" puts 'Syntax OK' end end # Count LOC in plugin lib desc 'Count LOC' namespace 'dev' do task :count_loc do files = 0 lines = 0 codelines = 0 #VER1 WAS: Dir.foreach("lib") { |file_name| #VER1 WAS: next unless file_name =~ /.*rb/ #VER1 WAS: f = File.open("lib/" + file_name) filelist = [ 'init.rb', 'lib/masterview.rb' ] filelist.concat Dir.glob('lib/**/*.rb') #filelist.concat Dir.glob('test**/*.rb') filelist.each { |file_name| f = File.open(file_name) files += 1 while line = f.gets lines += 1 next if line =~ /^\s*$/ next if line =~ /^\s*#/ codelines += 1 end } puts "Lines #{lines}, LOC #{codelines} in #{files} files" end end desc 'Remove tmp files from running dev utilities' namespace 'dev' do task :cleanup do FileUtils.remove_dir('tmp', true) end end #============================================================================== # Build/Release Tasks #============================================================================== # Publish beta gem #desc "Publish the gem" #task :publish => [:rdoc, :package] do # Rake::SshFilePublisher.new("foobar.com", "dist/pkg", "pkg", "#{PKG_FILE_NAME}.zip").upload # Rake::SshFilePublisher.new("foobar.com", "dist/pkg", "pkg", "#{PKG_FILE_NAME}.tgz").upload # Rake::SshFilePublisher.new("foobar.com", "dist/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload # # Rake::SshDirPublisher.new("foobar.com", "dist/api/#{PKG_NAME}", "doc").upload #end desc 'Verify RUBYFORGE_USER and RUBYFORGE_PASSWORD' task :verify_rubyforge do raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER'] raise "RUBYFORGE_PASSWORD environment variable not set!" unless ENV['RUBYFORGE_PASSWORD'] MASTERVIEW = MetaProject::Project::XForge::RubyForge.new('masterview') end desc 'Verify GMAIL_USER GMAIL_PASSWORD' task :verify_gmail do raise "GMAIL_USER environment variable not set!" unless ENV['GMAIL_USER'] raise "GMAIL_PASSWORD environment variable not set!" unless ENV['GMAIL_PASSWORD'] end def copy_if_different(src,dst) return if File.exist?(src) and File.exist?(dst) and File.read(src) == File.read(dst) FileUtils.cp src, dst end desc 'Copy duplicated files - copy files that are duplicated between packages' task :copy_duplicated_files do copy_if_different 'init.rb', 'generators/masterview_plugin/templates/init.rb' copy_if_different 'tasks/masterview.rake', 'generators/masterview_plugin/templates/masterview.rake' copy_if_different 'lib/masterview/extras/app/views/masterview/admin/empty.rhtml', 'generators/masterview_plugin/templates/empty.rhtml' copy_if_different 'examples/rails_app_config/masterview/settings.rb', 'generators/masterview_plugin/templates/settings.rb' copy_if_different 'examples/rails_app_config/masterview/environment/development.rb', 'generators/masterview_plugin/templates/development.rb' copy_if_different 'examples/rails_app_config/masterview/environment/production.rb', 'generators/masterview_plugin/templates/production.rb' end desc 'Build all packages' task :package => [ :copy_duplicated_files, # gems (runtime, mv generator, mv plugin generator, 3-in-1 supersaver) 'masterview:package', 'masterview_generator:package', 'masterview_plugin_generator:package', 'masterview_gem_pack:package', # zip/gzip of full masterview 'masterview_plugin:package' ] desc 'Re-build all packages' task :repackage => [ :copy_duplicated_files, # gems (runtime, mv generator, mv plugin generator, 3-in-1 supersaver) 'masterview:repackage', 'masterview_generator:repackage', 'masterview_plugin_generator:repackage', 'masterview_gem_pack:repackage', # zip/gzip of full masterview 'masterview_plugin:repackage' ] desc 'Release all files' task :release_files => [ # gems (runtime, mv generator, mv plugin generator, 3-in-1 supersaver) 'masterview:release_files', 'masterview_generator:release_files', 'masterview_plugin_generator:release_files', 'masterview_gem_pack:release_files', # zip/gzip of full masterview 'masterview_plugin:release_files' ] desc 'Remove all tar.gz / zip / gem build pkg files' task :rm_packages do FileUtils.remove_dir('pkg', true) end #### #ISSUE: jeff - we don't include that top-level index.html in any of the packages?! #### PKG_FILES_RELEASE_DOCS = [ "[A-Z]*" # README, RELEASE_NOTES, CHANGELOG, MIT_LICENSE, TODO ] PKG_FILES_RUNTIME = [ "lib/**/*", "directives/**/*", #SHOULD THIS GO AWAY (??) "Rakefile", "init.rb" ] PKG_FILES_MV_GENERATOR = [ "generators/masterview/**/*" # generator for creating app template scaffold ] PKG_FILES_MV_PLUGIN_GENERATOR = [ "generators/masterview_plugin/**/*" # generator for creating vendor/plugins stub for gem install ] PKG_FILES_DOCS = [ # docs and examples, actually "doc/*", "doc/images/*.png", "doc/screenshots/*", "doc/stylesheets/*", "examples/**/*" ] PKG_FILES_TESTS = [ "test/**/*" ] PKG_FILES_EXCLUDE_PATTERN = /\bCVS\b|~$|\.svn|semantic.cache/ RAKE_PROCESSOR = RUBY_PLATFORM =~ /mswin32/ ? 'rake.cmd' : 'rake' # sigh namespace 'masterview_plugin' do module MasterViewComplete PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : '' PKG_NAME = 'masterview_plugin' PKG_VERSION = MasterView::VERSION::STRING + PKG_BUILD PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}" RELEASE_NAME = "REL #{PKG_VERSION}" PKG_INCLUDES = PKG_FILES_RUNTIME + PKG_FILES_MV_GENERATOR + PKG_FILES_DOCS + PKG_FILES_TESTS + PKG_FILES_RELEASE_DOCS PKG_FILES = FileList.new( PKG_INCLUDES ).exclude( PKG_FILES_EXCLUDE_PATTERN ) spec = Gem::Specification.new do |s| s.name = PKG_NAME s.version = PKG_VERSION s.summary = "A (x)html friendly template engine for rails with the power of layouts, and partials. This is the plugin version which contains everything for installation, does not require any gems." s.has_rdoc = true s.files = PKG_FILES s.require_path = 'lib' s.autorequire = 'masterview' s.author = "Jeff Barczewski" s.email = "jeff.barczewski@gmail.com" s.homepage = "http://masterview.org/" end # Create Rubygem package Rake::GemPackageTask.new(spec) do |p| p.gem_spec = spec p.need_tar = true p.need_zip = true end desc "Release files on RubyForge." task :release_files => [ :verify_rubyforge ] do release_files = ["zip", "tgz"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" } Rake::XForge::Release.new(MASTERVIEW) do |release| release.user_name = ENV['RUBYFORGE_USER'] release.password = ENV['RUBYFORGE_PASSWORD'] release.files = release_files.to_a release.release_name = RELEASE_NAME release.package_name = PKG_NAME notes = [] File.open("RELEASE_NOTES") do |file| file.each do |line| line.chomp! line.gsub!(/^#.*$/, '') and next notes << line end end release.release_notes = notes.join("\n") changes = [] File.open("CHANGELOG") do |file| current = true file.each do |line| line.chomp! current = false if current and line =~ /^==/ break if line.empty? and not current changes << line end end release.release_changes = changes.join("\n") end end end end namespace 'masterview_gem_pack' do module MasterViewGemPack PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : '' PKG_NAME = 'masterview_gem_pack' PKG_VERSION = MasterView::VERSION::STRING + PKG_BUILD PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}" RELEASE_NAME = "REL #{PKG_VERSION}" PKG_INCLUDES = PKG_FILES_RELEASE_DOCS PKG_FILES = FileList.new( PKG_INCLUDES ).exclude( PKG_FILES_EXCLUDE_PATTERN ) spec = Gem::Specification.new do |s| s.name = PKG_NAME s.version = PKG_VERSION s.summary = "A (x)html friendly template engine for rails with the power of layouts, and partials. This gem package includes the other masterview gems for easy installation" s.has_rdoc = true s.files = PKG_FILES s.require_path = '.' s.extra_rdoc_files = ['README'] s.add_dependency( 'masterview', ">= #{PKG_VERSION}" ) s.add_dependency( 'masterview_generator', ">= #{PKG_VERSION}" ) s.add_dependency( 'masterview_plugin_generator', ">= #{PKG_VERSION}" ) s.author = "Jeff Barczewski" s.email = "jeff.barczewski@gmail.com" s.homepage = "http://masterview.org/" end # Create Rubygem package Rake::GemPackageTask.new(spec) do |p| p.gem_spec = spec p.need_tar = false p.need_zip = false end desc "Release files on RubyForge." task :release_files => [ :verify_rubyforge ] do release_files = ["gem"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" } Rake::XForge::Release.new(MASTERVIEW) do |release| release.user_name = ENV['RUBYFORGE_USER'] release.password = ENV['RUBYFORGE_PASSWORD'] release.files = release_files.to_a release.release_name = RELEASE_NAME release.package_name = PKG_NAME notes = [] File.open("RELEASE_NOTES") do |file| file.each do |line| line.chomp! line.gsub!(/^#.*$/, '') and next notes << line end end release.release_notes = notes.join("\n") changes = [] File.open("CHANGELOG") do |file| current = true file.each do |line| line.chomp! current = false if current and line =~ /^==/ break if line.empty? and not current changes << line end end release.release_changes = changes.join("\n") end end end end namespace 'masterview' do module MasterViewGem PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : '' PKG_NAME = 'masterview' PKG_VERSION = MasterView::VERSION::STRING + PKG_BUILD PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}" RELEASE_NAME = "REL #{PKG_VERSION}" PKG_INCLUDES = PKG_FILES_RUNTIME + PKG_FILES_DOCS + PKG_FILES_TESTS + PKG_FILES_RELEASE_DOCS PKG_FILES = FileList.new( PKG_INCLUDES ).exclude( PKG_FILES_EXCLUDE_PATTERN ) spec = Gem::Specification.new do |s| s.name = PKG_NAME s.version = PKG_VERSION s.summary = "A (x)html friendly template engine for rails with the power of layouts, and partials. " s.has_rdoc = true s.files = PKG_FILES s.require_path = 'lib' s.autorequire = 'masterview' s.extra_rdoc_files = ['README'] s.author = "Jeff Barczewski" s.email = "jeff.barczewski@gmail.com" s.homepage = "http://masterview.org/" end # Create Rubygem package Rake::GemPackageTask.new(spec) do |p| p.gem_spec = spec p.need_tar = false p.need_zip = false end desc "Release files on RubyForge." task :release_files => [ :verify_rubyforge ] do release_files = ["gem"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" } Rake::XForge::Release.new(MASTERVIEW) do |release| release.user_name = ENV['RUBYFORGE_USER'] release.password = ENV['RUBYFORGE_PASSWORD'] release.files = release_files.to_a release.release_name = RELEASE_NAME release.package_name = PKG_NAME notes = [] File.open("RELEASE_NOTES") do |file| file.each do |line| line.chomp! line.gsub!(/^#.*$/, '') and next notes << line end end release.release_notes = notes.join("\n") changes = [] File.open("CHANGELOG") do |file| current = true file.each do |line| line.chomp! current = false if current and line =~ /^==/ break if line.empty? and not current changes << line end end release.release_changes = changes.join("\n") end end end end namespace 'masterview_generator' do module MasterViewGenerator PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : '' PKG_NAME = 'masterview_generator' PKG_VERSION = MasterView::VERSION::STRING + PKG_BUILD PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}" RELEASE_NAME = "REL #{PKG_VERSION}" #PKG_INCLUDES = PKG_FILES_MV_GENERATOR #PKG_FILES = FileList.new( PKG_INCLUDES ).exclude( PKG_FILES_EXCLUDE_PATTERN ) desc "Package masterview_generator" task :package do work_dir = Dir.getwd Dir.chdir 'generators/masterview' system( "#{RAKE_PROCESSOR} package" ) Dir.chdir work_dir end desc "Repackage masterview_generator" task :repackage do work_dir = Dir.getwd Dir.chdir 'generators/masterview' system( "#{RAKE_PROCESSOR} repackage" ) Dir.chdir work_dir end desc "Release files on RubyForge." task :release_files => [ :verify_rubyforge ] do release_files = ["gem"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" } Rake::XForge::Release.new(MASTERVIEW) do |release| release.user_name = ENV['RUBYFORGE_USER'] release.password = ENV['RUBYFORGE_PASSWORD'] release.files = release_files.to_a release.release_name = RELEASE_NAME release.package_name = PKG_NAME notes = [] File.open("RELEASE_NOTES") do |file| file.each do |line| line.chomp! line.gsub!(/^#.*$/, '') and next notes << line end end release.release_notes = notes.join("\n") changes = [] File.open("CHANGELOG") do |file| current = true file.each do |line| line.chomp! current = false if current and line =~ /^==/ break if line.empty? and not current changes << line end end release.release_changes = changes.join("\n") end end end end namespace 'masterview_plugin_generator' do module MasterViewGemPluginGenerator PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : '' PKG_NAME = 'masterview_plugin_generator' PKG_VERSION = MasterView::VERSION::STRING + PKG_BUILD PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}" RELEASE_NAME = "REL #{PKG_VERSION}" PKG_INCLUDES = PKG_FILES_MV_PLUGIN_GENERATOR + PKG_FILES_RELEASE_DOCS PKG_FILES = FileList.new( PKG_INCLUDES ).exclude( PKG_FILES_EXCLUDE_PATTERN ) desc "Package masterview_generator" task :package do work_dir = Dir.getwd Dir.chdir 'generators/masterview_plugin' system( "#{RAKE_PROCESSOR} package" ) Dir.chdir work_dir end desc "Repackage masterview_generator" task :repackage do work_dir = Dir.getwd Dir.chdir 'generators/masterview_plugin' system( "#{RAKE_PROCESSOR} repackage" ) Dir.chdir work_dir end desc "Release files on RubyForge." task :release_files => [ :verify_rubyforge ] do release_files = ["gem"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" } Rake::XForge::Release.new(MASTERVIEW) do |release| release.user_name = ENV['RUBYFORGE_USER'] release.password = ENV['RUBYFORGE_PASSWORD'] release.files = release_files.to_a release.release_name = RELEASE_NAME release.package_name = PKG_NAME notes = [] File.open("RELEASE_NOTES") do |file| file.each do |line| line.chomp! line.gsub!(/^#.*$/, '') and next notes << line end end release.release_notes = notes.join("\n") changes = [] File.open("CHANGELOG") do |file| current = true file.each do |line| line.chomp! current = false if current and line =~ /^==/ break if line.empty? and not current changes << line end end release.release_changes = changes.join("\n") end end end end desc "Publish news on RubyForge" task :publish_news => [ :verify_rubyforge, :tar, :gem, :demotar] do Rake::XForge::NewsPublisher.new(Ruby_PDF) do |news| news.user_name = ENV['RUBYFORGE_USER'] news.password = ENV['RUBYFORGE_PASSWORD'] news.subject = "PDF::Writer #{PDF::Writer::VERSION} Released" news.changes_file = nil details = [] File.open("Release-Announcement") do |file| file.each do |line| line.chomp! break if line =~ /^=/ details << line end end news.details = details.join("\n") end end desc "Post a release announcement via GMail." #task :email_announcement => [ :verify_gmail, :tar, :gem, :demotar] do task :email_announcement => [ :verify_gmail ] do require 'gmailer' GMailer.connect(ENV["GMAIL_USER"], ENV["GMAIL_PASSWORD"]) do |gmail| gmail.send :to => "ruby-talk@ruby-lang.org", :subject => "[ANN] PDF::Writer #{PDF::Writer::VERSION}", :body => File.read("Release-Announcement") end end