Skip to content

Commit

Permalink
Spiked support for checking dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
technicalpickles committed Aug 6, 2009
1 parent c064035 commit 6abd53c
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 27 deletions.
29 changes: 2 additions & 27 deletions Rakefile
Expand Up @@ -96,31 +96,6 @@ else
task :default => :test
end

namespace :development_dependencies do
task :check do
missing_dependencies = Rake.application.jeweler.gemspec.development_dependencies.select do |dependency|
begin
Gem.activate dependency.name, dependency.version_requirements.to_s
false
rescue LoadError => e
true
end
end

#require 'ruby-debug'; breakpoint

if missing_dependencies.empty?
puts "Development dependencies seem to be installed."
else
puts "Missing some dependencies. Install them with the following commands:"
missing_dependencies.each do |dependency|
puts %Q{\tgem install #{dependency.name} --version "#{dependency.version_requirements}"}
end
abort "Run the specified gem commands before trying to run this again: #{$0} #{ARGV.join(' ')}"
end

end
end

task :test => 'development_dependencies:check'
task :features => 'development_dependencies:check'
task :test => :check_dependencies
task :features => :check_dependencies
6 changes: 6 additions & 0 deletions lib/jeweler.rb
Expand Up @@ -129,6 +129,12 @@ def setup_rubyforge
Jeweler::Commands::SetupRubyforge.build_for(self).run
end

def check_dependencies(type = nil)
command = Jeweler::Commands::CheckDependencies.build_for(self)
command.type = type

command.run
end

def in_git_repo?
File.exists?(File.join(self.base_dir, '.git'))
Expand Down
1 change: 1 addition & 0 deletions lib/jeweler/commands.rb
@@ -1,5 +1,6 @@
require 'jeweler/commands/build_gem'
require 'jeweler/commands/install_gem'
require 'jeweler/commands/check_dependencies'
require 'jeweler/commands/release'
require 'jeweler/commands/release_to_rubyforge'
require 'jeweler/commands/setup_rubyforge'
Expand Down
52 changes: 52 additions & 0 deletions lib/jeweler/commands/check_dependencies.rb
@@ -0,0 +1,52 @@
class Jeweler
module Commands
class CheckDependencies
class MissingDependenciesError < RuntimeError
attr_accessor :dependencies, :type
end

attr_accessor :gemspec, :type

def run
missing_dependencies = dependencies.select do |dependency|
begin
Gem.activate dependency.name, dependency.version_requirements.to_s
false
rescue LoadError => e
true
end
end

if missing_dependencies.empty?
puts "#{type || 'All'} dependencies seem to be installed."
else
puts "Missing some dependencies. Install them with the following commands:"
missing_dependencies.each do |dependency|
puts %Q{\tgem install #{dependency.name} --version "#{dependency.version_requirements}"}
end

abort "Run the specified gem commands before trying to run this again: #{$0} #{ARGV.join(' ')}"
end

end

def dependencies
case type
when :runtime, :development
gemspec.send("#{type}_dependencies")
else
gemspec.dependencies
end

end

def self.build_for(jeweler)
command = new

command.gemspec = jeweler.gemspec

command
end
end
end
end
18 changes: 18 additions & 0 deletions lib/jeweler/tasks.rb
Expand Up @@ -111,6 +111,24 @@ def define
task :release do
jeweler.release
end

desc "Check that runtime and development dependencies are installed"
task :check_dependencies do
jeweler.check_dependencies
end

namespace :check_dependencies do
desc "Check that runtime dependencies are installed"
task :runtime do
jeweler.check_dependencies(:runtime)
end

desc"Check that development dependencies are installed"
task :development do
jeweler.check_dependencies(:development)
end

end

end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/jeweler/templates/Rakefile
Expand Up @@ -75,10 +75,14 @@ rescue LoadError
end
<% end %>
task :<%= test_task %> => :check_dependencies
<% if should_use_cucumber %>
begin
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features)
task :features => :check_dependencies
rescue LoadError
task :features do
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
Expand Down

0 comments on commit 6abd53c

Please sign in to comment.