Buildr C0 Coverage Information - RCov

lib/buildr/packaging/gems.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/buildr/packaging/gems.rb 105 70
38.10%
42.86%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements.  See the NOTICE file distributed with this
3 # work for additional information regarding copyright ownership.  The ASF
4 # licenses this file to you under the Apache License, Version 2.0 (the
5 # "License"); you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
13 # License for the specific language governing permissions and limitations under
14 # the License.
15 
16 
17 require 'buildr/packaging/package'
18 require 'buildr/packaging/archive'
19 gem 'rubyforge' ; autoload :RubyForge, 'rubyforge'
20 Gem.autoload :Package, 'rubygems/package'
21 
22 
23 module Buildr
24 
25   class PackageGemTask < ArchiveTask
26 
27     def initialize(*args)
28       super
29       @spec = Gem::Specification.new
30       prepare do
31         include(changelog) if changelog
32       end
33     end
34 
35     attr_accessor :changelog
36 
37     def spec
38       yield @spec if block_given?
39       @spec
40     end
41 
42     def install
43       Util::Gems.command 'install', name
44     end
45 
46     def uninstall
47       Util::Gems.command 'uninstall', spec.name, '-v', spec.version.to_s
48     end
49 
50     def upload
51       rubyforge = RubyForge.new
52       rubyforge.login
53       rubyforge.userconfig.merge!('release_changes'=>changelog.to_s, 'preformatted'=>true) if changelog
54       rubyforge.add_release spec.rubyforge_project.downcase, spec.name.downcase, spec.version, package(:gem).to_s
55     end
56 
57   private
58 
59     def create_from(file_map)
60       spec.mark_version
61       spec.validate
62 
63       File.open(name, 'wb') do |io|
64         Gem::Package.open(io, 'w', nil) do |pkg|
65           pkg.metadata = spec.to_yaml
66           file_map.each do |path, content|
67             next if content.nil? || File.directory?(content.to_s)
68             pkg.add_file_simple(path, File.stat(content.to_s).mode & 0777, File.size(content.to_s)) do |os|
69               File.open(content.to_s, "rb") do |file|
70                 os.write file.read(4096)  until file.eof?
71               end
72             end
73           end
74         end
75       end
76     end
77 
78   end
79 
80 
81   module PackageAsGem #:nodoc:
82 
83     def package_as_gem(file_name) #:nodoc:
84       PackageGemTask.define_task(file_name).tap do |gem|
85         %w{ lib test doc }.each do |dir|
86           gem.include :from=>_(dir), :path=>dir if File.directory?(_(dir))
87         end
88         gem.spec do |spec|
89           spec.name = id
90           spec.version = version.gsub('-','.') # RubyGems doesn't like '-' in version numbers
91           spec.summary = full_comment
92           spec.has_rdoc = true
93           spec.rdoc_options << '--title' << comment
94           spec.require_path = 'lib'
95         end
96       end
97     end
98 
99   end
100 
101   class Project
102     include PackageAsGem
103   end
104 
105 end

Generated on 2011-07-06 23:35:38 -0700 with rcov 0.9.8