/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. require 'rubygems'
  22. begin
  23. gem 'rake'
  24. rescue Gem::LoadError
  25. end
  26. require 'rake/packagetask'
  27. ##
  28. # Create a package based upon a Gem::Specification. Gem packages, as well as
  29. # zip files and tar/gzipped packages can be produced by this task.
  30. #
  31. # In addition to the Rake targets generated by Rake::PackageTask, a
  32. # Gem::PackageTask will also generate the following tasks:
  33. #
  34. # [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.gem"</b>]
  35. # Create a RubyGems package with the given name and version.
  36. #
  37. # Example using a Gem::Specification:
  38. #
  39. # require 'rubygems'
  40. # require 'rubygems/package_task'
  41. #
  42. # spec = Gem::Specification.new do |s|
  43. # s.platform = Gem::Platform::RUBY
  44. # s.summary = "Ruby based make-like utility."
  45. # s.name = 'rake'
  46. # s.version = PKG_VERSION
  47. # s.requirements << 'none'
  48. # s.require_path = 'lib'
  49. # s.autorequire = 'rake'
  50. # s.files = PKG_FILES
  51. # s.description = <<-EOF
  52. # Rake is a Make-like program implemented in Ruby. Tasks
  53. # and dependencies are specified in standard Ruby syntax.
  54. # EOF
  55. # end
  56. #
  57. # Gem::PackageTask.new(spec) do |pkg|
  58. # pkg.need_zip = true
  59. # pkg.need_tar = true
  60. # end
  61. class Gem::PackageTask < Rake::PackageTask
  62. ##
  63. # Ruby Gem::Specification containing the metadata for this package. The
  64. # name, version and package_files are automatically determined from the
  65. # gemspec and don't need to be explicitly provided.
  66. attr_accessor :gem_spec
  67. ##
  68. # Create a Gem Package task library. Automatically define the gem if a
  69. # block is given. If no block is supplied, then #define needs to be called
  70. # to define the task.
  71. def initialize(gem_spec)
  72. init gem_spec
  73. yield self if block_given?
  74. define if block_given?
  75. end
  76. ##
  77. # Initialization tasks without the "yield self" or define operations.
  78. def init(gem)
  79. super gem.full_name, :noversion
  80. @gem_spec = gem
  81. @package_files += gem_spec.files if gem_spec.files
  82. end
  83. ##
  84. # Create the Rake tasks and actions specified by this Gem::PackageTask.
  85. # (+define+ is automatically called if a block is given to +new+).
  86. def define
  87. super
  88. task :package => [:gem]
  89. gem_file = gem_spec.file_name
  90. gem_path = File.join package_dir, gem_file
  91. gem_dir = File.join package_dir, gem_spec.full_name
  92. desc "Build the gem file #{gem_file}"
  93. task :gem => [gem_path]
  94. trace = Rake.application.options.trace
  95. Gem.configuration.verbose = trace
  96. file gem_path => [package_dir, gem_dir] + @gem_spec.files do
  97. chdir(gem_dir) do
  98. when_writing "Creating #{gem_spec.file_name}" do
  99. Gem::Builder.new(gem_spec).build
  100. verbose trace do
  101. mv gem_file, '..'
  102. end
  103. end
  104. end
  105. end
  106. end
  107. end