~ubuntu-branches/ubuntu/lucid/jruby/lucid

« back to all changes in this revision

Viewing changes to lib/ruby/1.9/rake/gempackagetask.rb

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Delafond
  • Date: 2009-12-09 17:30:55 UTC
  • Revision ID: james.westby@ubuntu.com-20091209173055-8ffzikq1768gywux
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
# Define a package task library to aid in the definition of GEM
 
4
# packages.
 
5
 
 
6
require 'rubygems'
 
7
require 'rake'
 
8
require 'rake/packagetask'
 
9
require 'rubygems/user_interaction'
 
10
require 'rubygems/builder'
 
11
 
 
12
module Rake
 
13
 
 
14
  # Create a package based upon a Gem spec.  Gem packages, as well as
 
15
  # zip files and tar/gzipped packages can be produced by this task.
 
16
  #
 
17
  # In addition to the Rake targets generated by PackageTask, a
 
18
  # GemPackageTask will also generate the following tasks:
 
19
  #
 
20
  # [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.gem"</b>]
 
21
  #   Create a Ruby GEM package with the given name and version.
 
22
  #
 
23
  # Example using a Ruby GEM spec:
 
24
  #
 
25
  #   require 'rubygems'
 
26
  #
 
27
  #   spec = Gem::Specification.new do |s|
 
28
  #     s.platform = Gem::Platform::RUBY
 
29
  #     s.summary = "Ruby based make-like utility."
 
30
  #     s.name = 'rake'
 
31
  #     s.version = PKG_VERSION
 
32
  #     s.requirements << 'none'
 
33
  #     s.require_path = 'lib'
 
34
  #     s.autorequire = 'rake'
 
35
  #     s.files = PKG_FILES
 
36
  #     s.description = <<EOF
 
37
  #   Rake is a Make-like program implemented in Ruby. Tasks
 
38
  #   and dependencies are specified in standard Ruby syntax. 
 
39
  #   EOF
 
40
  #   end
 
41
  #   
 
42
  #   Rake::GemPackageTask.new(spec) do |pkg|
 
43
  #     pkg.need_zip = true
 
44
  #     pkg.need_tar = true
 
45
  #   end
 
46
  #
 
47
  class GemPackageTask < PackageTask
 
48
    # Ruby GEM spec containing the metadata for this package.  The
 
49
    # name, version and package_files are automatically determined
 
50
    # from the GEM spec and don't need to be explicitly provided.
 
51
    attr_accessor :gem_spec
 
52
 
 
53
    # Create a GEM Package task library.  Automatically define the gem
 
54
    # if a block is given.  If no block is supplied, then +define+
 
55
    # needs to be called to define the task.
 
56
    def initialize(gem_spec)
 
57
      init(gem_spec)
 
58
      yield self if block_given?
 
59
      define if block_given?
 
60
    end
 
61
 
 
62
    # Initialization tasks without the "yield self" or define
 
63
    # operations.
 
64
    def init(gem)
 
65
      super(gem.name, gem.version)
 
66
      @gem_spec = gem
 
67
      @package_files += gem_spec.files if gem_spec.files
 
68
    end
 
69
 
 
70
    # Create the Rake tasks and actions specified by this
 
71
    # GemPackageTask.  (+define+ is automatically called if a block is
 
72
    # given to +new+).
 
73
    def define
 
74
      super
 
75
      task :package => [:gem]
 
76
      desc "Build the gem file #{gem_file}"
 
77
      task :gem => ["#{package_dir}/#{gem_file}"]
 
78
      file "#{package_dir}/#{gem_file}" => [package_dir] + @gem_spec.files do
 
79
        when_writing("Creating GEM") {
 
80
          Gem::Builder.new(gem_spec).build
 
81
          verbose(true) {
 
82
            mv gem_file, "#{package_dir}/#{gem_file}"
 
83
          }
 
84
        }
 
85
      end
 
86
    end
 
87
    
 
88
    def gem_file
 
89
      if @gem_spec.platform == Gem::Platform::RUBY
 
90
        "#{package_name}.gem"
 
91
      else
 
92
        "#{package_name}-#{@gem_spec.platform}.gem"
 
93
      end
 
94
    end
 
95
    
 
96
  end
 
97
end