C0 code coverage information

Generated on Wed Oct 07 08:33:57 -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/core/generate.rb 195 143
33.8%  
25.9%  
  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/pom'
 18 
 19 
 20 module Buildr
 21   module Generate #:nodoc:
 22 
 23     task 'generate' do
 24       script = nil 
 25       choose do |menu|
 26         menu.header = "To use Buildr you need a buildfile. Do you want me to create one?"
 27 
 28         menu.choice("From maven2 pom file") { script = Generate.from_maven2_pom('pom.xml').join("\n") } if File.exists?("pom.xml")
 29         menu.choice("From directory structure") { script = Generate.from_directory(Dir.pwd).join("\n") }
 30         menu.choice("Skip") { }
 31       end
 32        
 33       if script    
 34         buildfile = File.expand_path(Buildr::Application::DEFAULT_BUILDFILES.first)
 35         File.open(buildfile, "w") { |file| file.write script }
 36         puts "Created #{buildfile}"
 37       end        
 38     end
 39 
 40     class << self
 41 
 42       HEADER = "# Generated by Buildr #{Buildr::VERSION}, change to your liking\n\n"
 43 
 44       def from_directory(path = Dir.pwd, root = true)
 45         Dir.chdir(path) do
 46           name = File.basename(path)
 47           if root
 48             script = HEADER.split("\n")
 49             header = <<-EOF
 50 # Version number for this release
 51 VERSION_NUMBER = "1.0.0"
 52 # Group identifier for your projects
 53 GROUP = "#{name}"
 54 COPYRIGHT = ""
 55 
 56 # Specify Maven 2.0 remote repositories here, like this:
 57 repositories.remote << "http://www.ibiblio.org/maven2/"
 58 
 59 desc "The #{name.capitalize} project"
 60 define "#{name}" do
 61 
 62   project.version = VERSION_NUMBER
 63   project.group = GROUP
 64   manifest["Implementation-Vendor"] = COPYRIGHT
 65             EOF
 66             script += header.split("\n")
 67           else
 68             script = [ %{define "#{name}" do} ]
 69           end
 70           script <<  "  compile.with # Add classpath dependencies" if File.exist?("src/main/java")
 71           script <<  "  resources" if File.exist?("src/main/resources")
 72           script <<  "  test.compile.with # Add classpath dependencies" if File.exist?("src/test/java")
 73           script <<  "  test.resources" if File.exist?("src/test/resources")
 74           if File.exist?("src/main/webapp")
 75             script <<  "  package(:war)"
 76           elsif File.exist?("src/main/java")
 77             script <<  "  package(:jar)"
 78           end
 79           dirs = FileList["*"].exclude("src", "target", "report").
 80             select { |file| File.directory?(file) && File.exist?(File.join(file, "src")) }
 81           unless dirs.empty?
 82             script << ""
 83             dirs.sort.each do |dir|
 84               script << from_directory(dir, false).flatten.map { |line| "  " + line } << ""
 85             end
 86           end
 87           script << "end"
 88           script.flatten
 89         end
 90       end
 91 
 92       def from_maven2_pom(path = 'pom.xml', root = true)
 93         pom = Buildr::POM.load(path)
 94         project = pom.project
 95 
 96         artifactId = project['artifactId'].first
 97         description = project['name'] || "The #{artifactId} project"
 98         project_name = File.basename(Dir.pwd)
 99 
100         if root
101           script = HEADER.split("\n")
102 
103           settings_file = ENV["M2_SETTINGS"] || File.join(ENV['HOME'], ".m2/settings.xml")
104           settings = XmlSimple.xml_in(IO.read(settings_file)) if File.exists?(settings_file)
105 
106           if settings
107             proxy = settings['proxies'].first['proxy'].find { |proxy|
108               proxy["active"].nil? || proxy["active"].to_s =~ /true/
109             } rescue nil
110             
111             if proxy
112               url = %{#{proxy["protocol"].first}://#{proxy["host"].first}:#{proxy["port"].first}}
113               exclude = proxy["nonProxyHosts"].to_s.gsub("|", ",") if proxy["nonProxyHosts"]
114               script << "options.proxy.http = '#{url}'"
115               script << "options.proxy.exclude << '#{exclude}'" if exclude
116               script << ''
117               # In addition, we need to use said proxies to download artifacts.
118               Buildr.options.proxy.http = url
119               Buildr.options.proxy.exclude << exclude if exclude
120             end
121           end
122 
123           repositories = project["repositories"].first["repository"].select { |repository|
124             legacy = repository["layout"].to_s =~ /legacy/
125             !legacy
126           } rescue nil
127           repositories = [{"name" => "Standard maven2 repository", "url" => "http://www.ibiblio.org/maven2"}] if repositories.nil? || repositories.empty?
128           repositories.each do |repository|
129             name, url = repository["name"], repository["url"]
130             script << "# #{name}"
131             script << "repositories.remote << '#{url}'"
132             # In addition we need to use said repositores to download artifacts.
133             Buildr.repositories.remote << url.to_s
134           end
135           script << ""
136         else
137           script = []
138         end
139 
140         script << "desc '#{description}'"
141         script << "define '#{project_name}' do"
142 
143         groupId = project['groupId']
144         script << "  project.group = '#{groupId}'" if groupId
145 
146         version = project['version']
147         script << "  project.version = '#{version}'" if version
148 
149         #get plugins configurations
150         plugins = project['build'].first['plugins'].first['plugin'] rescue {}
151         if plugins
152           compile_plugin = plugins.find{|pl| (pl['groupId'].nil? or pl['groupId'].first == 'org.apache.maven.plugins') and pl['artifactId'].first == 'maven-compiler-plugin'}
153           if compile_plugin
154             source = compile_plugin.first['configuration'].first['source'] rescue nil
155             target = compile_plugin.first['configuration'].first['target'] rescue nil
156 
157             script << "  compile.options.source = '#{source}'" if source
158             script << "  compile.options.target = '#{target}'" if target
159           end
160         end
161 
162         compile_dependencies = pom.dependencies
163         dependencies = compile_dependencies.sort.map{|d| "'#{d}'"}.join(', ')
164         script <<  "  compile.with #{dependencies}" unless dependencies.empty?
165 
166         test_dependencies = (pom.dependencies(['test']) - compile_dependencies).reject{|d| d =~ /^junit:junit:jar:/ }
167         #check if we have testng
168         use_testng = test_dependencies.find{|d| d =~ /^org.testng:testng:jar:/}
169         if use_testng
170           script <<  "  test.using :testng"
171           test_dependencies = pom.dependencies(['test']).reject{|d| d =~ /^org.testng:testng:jar:/ }
172         end
173 
174         test_dependencies = test_dependencies.sort.map{|d| "'#{d}'"}.join(', ')
175         script <<  "  test.with #{test_dependencies}" unless test_dependencies.empty?
176 
177         packaging = project['packaging'] ? project['packaging'].first : 'jar'
178         if %w(jar war).include?(packaging)
179           script <<  "  package :#{packaging}, :id => '#{artifactId}'"
180         end
181 
182         modules = project['modules'].first['module'] rescue nil
183         if modules
184           script << ""
185           modules.each do |mod|
186             script << from_maven2_pom(File.join(File.dirname(path), mod, 'pom.xml'), false).flatten.map { |line| "  " + line } << ""
187           end
188         end
189         script << "end"
190         script.flatten
191       end
192        
193     end
194   end
195 end 

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

Valid XHTML 1.0! Valid CSS!