C0 code coverage information

Generated on Wed Oct 07 08:34:05 -0700 2009 with rcov 0.8.2.1


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.
Name Total lines Lines of code Total coverage Code coverage
lib/buildr/packaging/package.rb 238 107
97.9%  
95.3%  
  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/core/project'
 18 require 'buildr/core/compile'
 19 require 'buildr/packaging/artifact'
 20 
 21 
 22 module Buildr
 23   # Methods added to Project to support packaging and tasks for packaging,
 24   # installing and uploading packages.
 25   module Package
 26 
 27     include Extension
 28 
 29     first_time do
 30       desc 'Create packages'
 31       Project.local_task('package'=>'build') { |name| "Packaging #{name}" }
 32       desc 'Install packages created by the project'
 33       Project.local_task('install'=>'package') { |name| "Installing packages from #{name}" }
 34       desc 'Remove previously installed packages'
 35       Project.local_task('uninstall') { |name| "Uninstalling packages from #{name}" }
 36       desc 'Upload packages created by the project'
 37       Project.local_task('upload'=>'package') { |name| "Deploying packages from #{name}" }
 38       # Anything that comes after local packaging (install, upload) executes the integration tests,
 39       # which do not conflict with integration invoking the project's own packaging (package=>
 40       # integration=>foo:package is not circular, just confusing to debug.)
 41       task 'package' do
 42         task('integration').invoke if Buildr.options.test && Buildr.application.original_dir == Dir.pwd
 43       end
 44     end
 45 
 46     before_define do |project|
 47       [ :package, :install, :uninstall, :upload ].each { |name| project.recursive_task name }
 48       # Need to run build before package, since package is often used as a dependency by tasks that
 49       # expect build to happen.
 50       project.task('package'=>project.task('build'))
 51       project.group ||= project.parent && project.parent.group || project.name
 52       project.version ||= project.parent && project.parent.version
 53     end
 54 
 55     # The project's identifier. Same as the project name, with colons replaced by dashes.
 56     # The ID for project foo:bar is foo-bar.
 57     def id
 58       name.gsub(':', '-')
 59     end
 60 
 61     # Group used for packaging. Inherited from parent project. Defaults to the top-level project name.
 62     attr_accessor :group
 63 
 64     # Version used for packaging. Inherited from parent project.
 65     attr_accessor :version
 66 
 67     # :call-seq:
 68     #   package(type, spec?) => task
 69     #
 70     # Defines and returns a package created by this project.
 71     #
 72     # The first argument declares the package type. For example, :jar to create a JAR file.
 73     # The package is an artifact that takes its artifact specification from the project.
 74     # You can override the artifact specification by passing various options in the second
 75     # argument, for example:
 76     #   package(:zip, :classifier=>'sources')
 77     #
 78     # Packages that are ZIP files provides various ways to include additional files, directories,
 79     # and even merge ZIPs together. Have a look at ZipTask for more information. In case you're
 80     # wondering, JAR and WAR packages are ZIP files.
 81     #
 82     # You can also enhance a JAR package using the ZipTask#with method that accepts the following options:
 83     # * :manifest -- Specifies how to create the MANIFEST.MF. By default, uses the project's
 84     #   #manifest property.
 85     # * :meta_inf -- Specifies files to be included in the META-INF directory. By default,
 86     #   uses the project's #meta-inf property.
 87     #
 88     # The WAR package supports the same options and adds a few more:
 89     # * :classes -- Directories of class files to include in WEB-INF/classes. Includes the compile
 90     #   target directory by default.
 91     # * :libs -- Artifacts and files to include in WEB-INF/libs. Includes the compile classpath
 92     #   dependencies by default.
 93     #
 94     # For example:
 95     #   define 'project' do
 96     #     define 'beans' do
 97     #       package :jar
 98     #     end
 99     #     define 'webapp' do
100     #       compile.with project('beans')
101     #       package(:war).with :libs=>MYSQL_JDBC
102     #     end
103     #     package(:zip, :classifier=>'sources').include path_to('.')
104     #  end
105     #
106     # Two other packaging types are:
107     # * package :sources -- Creates a ZIP file with the source code and classifier 'sources', for use by IDEs.
108     # * package :javadoc -- Creates a ZIP file with the Javadocs and classifier 'javadoc'. You can use the
109     #   javadoc method to further customize it.
110     #
111     # A package is also an artifact. The following tasks operate on packages created by the project:
112     #   buildr upload     # Upload packages created by the project
113     #   buildr install    # Install packages created by the project
114     #   buildr package    # Create packages
115     #   buildr uninstall  # Remove previously installed packages
116     #
117     # If you want to add additional packaging types, implement a method with the name package_as_[type]
118     # that accepts a file name and returns an appropriate Rake task.  For example:
119     #   def package_as_zip(file_name) #:nodoc:
120     #     ZipTask.define_task(file_name)
121     #   end
122     #
123     # The file name is determined from the specification passed to the package method, however, some
124     # packagers need to override this.  For example, package(:sources) produces a file with the extension
125     # 'zip' and the classifier 'sources'.  If you need to overwrite the default implementation, you should
126     # also include a method named package_as_[type]_respec.  For example:
127     #   def package_as_sources_spec(spec) #:nodoc:
128     #     { :type=>:zip, :classifier=>'sources' }.merge(spec)
129     #   end
130     def package(*args)
131       spec = Hash === args.last ? args.pop.dup : {}
132       no_options = spec.empty? # since spec is mutated
133       if spec[:file]
134         rake_check_options spec, :file, :type
135         spec[:type] = args.shift || spec[:type] || spec[:file].split('.').last
136         file_name = spec[:file]
137       else
138         rake_check_options spec, *ActsAsArtifact::ARTIFACT_ATTRIBUTES
139         spec[:id] ||= self.id
140         spec[:group] ||= self.group
141         spec[:version] ||= self.version
142         spec[:type] = args.shift || spec[:type] || compile.packaging || :zip
143       end
144 
145       packager = method("package_as_#{spec[:type]}") rescue fail("Don't know how to create a package of type #{spec[:type]}")
146       if packager.arity == 1
147         unless file_name
148           spec = send("package_as_#{spec[:type]}_spec", spec) if respond_to?("package_as_#{spec[:type]}_spec")
149           file_name = path_to(:target, Artifact.hash_to_file_name(spec))
150         end
151         package = (no_options && packages.detect { |pkg| pkg.type == spec[:type] && 
152                   (spec[:classifier].nil? || pkg.classifier == spec[:classifier])}) ||
153           packages.find { |pkg| pkg.name == file_name }                             ||
154           packager.call(file_name)
155       else
156         Buildr.application.deprecated "We changed the way package_as methods are implemented.  See the package method documentation for more details."
157         file_name ||= path_to(:target, Artifact.hash_to_file_name(spec))
158         package = packager.call(file_name, spec)
159       end
160 
161       # First time: prepare package for install, uninstall and upload tasks.
162       unless packages.include?(package)
163         # We already run build before package, but we also need to do so if the package itself is
164         # used as a dependency, before we get to run the package task.
165         task 'package'=>package
166         package.enhance [task('build')]
167         package.enhance { info "Packaging #{File.basename(file_name)}" }
168 
169         if spec[:file]
170           class << package ; self ; end.send(:define_method, :type) { spec[:type] }
171         else
172           # Make it an artifact using the specifications, and tell it how to create a POM.
173           package.extend ActsAsArtifact
174           package.send :apply_spec, spec.only(*Artifact::ARTIFACT_ATTRIBUTES)
175           # Another task to create the POM file.
176           pom = package.pom
177           pom.enhance do
178             mkpath File.dirname(pom.name)
179             File.open(pom.name, 'w') { |file| file.write pom.pom_xml }
180           end
181           file(Buildr.repositories.locate(package)=>package) { package.install }
182 
183           # Add the package to the list of packages created by this project, and
184           # register it as an artifact. The later is required so if we look up the spec
185           # we find the package in the project's target directory, instead of finding it
186           # in the local repository and attempting to install it.
187           Artifact.register package, pom
188         end
189 
190         task('install')   { package.install if package.respond_to?(:install) }
191         task('uninstall') { package.uninstall if package.respond_to?(:uninstall) }
192         task('upload')    { package.upload if package.respond_to?(:upload) }
193 
194         packages << package
195       end
196       package
197     end
198 
199     # :call-seq:
200     #   packages => tasks
201     #
202     # Returns all packages created by this project. A project may create any number of packages.
203     #
204     # This method is used whenever you pass a project to Buildr#artifact or any other method
205     # that accepts artifact specifications and projects. You can use it to list all packages
206     # created by the project. If you want to return a specific package, it is often more
207     # convenient to call #package with the type.
208     def packages
209       @packages ||= []
210     end
211 
212   protected
213 
214     def package_as_zip(file_name) #:nodoc:
215       ZipTask.define_task(file_name)
216     end
217 
218     def package_as_tar(file_name) #:nodoc:
219       TarTask.define_task(file_name)
220     end
221     alias :package_as_tgz :package_as_tar
222 
223     def package_as_sources_spec(spec) #:nodoc:
224       spec.merge(:type=>:zip, :classifier=>'sources')
225     end
226 
227     def package_as_sources(file_name) #:nodoc:
228       ZipTask.define_task(file_name).tap do |zip|
229         zip.include :from=>compile.sources
230       end
231     end
232 
233   end
234 end
235 
236 class Buildr::Project
237   include Buildr::Package
238 end

Generated using the rcov code coverage analysis tool for Ruby version 0.8.2.1.

Valid XHTML 1.0! Valid CSS!