~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to lib/rake/gempackagetask.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

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