C0 code coverage information

Generated on Wed Oct 07 08:34:06 -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/scala/compiler.rb 195 120
85.6%  
78.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 require 'buildr/core/project'
 17 require 'buildr/core/common'
 18 require 'buildr/core/compile'
 19 require 'buildr/packaging'
 20 
 21 module Buildr::Scala
 22   DEFAULT_VERSION = '2.7.5'   # currently the latest (Jun 19, 2009)
 23   
 24   class << self
 25     
 26     # Retrieves the Scala version string from the 
 27     # standard library or nil if Scala is not
 28     # available.
 29     def version_str
 30       begin
 31         # Scala version string normally looks like "version 2.7.3.final"
 32         Java.scala.util.Properties.versionString.sub 'version ', ''
 33       rescue
 34         nil
 35       end
 36     end
 37     
 38     def version
 39       if version_str
 40         # any consecutive sequence of numbers followed by dots
 41         match = version_str.match(/\d+\.\d[\d\.]*/) or
 42           fail "Unable to parse Scala version: #{version_str} "
 43         match[0].sub(/.$/, "") # remove trailing dot, if any
 44       else
 45         DEFAULT_VERSION       # TODO return the version installed from Maven repo
 46       end
 47     end
 48   end
 49 
 50   # Scalac compiler:
 51   #   compile.using(:scalac)
 52   # Used by default if .scala files are found in the src/main/scala directory (or src/test/scala)
 53   # and sets the target directory to target/classes (or target/test/classes).
 54   #
 55   # Accepts the following options:
 56   # * :warnings    -- Generate warnings if true (opposite of -nowarn).
 57   # * :deprecation -- Output source locations where deprecated APIs are used.
 58   # * :optimise    -- Generates faster bytecode by applying optimisations to the program.
 59   # * :target      -- Class file compatibility with specified release.
 60   # * :debug       -- Generate debugging info.
 61   # * :other       -- Array of options to pass to the Scalac compiler as is, e.g. -Xprint-types
 62   class Scalac < Buildr::Compiler::Base
 63     
 64     # The scalac compiler jars are added to classpath at load time,
 65     # if you want to customize artifact versions, you must set them on the
 66     #
 67     #      artifact_ns['Buildr::Compiler::Scalac'].library = '2.7.5'
 68     #
 69     # namespace before this file is required.  This is of course, only
 70     # if SCALA_HOME is not set or invalid.
 71     REQUIRES = ArtifactNamespace.for(self) do |ns|
 72       ns.library!      'org.scala-lang:scala-library:jar:>=' + DEFAULT_VERSION
 73       ns.compiler!     'org.scala-lang:scala-compiler:jar:>=' + DEFAULT_VERSION
 74     end
 75     
 76     class << self
 77       def scala_home
 78         env_home = ENV['SCALA_HOME']
 79         
 80         @home ||= (if !env_home.nil? && File.exists?(env_home + '/lib/scala-library.jar') && File.exists?(env_home + '/lib/scala-compiler.jar')
 81           env_home
 82         else
 83           nil
 84         end)
 85       end
 86       
 87       def installed?
 88         !scala_home.nil?
 89       end
 90 
 91       def dependencies
 92         if installed?
 93           ['scala-library', 'scala-compiler'].map { |s| File.expand_path("lib/#{s}.jar", scala_home) }
 94         else
 95           REQUIRES.artifacts.map(&:to_s)
 96         end
 97       end
 98 
 99       def use_fsc
100         installed? && ENV["USE_FSC"] =~ /^(yes|on|true)$/i
101       end
102       
103       def applies_to?(project, task) #:nodoc:
104         paths = task.sources + [sources].flatten.map { |src| Array(project.path_to(:source, task.usage, src.to_sym)) }
105         paths.flatten!
106         
107         # Just select if we find .scala files
108         paths.any? { |path| !Dir["#{path}/**/*.scala"].empty? }
109       end
110     end
111     
112     Javac = Buildr::Compiler::Javac
113 
114     OPTIONS = [:warnings, :deprecation, :optimise, :target, :debug, :other, :javac]
115     
116     Java.classpath << dependencies
117 
118     specify :language=>:scala, :sources => [:scala, :java], :source_ext => [:scala, :java],
119             :target=>'classes', :target_ext=>'class', :packaging=>:jar
120 
121     def initialize(project, options) #:nodoc:
122       super
123       options[:debug] = Buildr.options.debug if options[:debug].nil?
124       options[:warnings] = verbose if options[:warnings].nil?
125       options[:deprecation] ||= false
126       options[:optimise] ||= false
127       options[:javac] ||= {}
128       
129       @java = Javac.new(project, options[:javac])
130     end
131 
132     def compile(sources, target, dependencies) #:nodoc:
133       check_options options, OPTIONS
134 
135       cmd_args = []
136       cmd_args << '-classpath' << (dependencies + Scalac.dependencies).join(File::PATH_SEPARATOR)
137       source_paths = sources.select { |source| File.directory?(source) }
138       cmd_args << '-sourcepath' << source_paths.join(File::PATH_SEPARATOR) unless source_paths.empty?
139       cmd_args << '-d' << File.expand_path(target)
140       cmd_args += scalac_args
141       cmd_args += files_from_sources(sources)
142 
143       unless Buildr.application.options.dryrun
144         trace((['scalac'] + cmd_args).join(' '))
145         
146         if Scalac.use_fsc
147           system(([File.expand_path('bin/fsc', Scalac.scala_home)] + cmd_args).join(' ')) or
148             fail 'Failed to compile, see errors above'
149         else
150           Java.load
151           begin
152             Java.scala.tools.nsc.Main.process(cmd_args.to_java(Java.java.lang.String))
153           rescue => e
154             fail "Scala compiler crashed:\n#{e.inspect}" 
155           end
156           fail 'Failed to compile, see errors above' if Java.scala.tools.nsc.Main.reporter.hasErrors
157         end
158  
159         java_sources = java_sources(sources)
160         unless java_sources.empty?
161           trace 'Compiling mixed Java/Scala sources'
162           
163           # TODO  includes scala-compiler.jar
164           deps = dependencies + Scalac.dependencies + [ File.expand_path(target) ]
165           @java.compile(java_sources, target, deps)
166         end
167       end
168     end
169 
170   private
171 
172     def java_sources(sources)
173       sources.flatten.map { |source| File.directory?(source) ? FileList["#{source}/**/*.java"] : source } .
174         flatten.reject { |file| File.directory?(file) || File.extname(file) != '.java' }.map { |file| File.expand_path(file) }.uniq
175     end
176 
177     # Returns Scalac command line arguments from the set of options.
178     def scalac_args #:nodoc:
179       args = []
180       args << "-nowarn" unless options[:warnings]
181       args << "-verbose" if Buildr.application.options.trace
182       args << "-g" if options[:debug]
183       args << "-deprecation" if options[:deprecation]
184       args << "-optimise" if options[:optimise]
185       args << "-target:jvm-" + options[:target].to_s if options[:target]
186       args + Array(options[:other])
187     end
188 
189   end
190     
191 end
192 
193 # Scala compiler comes first, ahead of Javac, this allows it to pick
194 # projects that mix Scala and Java code by spotting Scala code first.
195 Buildr::Compiler.compilers.unshift Buildr::Scala::Scalac

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

Valid XHTML 1.0! Valid CSS!