PageRenderTime 64ms CodeModel.GetById 54ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/tools/Ruby/lib/ruby/site_ruby/1.8/rubygems/package_task.rb

http://github.com/agross/netopenspace
Ruby | 126 lines | 40 code | 19 blank | 67 comment | 3 complexity | bd92d8c79e9e222672e6718b447511b1 MD5 | raw file
  1# Copyright (c) 2003, 2004 Jim Weirich, 2009 Eric Hodel
  2#
  3# Permission is hereby granted, free of charge, to any person obtaining
  4# a copy of this software and associated documentation files (the
  5# "Software"), to deal in the Software without restriction, including
  6# without limitation the rights to use, copy, modify, merge, publish,
  7# distribute, sublicense, and/or sell copies of the Software, and to
  8# permit persons to whom the Software is furnished to do so, subject to
  9# the following conditions:
 10#
 11# The above copyright notice and this permission notice shall be
 12# included in all copies or substantial portions of the Software.
 13#
 14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 15# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 16# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 17# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 18# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 19# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21
 22require 'rubygems'
 23begin
 24  gem 'rake'
 25rescue Gem::LoadError
 26end
 27
 28require 'rake/packagetask'
 29
 30##
 31# Create a package based upon a Gem::Specification.  Gem packages, as well as
 32# zip files and tar/gzipped packages can be produced by this task.
 33#
 34# In addition to the Rake targets generated by Rake::PackageTask, a
 35# Gem::PackageTask will also generate the following tasks:
 36#
 37# [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.gem"</b>]
 38#   Create a RubyGems package with the given name and version.
 39#
 40# Example using a Gem::Specification:
 41#
 42#   require 'rubygems'
 43#   require 'rubygems/package_task'
 44#
 45#   spec = Gem::Specification.new do |s|
 46#     s.platform = Gem::Platform::RUBY
 47#     s.summary = "Ruby based make-like utility."
 48#     s.name = 'rake'
 49#     s.version = PKG_VERSION
 50#     s.requirements << 'none'
 51#     s.require_path = 'lib'
 52#     s.autorequire = 'rake'
 53#     s.files = PKG_FILES
 54#     s.description = <<-EOF
 55#   Rake is a Make-like program implemented in Ruby. Tasks
 56#   and dependencies are specified in standard Ruby syntax.
 57#     EOF
 58#   end
 59#
 60#   Gem::PackageTask.new(spec) do |pkg|
 61#     pkg.need_zip = true
 62#     pkg.need_tar = true
 63#   end
 64
 65class Gem::PackageTask < Rake::PackageTask
 66
 67  ##
 68  # Ruby Gem::Specification containing the metadata for this package.  The
 69  # name, version and package_files are automatically determined from the
 70  # gemspec and don't need to be explicitly provided.
 71
 72  attr_accessor :gem_spec
 73
 74  ##
 75  # Create a Gem Package task library.  Automatically define the gem if a
 76  # block is given.  If no block is supplied, then #define needs to be called
 77  # to define the task.
 78
 79  def initialize(gem_spec)
 80    init gem_spec
 81    yield self if block_given?
 82    define if block_given?
 83  end
 84
 85  ##
 86  # Initialization tasks without the "yield self" or define operations.
 87
 88  def init(gem)
 89    super gem.full_name, :noversion
 90    @gem_spec = gem
 91    @package_files += gem_spec.files if gem_spec.files
 92  end
 93
 94  ##
 95  # Create the Rake tasks and actions specified by this Gem::PackageTask.
 96  # (+define+ is automatically called if a block is given to +new+).
 97
 98  def define
 99    super
100
101    task :package => [:gem]
102
103    gem_file = gem_spec.file_name
104    gem_path = File.join package_dir, gem_file
105    gem_dir  = File.join package_dir, gem_spec.full_name
106
107    desc "Build the gem file #{gem_file}"
108    task :gem => [gem_path]
109
110    trace = Rake.application.options.trace
111    Gem.configuration.verbose = trace
112
113    file gem_path => [package_dir, gem_dir] + @gem_spec.files do
114      chdir(gem_dir) do
115        when_writing "Creating #{gem_spec.file_name}" do
116          Gem::Builder.new(gem_spec).build
117          verbose trace do
118            mv gem_file, '..'
119          end
120        end
121      end
122    end
123  end
124
125end
126