module RJack::TarPit::GemTaskDefiner

Attributes

need_tar[RW]

Should package create a tarball? (default: false)

need_zip[RW]

Should package create a zipfile? (default: false)

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/rjack-tarpit/gem.rb, line 29
def initialize
  super

  @need_tar = false
  @need_zip = false

  add_define_hook( :define_gem_tasks )
end

Public Instance Methods

define_gem_tasks() click to toggle source
# File lib/rjack-tarpit/gem.rb, line 38
def define_gem_tasks

  Gem::PackageTask.new( spec ) do |pkg|
    pkg.need_tar = @need_tar
    pkg.need_zip = @need_zip
  end

  desc 'Dump plain ruby Gem::Specification'
  task :debug_gem do
    puts spec.to_ruby
  end

  desc "gem push (gemcutter)"
  task :push => [ :gem ] do
    require 'rubygems'
    require 'rubygems/command_manager'
    cm = Gem::CommandManager.instance
    cm.run( gem_config( 'push', '-V', gem_file ) )
  end

  desc "gem(+maven) install"
  task :install => [ :gem ] do
    require 'rubygems'
    require 'rubygems/command_manager'
    cm = Gem::CommandManager.instance
    begin
      cm.run( gem_config( 'install', '--local', '-V', gem_file ) )
    rescue Gem::SystemExitException => x
      raise "Install failed (#{x.exit_code})" if x.exit_code != 0
    end
  end

  desc "gem install missing/all dev dependencies"
  task( :install_deps, :force ) do |t,args|
    require 'rubygems'
    require 'rubygems/command_manager'
    force = ( args[:force] == 'force' )
    @spec.dependencies.each do |dep|
      if force
        gem_install_dep( dep )
      else
        begin
          gem( *dep )
        rescue Gem::LoadError => e
          puts "Gem dep: " + e.to_s
          gem_install_dep( dep )
        end
      end
    end
  end
end
gem_config( command, *args ) click to toggle source
# File lib/rjack-tarpit/gem.rb, line 108
def gem_config( command, *args )
  cargs = [ 'gem', command ].map do |cmd|
    conf = Gem.configuration[ cmd ]
    conf.is_a?( String ) ? conf.split( ' ' ) : Array( conf )
  end
  cargs.flatten!
  [ command ] + cargs + args
end
gem_file() click to toggle source
# File lib/rjack-tarpit/gem.rb, line 100
def gem_file
  parts = [ spec.name, spec.version ]
  p = spec.platform
  parts << 'java' if p.respond_to?( :os ) && p.os == 'java'

  "pkg/#{ parts.join( '-' ) }.gem"
end
gem_install_dep( dep ) click to toggle source
# File lib/rjack-tarpit/gem.rb, line 90
def gem_install_dep( dep )
  puts "Install: " + dep.inspect
  cm = Gem::CommandManager.instance
  c = [ 'install', '--remote', '-V', dep.name ]
  c += dep.requirement.as_list.map { |r| [ '-v', r ] }.flatten
  cm.run( gem_config( *c ) )
rescue Gem::SystemExitException => x
  raise "Install failed (#{x.exit_code})" if x.exit_code != 0
end