Buildr C0 Coverage Information - RCov

lib/buildr/groovy/compiler.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/buildr/groovy/compiler.rb 153 75
26.80%
36.00%

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 module Buildr::Groovy
18 
19   REQUIRES = ArtifactNamespace.for(self) do |ns|
20     ns.jansi! 'org.fusesource.jansi:jansi:jar:1.2.1'
21     ns.jline! 'jline:jline:jar:0.9.94'
22   end
23 
24   class << self
25     def dependencies #:nodoc:
26       REQUIRES.artifacts + Groovyc.dependencies
27     end
28   end
29 
30   # Groovyc compiler:
31   #  compile.using(:groovyc)
32   #
33   # You need to require 'buildr/groovy/compiler' if you need to use this compiler.
34   #
35   # Used by default if .groovy files are found in the src/main/groovy directory (or src/test/groovy)
36   # and sets the target directory to target/classes (or target/test/classes).
37   #
38   # Groovyc is a joint compiler, this means that when selected for a project, this compiler is used
39   # to compile both groovy and java sources. It's recommended that Groovy sources are placed in the
40   # src/main/groovy directory, even though this compiler also looks in src/main/java
41   #
42   # Groovyc accepts the following options:
43   #
44   # * :encoding          -- Encoding of source files
45   # * :verbose           -- Asks the compiler for verbose output, true when running in verbose mode.
46   # * :fork              -- Whether to execute groovyc using a spawned instance of the JVM; defaults to no
47   # * :memoryInitialSize -- The initial size of the memory for the underlying VM, if using fork mode; ignored otherwise.
48   #                                     Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)
49   # * :memoryMaximumSize -- The maximum size of the memory for the underlying VM, if using fork mode; ignored otherwise.
50   #                                     Defaults to the standard VM memory setting. (Examples: 83886080, 81920k, or 80m)
51   # * :listfiles         -- Indicates whether the source files to be compiled will be listed; defaults to no
52   # * :stacktrace        -- If true each compile error message will contain a stacktrace
53   # * :warnings          -- Issue warnings when compiling.  True when running in verbose mode.
54   # * :debug             -- Generates bytecode with debugging information.  Set from the debug
55   #                                     environment variable/global option.
56   # * :deprecation       -- If true, shows deprecation messages.  False by default.
57   # * :optimise          -- Generates faster bytecode by applying optimisations to the program.
58   # * :source            -- Source code compatibility.
59   # * :target            -- Bytecode compatibility.
60   # * :javac             -- Hash of options passed to the ant javac task
61   #
62   class Groovyc < Compiler::Base
63 
64     # The groovyc 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::Groovy::Groovyc).groovy = '1.7.1'
68     #
69     # namespace before this file is required.
70     REQUIRES = ArtifactNamespace.for(self) do |ns|
71       ns.groovy!       'org.codehaus.groovy:groovy:jar:>=1.7.5'
72       ns.commons_cli!  'commons-cli:commons-cli:jar:>=1.2'
73       ns.asm!          'asm:asm:jar:>=3.2'
74       ns.antlr!        'antlr:antlr:jar:>=2.7.7'
75     end
76 
77     ANT_TASK = 'org.codehaus.groovy.ant.Groovyc'
78     GROOVYC_OPTIONS = [:encoding, :verbose, :fork, :memoryInitialSize, :memoryMaximumSize, :listfiles, :stacktrace]
79     JAVAC_OPTIONS = [:optimise, :warnings, :debug, :deprecation, :source, :target, :javac]
80     OPTIONS = GROOVYC_OPTIONS + JAVAC_OPTIONS
81 
82     class << self
83       def dependencies #:nodoc:
84         REQUIRES.artifacts
85       end
86 
87       def applies_to?(project, task) #:nodoc:
88         paths = task.sources + [sources].flatten.map { |src| Array(project.path_to(:source, task.usage, src.to_sym)) }
89         paths.flatten!
90         # Just select if we find .groovy files
91         paths.any? { |path| !Dir["#{path}/**/*.groovy"].empty? }
92       end
93     end
94 
95     # Groovy dependencies don't need to go into JVM's system classpath.
96     # In fact, if they end up there it causes trouble because Groovy has issues
97     # loading other classes such as test frameworks (e.g. JUnit).
98     #
99     # Java.classpath << lambda { dependencies }
100 
101     specify :language => :groovy, :sources => [:groovy, :java], :source_ext => [:groovy, :java],
102             :target => 'classes', :target_ext => 'class', :packaging => :jar
103 
104     def initialize(project, options) #:nodoc:
105       super
106       options[:debug] = Buildr.options.debug if options[:debug].nil?
107       options[:deprecation] ||= false
108       options[:optimise] ||= false
109       options[:verbose] ||= trace?(:groovyc) if options[:verbose].nil?
110       options[:warnings] = verbose if options[:warnings].nil?
111       options[:javac] = OpenObject.new if options[:javac].nil?
112     end
113 
114     # http://groovy.codehaus.org/The+groovyc+Ant+Task
115     def compile(sources, target, dependencies) #:nodoc:
116       return if Buildr.application.options.dryrun
117       Buildr.ant 'groovyc' do |ant|
118         classpath = dependencies
119         ant.taskdef :name => 'groovyc', :classname => ANT_TASK, :classpath => classpath.join(File::PATH_SEPARATOR)
120         ant.groovyc groovyc_options(sources, target) do
121           sources.each { |src| ant.src :path => src }
122           ant.classpath do
123             classpath.each { |dep| ant.pathelement :path => dep }
124           end
125           ant.javac(javac_options)
126         end
127       end
128     end
129 
130    private
131     def groovyc_options(sources, target)
132       check_options options, OPTIONS
133       groovyc_options = options.to_hash.only(*GROOVYC_OPTIONS)
134       groovyc_options[:destdir] = File.expand_path(target)
135       groovyc_options
136     end
137 
138     def javac_options
139       check_options options, OPTIONS
140       javac_options = options.to_hash.only(*JAVAC_OPTIONS)
141       javac_options[:optimize] = (javac_options.delete(:optimise) || false)
142       javac_options[:nowarn] = (javac_options.delete(:warnings) || verbose).to_s !~ /^(true|yes|on)$/i
143       other = javac_options.delete(:javac) || {}
144       javac_options.merge!(other)
145       javac_options
146     end
147 
148   end
149 end
150 
151 # Groovy compiler comes first, ahead of Javac, this allows it to pick
152 # projects that mix Groovy and Java code by spotting Groovy code first.
153 Buildr::Compiler.compilers.unshift Buildr::Groovy::Groovyc

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