C0 code coverage information

Generated on Wed Oct 07 08:34:01 -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/java/emma.rb 244 161
100.0%  
100.0%  
  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/java'
 18 
 19 
 20 module Buildr
 21 
 22   # Provides the <code>emma:html</code> and <code>emma:xml</code> tasks.
 23   # Require explicitly using <code>require "buildr/emma"</code>.
 24   #
 25   # You can generate emma reports for a single project 
 26   # using the project name as prefix:
 27   #
 28   #   project_name:emma:html
 29   #
 30   # You can also specify which classes to include/exclude from instrumentation by 
 31   # passing a class name regexp to the <code>emma.include</code> or 
 32   # <code>emma.exclude</code> methods. 
 33   # 
 34   #   define 'someModule' do 
 35   #      emma.include 'some.package.*'
 36   #      emma.exclude 'some.foo.util.SimpleUtil'
 37   #   end
 38   module Emma
 39 
 40     VERSION = '2.0.5312'
 41 
 42     class << self
 43 
 44       def version
 45         Buildr.settings.build['emma'] || VERSION
 46       end
 47 
 48       def dependencies
 49         @dependencies ||= ["emma:emma_ant:jar:#{version}", "emma:emma:jar:#{version}"]
 50       end
 51 
 52       def report_to format=nil
 53         File.expand_path('reports/emma')
 54       end
 55 
 56       def data_file()
 57         File.join(report_to, 'coverage.es')
 58       end
 59 
 60       def ant
 61         
 62         Buildr.ant 'emma' do |ant|
 63           ant.taskdef :resource=>'emma_ant.properties',
 64             :classpath=>Buildr.artifacts(dependencies).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
 65           ant.emma :verbosity=>(Buildr.application.options.trace ? 'verbose' : 'warning') do
 66             yield ant
 67           end
 68         end
 69       end
 70     end
 71     
 72     class EmmaConfig # :nodoc:
 73       
 74       def initialize(project)
 75         @project = project
 76       end
 77       
 78       attr_reader :project
 79       private :project
 80 
 81       attr_writer :metadata_file, :coverage_file, :instrumented_dir, :report_dir
 82       
 83       def coverage_file
 84         @coverage_file ||= File.join(report_dir, 'coverage.ec')
 85       end
 86 
 87       def metadata_file
 88         @metadata_file ||= File.join(report_dir, 'coverage.em')
 89       end
 90 
 91       def instrumented_dir
 92         @instrumented_dir ||= project.path_to(:target, :instrumented, :classes)
 93       end
 94 
 95       def report_dir
 96         @report_dir ||= project.path_to(:reports, :emma)
 97       end
 98       
 99       def report_to format
100         report_dir
101       end
102 
103       # :call-seq:
104       #   project.emma.include(*classPatterns)
105       #
106       def include(*classPatterns)
107         includes.push(*classPatterns)
108         self
109       end
110       
111       def includes
112         @includeClasses ||= []
113       end
114 
115       # :call-seq:
116       #   project.emma.exclude(*classPatterns)
117       #
118       def exclude(*classPatterns)
119         excludes.push(*classPatterns)
120         self
121       end
122 
123       def excludes
124         @excludeClasses ||= []
125       end
126 
127       def sources
128         project.compile.sources
129       end
130     end
131 
132     module EmmaExtension # :nodoc:
133       include Buildr::Extension
134 
135       def emma
136         @emma_config ||= EmmaConfig.new(self)
137       end
138 
139       after_define do |project|
140         emma = project.emma
141         
142         namespace 'emma' do
143           unless project.compile.target.nil?
144             # Instrumented bytecode goes in a different directory. This task creates before running the test
145             # cases and monitors for changes in the generate bytecode.
146             instrumented = project.file(emma.instrumented_dir => project.compile.target) do |task|
147               unless project.compile.sources.empty?
148                 info "Instrumenting classes with emma metadata file #{emma.metadata_file}"
149                 Emma.ant do |ant|
150                   ant.instr :instrpath=>project.compile.target.to_s, :destdir=>task.to_s, :metadatafile=>emma.metadata_file do
151                     ant.filter :includes=>emma.includes.join(', ') unless emma.includes.empty?
152                     ant.filter :excludes=>emma.excludes.join(', ') unless emma.excludes.empty?
153                   end
154                 end
155                 touch task.to_s
156               end
157             end
158             
159             task 'instrument' => instrumented
160             
161             # We now have two target directories with bytecode.
162             project.test.dependencies.unshift emma.instrumented_dir
163             project.test.with Emma.dependencies
164             project.test.options[:properties]["emma.coverage.out.file"] = emma.coverage_file
165             
166             [:xml, :html].each do |format|
167               task format => ['instrument', 'test'] do
168                 missing_required_files = [emma.metadata_file, emma.coverage_file].reject { |f| File.exist?(f) }
169                 if missing_required_files.empty?
170                   info "Creating test coverage reports in #{emma.report_dir}"
171                   mkdir_p emma.report_dir
172                   Emma.ant do |ant|
173                     ant.report do
174                       ant.infileset :file=>emma.metadata_file
175                       ant.infileset :file=>emma.coverage_file
176                       ant.send format, :outfile=>File.join(emma.report_to(format),"coverage.#{format}")
177                       ant.sourcepath do
178                         emma.sources.flatten.each do |src|
179                           ant.dirset(:dir=>src.to_s) if File.exist?(src.to_s)
180                         end
181                       end
182                     end
183                   end
184                 else
185                   info "No test coverage report for #{project}. Missing: #{missing_required_files.join(', ')}"
186                 end
187               end
188             end
189           end
190         end
191 
192         project.clean do
193           rm_rf [emma.report_dir, emma.coverage_file, emma.metadata_file, emma.instrumented_dir]
194         end
195         
196       end
197       
198     end
199 
200     class Buildr::Project
201       include EmmaExtension
202     end
203 
204     namespace "emma" do
205 
206       Project.local_task('instrument') { |name| "Instrumenting #{name}" }
207       
208       [:xml, :html].each do |format|
209         desc "Run the test cases and produce code coverage reports in #{format}"
210         task format => ['instrument', 'test'] do
211           info "Creating test coverage reports in #{format}"
212           mkdir_p report_to(format)
213           Emma.ant do |ant|
214             ant.merge :outfile=>data_file do
215               Buildr.projects.each do |project|
216                 [project.emma.metadata_file, project.emma.coverage_file].each do |data_file|
217                   ant.fileset :file=>data_file if File.exist?(data_file)
218                 end
219               end
220             end
221             ant.report do
222               ant.infileset :file=>data_file
223               ant.send format, :outfile=>File.join(report_to(format), "coverage.#{format}")
224               ant.sourcepath do
225                 Buildr.projects.map(&:emma).map(&:sources).flatten.map(&:to_s).each do |src|
226                   ant.dirset :dir=>src if File.exist?(src)
227                 end    
228               end
229             end
230           end
231         end
232       end
233       
234       task :clean do
235         rm_rf [report_to, data_file]
236       end
237       end
238 
239     task :clean do
240       task('emma:clean').invoke if Dir.pwd == Rake.application.original_dir
241     end
242 
243   end
244 end

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

Valid XHTML 1.0! Valid CSS!