From 9db7e3b1ae68ebcfa6fc868a7ca28f1a4544e1d7 Mon Sep 17 00:00:00 2001 From: James Adam Date: Fri, 28 Aug 2009 16:33:36 +0100 Subject: [PATCH] Gracefully ignore gem tasks when rubygems isn't properly available. --- Rakefile | 195 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 99 insertions(+), 96 deletions(-) diff --git a/Rakefile b/Rakefile index d861968..f929157 100644 --- a/Rakefile +++ b/Rakefile @@ -11,112 +11,115 @@ end task :default => :spec - require "rubygems" require "rake/gempackagetask" require "rake/rdoctask" -# This builds the actual gem. For details of what all these options -# mean, and other ones you can add, check the documentation here: -# -# http://rubygems.org/read/chapter/20 -# -spec = Gem::Specification.new do |s| - - # Change these as appropriate - s.name = "vanilla" - s.version = "1.1.0" - s.summary = "A bliki-type web content thing." - s.author = "James Adam" - s.email = "james@lazyatom.com.com" - s.homepage = "http://github.com/lazyatom/vanilla-rb" - - s.has_rdoc = true - s.extra_rdoc_files = %w(README) - s.rdoc_options = %w(--main README) - - # Add any extra files to include in the gem - s.files = %w(config.example.yml config.ru Rakefile README) + Dir.glob("{spec,lib,bin,public}/**/*") - s.executables = ['vanilla'] - s.require_paths = ["lib"] - - # All the other gems we need. - s.add_dependency("rack", ">= 0.9.1") - s.add_dependency("soup", ">= 0.2.1") - s.add_dependency("ratom", ">= 0.3.5") - s.add_dependency("RedCloth", ">= 4.1.1") - s.add_dependency("BlueCloth", ">= 1.0.0") - - s.add_development_dependency("rspec") # add any other gems for testing/development +if Kernel.const_defined?(:Gem) + # This builds the actual gem. For details of what all these options + # mean, and other ones you can add, check the documentation here: + # + # http://rubygems.org/read/chapter/20 + # + spec = Gem::Specification.new do |s| - # If you want to publish automatically to rubyforge, you'll may need - # to tweak this, and the publishing task below too. - s.rubyforge_project = "vanilla" -end + # Change these as appropriate + s.name = "vanilla" + s.version = "1.1.0" + s.summary = "A bliki-type web content thing." + s.author = "James Adam" + s.email = "james@lazyatom.com.com" + s.homepage = "http://github.com/lazyatom/vanilla-rb" -# This task actually builds the gem. We also regenerate a static -# .gemspec file, which is useful if something (i.e. GitHub) will -# be automatically building a gem for this project. If you're not -# using GitHub, edit as appropriate. -Rake::GemPackageTask.new(spec) do |pkg| - pkg.gem_spec = spec - - # Generate the gemspec file for github. - file = File.dirname(__FILE__) + "/#{spec.name}.gemspec" - File.open(file, "w") {|f| f << spec.to_ruby } -end + s.has_rdoc = true + s.extra_rdoc_files = %w(README) + s.rdoc_options = %w(--main README) -# Generate documentation -Rake::RDocTask.new do |rd| - rd.main = "README" - rd.rdoc_files.include("README", "lib/**/*.rb") - rd.rdoc_dir = "rdoc" -end + # Add any extra files to include in the gem + s.files = %w(config.example.yml config.ru Rakefile README) + Dir.glob("{spec,lib,bin,public}/**/*") + s.executables = ['vanilla'] + s.require_paths = ["lib"] -desc 'Clear out RDoc and generated packages' -task :clean => [:clobber_rdoc, :clobber_package] do - rm "#{spec.name}.gemspec" -end + # All the other gems we need. + s.add_dependency("rack", ">= 0.9.1") + s.add_dependency("soup", ">= 0.2.1") + s.add_dependency("ratom", ">= 0.3.5") + s.add_dependency("RedCloth", ">= 4.1.1") + s.add_dependency("BlueCloth", ">= 1.0.0") -# If you want to publish to RubyForge automatically, here's a simple -# task to help do that. If you don't, just get rid of this. -# Be sure to set up your Rubyforge account details with the Rubyforge -# gem; you'll need to run `rubyforge setup` and `rubyforge config` at -# the very least. -begin - require "rake/contrib/sshpublisher" - namespace :rubyforge do - - desc "Release gem and RDoc documentation to RubyForge" - task :release => ["rubyforge:release:gem", "rubyforge:release:docs"] - - namespace :release do - desc "Release a new version of this gem" - task :gem => [:package] do - require 'rubyforge' - rubyforge = RubyForge.new - rubyforge.configure - rubyforge.login - rubyforge.userconfig['release_notes'] = spec.summary - path_to_gem = File.join(File.dirname(__FILE__), "pkg", "#{spec.name}-#{spec.version}.gem") - puts "Publishing #{spec.name}-#{spec.version.to_s} to Rubyforge..." - rubyforge.add_release(spec.rubyforge_project, spec.name, spec.version.to_s, path_to_gem) - end - - desc "Publish RDoc to RubyForge." - task :docs => [:rdoc] do - config = YAML.load( - File.read(File.expand_path('~/.rubyforge/user-config.yml')) - ) - - host = "#{config['username']}@rubyforge.org" - remote_dir = "/var/www/gforge-projects/vanilla-rb/" # Should be the same as the rubyforge project name - local_dir = 'rdoc' - - Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload + s.add_development_dependency("rspec") # add any other gems for testing/development + + # If you want to publish automatically to rubyforge, you'll may need + # to tweak this, and the publishing task below too. + s.rubyforge_project = "vanilla" + end + + # This task actually builds the gem. We also regenerate a static + # .gemspec file, which is useful if something (i.e. GitHub) will + # be automatically building a gem for this project. If you're not + # using GitHub, edit as appropriate. + Rake::GemPackageTask.new(spec) do |pkg| + pkg.gem_spec = spec + + # Generate the gemspec file for github. + file = File.dirname(__FILE__) + "/#{spec.name}.gemspec" + File.open(file, "w") {|f| f << spec.to_ruby } + end + + # Generate documentation + Rake::RDocTask.new do |rd| + rd.main = "README" + rd.rdoc_files.include("README", "lib/**/*.rb") + rd.rdoc_dir = "rdoc" + end + + desc 'Clear out RDoc and generated packages' + task :clean => [:clobber_rdoc, :clobber_package] do + rm "#{spec.name}.gemspec" + end + + # If you want to publish to RubyForge automatically, here's a simple + # task to help do that. If you don't, just get rid of this. + # Be sure to set up your Rubyforge account details with the Rubyforge + # gem; you'll need to run `rubyforge setup` and `rubyforge config` at + # the very least. + begin + require "rake/contrib/sshpublisher" + namespace :rubyforge do + + desc "Release gem and RDoc documentation to RubyForge" + task :release => ["rubyforge:release:gem", "rubyforge:release:docs"] + + namespace :release do + desc "Release a new version of this gem" + task :gem => [:package] do + require 'rubyforge' + rubyforge = RubyForge.new + rubyforge.configure + rubyforge.login + rubyforge.userconfig['release_notes'] = spec.summary + path_to_gem = File.join(File.dirname(__FILE__), "pkg", "#{spec.name}-#{spec.version}.gem") + puts "Publishing #{spec.name}-#{spec.version.to_s} to Rubyforge..." + rubyforge.add_release(spec.rubyforge_project, spec.name, spec.version.to_s, path_to_gem) + end + + desc "Publish RDoc to RubyForge." + task :docs => [:rdoc] do + config = YAML.load( + File.read(File.expand_path('~/.rubyforge/user-config.yml')) + ) + + host = "#{config['username']}@rubyforge.org" + remote_dir = "/var/www/gforge-projects/vanilla-rb/" # Should be the same as the rubyforge project name + local_dir = 'rdoc' + + Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload + end end end + rescue LoadError + puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured." end -rescue LoadError - puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured." +else + puts "Gem management tasks unavailable, as rubygems was not fully loaded." end \ No newline at end of file