buildr 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +76 -0
- data/NOTICE +1 -1
- data/README.rdoc +9 -21
- data/Rakefile +20 -37
- data/_buildr +3 -12
- data/{doc/print.toc.yaml → _jbuildr} +14 -14
- data/addon/buildr/cobertura.rb +5 -219
- data/addon/buildr/drb.rb +281 -0
- data/addon/buildr/emma.rb +5 -221
- data/addon/buildr/nailgun.rb +93 -689
- data/bin/buildr +0 -9
- data/buildr.buildfile +4 -4
- data/buildr.gemspec +27 -21
- data/doc/_layouts/default.html +82 -0
- data/doc/_layouts/preface.html +22 -0
- data/doc/{pages/artifacts.textile → artifacts.textile} +82 -42
- data/doc/{pages/building.textile → building.textile} +89 -47
- data/doc/{pages/contributing.textile → contributing.textile} +53 -45
- data/doc/css/default.css +6 -5
- data/doc/css/print.css +17 -24
- data/doc/css/syntax.css +7 -36
- data/doc/download.textile +78 -0
- data/doc/{pages/extending.textile → extending.textile} +45 -24
- data/doc/{pages/getting_started.textile → getting_started.textile} +146 -88
- data/doc/images/asf-logo.gif +0 -0
- data/doc/images/note.png +0 -0
- data/doc/index.textile +47 -0
- data/doc/{pages/languages.textile → languages.textile} +108 -54
- data/doc/mailing_lists.textile +25 -0
- data/doc/{pages/more_stuff.textile → more_stuff.textile} +152 -73
- data/doc/{pages/packaging.textile → packaging.textile} +181 -96
- data/doc/preface.textile +28 -0
- data/doc/{pages/projects.textile → projects.textile} +55 -40
- data/doc/scripts/buildr-git.rb +364 -264
- data/doc/scripts/gitflow.rb +296 -0
- data/doc/scripts/install-jruby.sh +2 -2
- data/doc/scripts/install-linux.sh +6 -6
- data/doc/scripts/install-osx.sh +2 -2
- data/doc/{pages/settings_profiles.textile → settings_profiles.textile} +83 -45
- data/doc/{pages/testing.textile → testing.textile} +77 -41
- data/lib/buildr.rb +5 -5
- data/lib/buildr/core.rb +2 -0
- data/lib/buildr/core/application.rb +321 -151
- data/lib/buildr/core/build.rb +298 -167
- data/lib/buildr/core/checks.rb +4 -132
- data/lib/buildr/core/common.rb +1 -5
- data/lib/buildr/core/compile.rb +3 -9
- data/lib/buildr/core/environment.rb +12 -3
- data/lib/buildr/core/filter.rb +20 -18
- data/lib/buildr/core/generate.rb +36 -36
- data/lib/buildr/core/help.rb +2 -1
- data/lib/buildr/core/osx.rb +46 -0
- data/lib/buildr/core/progressbar.rb +1 -1
- data/lib/buildr/core/project.rb +7 -34
- data/lib/buildr/core/test.rb +12 -6
- data/lib/buildr/core/transports.rb +13 -11
- data/lib/buildr/core/util.rb +14 -23
- data/lib/buildr/groovy/bdd.rb +3 -2
- data/lib/buildr/groovy/compiler.rb +1 -1
- data/lib/buildr/ide/eclipse.rb +31 -21
- data/lib/buildr/ide/idea.rb +3 -2
- data/lib/buildr/ide/idea7x.rb +6 -4
- data/lib/buildr/java/ant.rb +3 -1
- data/lib/buildr/java/bdd.rb +9 -7
- data/lib/buildr/java/cobertura.rb +243 -0
- data/lib/buildr/java/compiler.rb +5 -4
- data/lib/buildr/java/emma.rb +244 -0
- data/lib/buildr/java/packaging.rb +11 -8
- data/lib/buildr/java/pom.rb +0 -4
- data/lib/buildr/java/rjb.rb +1 -1
- data/lib/buildr/java/test_result.rb +5 -7
- data/lib/buildr/java/tests.rb +17 -11
- data/lib/buildr/packaging.rb +5 -2
- data/lib/buildr/packaging/archive.rb +488 -0
- data/lib/buildr/packaging/artifact.rb +48 -29
- data/lib/buildr/packaging/artifact_namespace.rb +6 -6
- data/lib/buildr/packaging/gems.rb +4 -4
- data/lib/buildr/packaging/package.rb +3 -2
- data/lib/buildr/packaging/tar.rb +85 -3
- data/lib/buildr/packaging/version_requirement.rb +172 -0
- data/lib/buildr/packaging/zip.rb +24 -682
- data/lib/buildr/packaging/ziptask.rb +313 -0
- data/lib/buildr/scala.rb +5 -0
- data/lib/buildr/scala/bdd.rb +100 -0
- data/lib/buildr/scala/compiler.rb +45 -4
- data/lib/buildr/scala/tests.rb +12 -59
- data/rakelib/checks.rake +57 -0
- data/rakelib/doc.rake +58 -68
- data/rakelib/jekylltask.rb +110 -0
- data/rakelib/package.rake +35 -37
- data/rakelib/release.rake +119 -35
- data/rakelib/rspec.rake +29 -39
- data/rakelib/setup.rake +21 -59
- data/rakelib/stage.rake +184 -26
- data/spec/addon/drb_spec.rb +328 -0
- data/spec/core/application_spec.rb +32 -25
- data/spec/core/build_spec.rb +336 -126
- data/spec/core/checks_spec.rb +292 -310
- data/spec/core/common_spec.rb +8 -2
- data/spec/core/compile_spec.rb +17 -1
- data/spec/core/generate_spec.rb +3 -3
- data/spec/core/project_spec.rb +18 -10
- data/spec/core/test_spec.rb +8 -1
- data/spec/core/transport_spec.rb +40 -3
- data/spec/core/util_spec.rb +67 -0
- data/spec/ide/eclipse_spec.rb +96 -28
- data/spec/ide/idea7x_spec.rb +84 -0
- data/spec/java/ant.rb +5 -0
- data/spec/java/bdd_spec.rb +12 -3
- data/spec/{addon → java}/cobertura_spec.rb +6 -6
- data/spec/{addon → java}/emma_spec.rb +5 -6
- data/spec/java/java_spec.rb +12 -2
- data/spec/java/packaging_spec.rb +31 -2
- data/spec/{addon → java}/test_coverage_spec.rb +3 -3
- data/spec/java/tests_spec.rb +5 -0
- data/spec/packaging/archive_spec.rb +11 -1
- data/spec/{core → packaging}/artifact_namespace_spec.rb +10 -2
- data/spec/packaging/artifact_spec.rb +44 -3
- data/spec/packaging/packaging_spec.rb +1 -1
- data/spec/sandbox.rb +17 -14
- data/spec/scala/bdd_spec.rb +150 -0
- data/spec/scala/compiler_spec.rb +27 -0
- data/spec/scala/scala.rb +38 -0
- data/spec/scala/tests_spec.rb +78 -33
- data/spec/spec_helpers.rb +29 -5
- data/spec/version_requirement_spec.rb +6 -0
- metadata +175 -171
- data/DISCLAIMER +0 -7
- data/doc/images/apache-incubator-logo.png +0 -0
- data/doc/pages/download.textile +0 -51
- data/doc/pages/index.textile +0 -42
- data/doc/pages/mailing_lists.textile +0 -17
- data/doc/pages/recipes.textile +0 -103
- data/doc/pages/troubleshooting.textile +0 -103
- data/doc/pages/whats_new.textile +0 -323
- data/doc/print.haml +0 -51
- data/doc/site.haml +0 -56
- data/doc/site.toc.yaml +0 -47
- data/etc/git-svn-authors +0 -16
- data/lib/buildr/core/application_cli.rb +0 -139
- data/rakelib/apache.rake +0 -191
- data/rakelib/changelog.rake +0 -57
- data/rakelib/rubyforge.rake +0 -53
- data/rakelib/scm.rake +0 -49
data/lib/buildr/java/ant.rb
CHANGED
data/lib/buildr/java/bdd.rb
CHANGED
@@ -13,9 +13,11 @@
|
|
13
13
|
# License for the specific language governing permissions and limitations under
|
14
14
|
# the License.
|
15
15
|
|
16
|
+
|
16
17
|
require 'buildr/java/tests'
|
17
18
|
require 'buildr/java/test_result'
|
18
19
|
|
20
|
+
|
19
21
|
module Buildr
|
20
22
|
|
21
23
|
# Mixin for test frameworks using src/spec/{lang}
|
@@ -46,7 +48,7 @@ module Buildr
|
|
46
48
|
module TestFramework::JRubyBased
|
47
49
|
extend self
|
48
50
|
|
49
|
-
VERSION = '1.1.
|
51
|
+
VERSION = '1.1.6'
|
50
52
|
|
51
53
|
class << self
|
52
54
|
def version
|
@@ -83,15 +85,15 @@ module Buildr
|
|
83
85
|
|
84
86
|
spec_dir = task.project.path_to(:source, :spec, :ruby)
|
85
87
|
report_dir = task.report_to.to_s
|
86
|
-
|
87
|
-
|
88
|
+
rm_rf report_dir
|
89
|
+
mkdir_p report_dir
|
88
90
|
ENV['CI_REPORTS'] = report_dir
|
89
91
|
|
90
92
|
runner = runner_config
|
91
93
|
runner.content = runner_content(binding)
|
92
94
|
|
93
95
|
Buildr.write(runner.file, runner.content)
|
94
|
-
|
96
|
+
rm_f runner.result
|
95
97
|
|
96
98
|
if RUBY_PLATFORM[/java/] && !options.fork
|
97
99
|
runtime = new_runtime
|
@@ -139,7 +141,7 @@ module Buildr
|
|
139
141
|
fail msg unless jruby_installed?
|
140
142
|
end
|
141
143
|
end
|
142
|
-
|
144
|
+
|
143
145
|
def jruby(*args)
|
144
146
|
java_args = ['org.jruby.Main', *args]
|
145
147
|
java_args << {} unless Hash === args.last
|
@@ -175,13 +177,13 @@ module Buildr
|
|
175
177
|
end
|
176
178
|
require 'rubygems'
|
177
179
|
begin
|
178
|
-
Kernel.gem name, version
|
180
|
+
Kernel.send :gem, name, version
|
179
181
|
rescue LoadError, Gem::LoadError => e
|
180
182
|
require 'rubygems/gem_runner'
|
181
183
|
Gem.manage_gems
|
182
184
|
args = ['install', name, '--version', version] + args
|
183
185
|
Gem::GemRunner.new.run(args)
|
184
|
-
Kernel.gem name, version
|
186
|
+
Kernel.send :gem, name, version
|
185
187
|
end
|
186
188
|
end
|
187
189
|
}
|
@@ -0,0 +1,243 @@
|
|
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>cobertura:html</code> and <code>cobertura:xml</code> tasks.
|
23
|
+
# Require explicitly using <code>require "buildr/cobertura"</code>.
|
24
|
+
#
|
25
|
+
# You can generate cobertura reports for a single project
|
26
|
+
# using the project name as prefix:
|
27
|
+
#
|
28
|
+
# project_name:cobertura:html
|
29
|
+
#
|
30
|
+
# You can also specify which classes to include/exclude from instrumentation by
|
31
|
+
# passing a class name regexp to the <code>cobertura.include</code> or
|
32
|
+
# <code>cobertura.exclude</code> methods.
|
33
|
+
#
|
34
|
+
# define 'someModule' do
|
35
|
+
# cobertura.include 'some.package.*'
|
36
|
+
# cobertura.include /some.(foo|bar).*/
|
37
|
+
# cobertura.exclude 'some.foo.util.SimpleUtil'
|
38
|
+
# cobertura.exclude /*.Const(ants)?/i
|
39
|
+
# end
|
40
|
+
module Cobertura
|
41
|
+
|
42
|
+
VERSION = '1.9'
|
43
|
+
|
44
|
+
class << self
|
45
|
+
|
46
|
+
def version
|
47
|
+
Buildr.settings.build['cobertura'] || VERSION
|
48
|
+
end
|
49
|
+
|
50
|
+
def dependencies
|
51
|
+
@dependencies ||= [ "net.sourceforge.cobertura:cobertura:jar:#{version}", "log4j:log4j:jar:1.2.9",
|
52
|
+
"asm:asm:jar:2.2.1", "asm:asm-tree:jar:2.2.1", "oro:oro:jar:2.0.8"]
|
53
|
+
end
|
54
|
+
|
55
|
+
def report_to(file = nil)
|
56
|
+
File.expand_path(File.join(*["reports/cobertura", file.to_s].compact))
|
57
|
+
end
|
58
|
+
|
59
|
+
def data_file()
|
60
|
+
File.expand_path("reports/cobertura.ser")
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
class CoberturaConfig # :nodoc:
|
66
|
+
|
67
|
+
def initialize(project)
|
68
|
+
@project = project
|
69
|
+
end
|
70
|
+
|
71
|
+
attr_reader :project
|
72
|
+
private :project
|
73
|
+
|
74
|
+
attr_writer :data_file, :instrumented_dir, :report_dir
|
75
|
+
|
76
|
+
def data_file
|
77
|
+
@data_file ||= project.path_to(:reports, 'cobertura.ser')
|
78
|
+
end
|
79
|
+
|
80
|
+
def instrumented_dir
|
81
|
+
@instrumented_dir ||= project.path_to(:target, :instrumented, :classes)
|
82
|
+
end
|
83
|
+
|
84
|
+
def report_dir
|
85
|
+
@report_dir ||= project.path_to(:reports, :cobertura)
|
86
|
+
end
|
87
|
+
|
88
|
+
def report_to(file = nil)
|
89
|
+
File.expand_path(File.join(*[report_dir, file.to_s].compact))
|
90
|
+
end
|
91
|
+
|
92
|
+
# :call-seq:
|
93
|
+
# project.cobertura.include(*classPatterns)
|
94
|
+
#
|
95
|
+
def include(*classPatterns)
|
96
|
+
includes.push(*classPatterns.map { |p| String === p ? Regexp.new(p) : p })
|
97
|
+
self
|
98
|
+
end
|
99
|
+
|
100
|
+
def includes
|
101
|
+
@includeClasses ||= []
|
102
|
+
end
|
103
|
+
|
104
|
+
# :call-seq:
|
105
|
+
# project.cobertura.exclude(*classPatterns)
|
106
|
+
#
|
107
|
+
def exclude(*classPatterns)
|
108
|
+
excludes.push(*classPatterns.map { |p| String === p ? Regexp.new(p) : p })
|
109
|
+
self
|
110
|
+
end
|
111
|
+
|
112
|
+
def excludes
|
113
|
+
@excludeClasses ||= []
|
114
|
+
end
|
115
|
+
|
116
|
+
def sources
|
117
|
+
project.compile.sources
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
module CoberturaExtension # :nodoc:
|
122
|
+
include Buildr::Extension
|
123
|
+
|
124
|
+
def cobertura
|
125
|
+
@cobertura_config ||= CoberturaConfig.new(self)
|
126
|
+
end
|
127
|
+
|
128
|
+
after_define do |project|
|
129
|
+
cobertura = project.cobertura
|
130
|
+
|
131
|
+
namespace 'cobertura' do
|
132
|
+
unless project.compile.target.nil?
|
133
|
+
# Instrumented bytecode goes in a different directory. This task creates before running the test
|
134
|
+
# cases and monitors for changes in the generate bytecode.
|
135
|
+
instrumented = project.file(cobertura.instrumented_dir => project.compile.target) do |task|
|
136
|
+
mkdir_p task.to_s
|
137
|
+
unless project.compile.sources.empty?
|
138
|
+
info "Instrumenting classes with cobertura data file #{cobertura.data_file}"
|
139
|
+
Buildr.ant "cobertura" do |ant|
|
140
|
+
ant.taskdef :resource=>"tasks.properties",
|
141
|
+
:classpath=>Buildr.artifacts(Cobertura.dependencies).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
|
142
|
+
ant.send "cobertura-instrument", :todir=>task.to_s, :datafile=>cobertura.data_file do
|
143
|
+
includes, excludes = cobertura.includes, cobertura.excludes
|
144
|
+
|
145
|
+
classes_dir = project.compile.target.to_s
|
146
|
+
if includes.empty? && excludes.empty?
|
147
|
+
ant.fileset :dir => classes_dir do
|
148
|
+
ant.include :name => "**/*.class"
|
149
|
+
end
|
150
|
+
else
|
151
|
+
includes = [//] if includes.empty?
|
152
|
+
Dir.glob(File.join(classes_dir, "**/*.class")) do |cls|
|
153
|
+
cls_name = cls.gsub(/#{classes_dir}\/?|\.class$/, '').gsub('/', '.')
|
154
|
+
if includes.any? { |p| p === cls_name } && !excludes.any? { |p| p === cls_name }
|
155
|
+
ant.fileset :file => cls
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
touch task.to_s
|
163
|
+
end
|
164
|
+
|
165
|
+
task 'instrument' => instrumented
|
166
|
+
|
167
|
+
# We now have two target directories with bytecode. It would make sense to remove compile.target
|
168
|
+
# and add instrumented instead, but apparently Cobertura only creates some of the classes, so
|
169
|
+
# we need both directories and instrumented must come first.
|
170
|
+
project.test.dependencies.unshift cobertura.instrumented_dir
|
171
|
+
project.test.with Cobertura.dependencies
|
172
|
+
project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = cobertura.data_file
|
173
|
+
|
174
|
+
[:xml, :html].each do |format|
|
175
|
+
task format => ['instrument', 'test'] do
|
176
|
+
info "Creating test coverage reports in #{cobertura.report_to(format)}"
|
177
|
+
Buildr.ant "cobertura" do |ant|
|
178
|
+
ant.taskdef :resource=>"tasks.properties",
|
179
|
+
:classpath=>Buildr.artifacts(Cobertura.dependencies).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
|
180
|
+
ant.send "cobertura-report", :format=>format,
|
181
|
+
:destdir=>cobertura.report_to(format), :datafile=>cobertura.data_file do
|
182
|
+
cobertura.sources.flatten.each do |src|
|
183
|
+
ant.fileset(:dir=>src.to_s) if File.exist?(src.to_s)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
project.clean do
|
194
|
+
rm_rf [cobertura.report_to, cobertura.data_file, cobertura.instrumented_dir]
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
class Buildr::Project
|
202
|
+
include CoberturaExtension
|
203
|
+
end
|
204
|
+
|
205
|
+
namespace "cobertura" do
|
206
|
+
|
207
|
+
task "instrument" do
|
208
|
+
Buildr.projects.each do |project|
|
209
|
+
project.cobertura.data_file = data_file
|
210
|
+
project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = data_file
|
211
|
+
instrument_task ="#{project.name}:cobertura:instrument"
|
212
|
+
task(instrument_task).invoke if Rake::Task.task_defined?(instrument_task)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
[:xml, :html].each do |format|
|
217
|
+
report_target = report_to(format)
|
218
|
+
desc "Run the test cases and produce code coverage reports in #{report_target}"
|
219
|
+
task format => ["instrument", "test"] do
|
220
|
+
info "Creating test coverage reports in #{report_target}"
|
221
|
+
Buildr.ant "cobertura" do |ant|
|
222
|
+
ant.taskdef :resource=>"tasks.properties",
|
223
|
+
:classpath=>Buildr.artifacts(Cobertura.dependencies).each(&:invoke).map(&:to_s).join(File::PATH_SEPARATOR)
|
224
|
+
ant.send "cobertura-report", :destdir=>report_target, :format=>format, :datafile=>data_file do
|
225
|
+
Buildr.projects.map(&:cobertura).map(&:sources).flatten.each do |src|
|
226
|
+
ant.fileset :dir=>src.to_s if File.exist?(src.to_s)
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
task "clean" do
|
234
|
+
rm_rf [report_to, data_file]
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
task "clean" do
|
239
|
+
task("cobertura:clean").invoke if Dir.pwd == Rake.application.original_dir
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
end
|
data/lib/buildr/java/compiler.rb
CHANGED
@@ -31,12 +31,13 @@ module Buildr
|
|
31
31
|
# Accepts the following options:
|
32
32
|
# * :warnings -- Issue warnings when compiling. True when running in verbose mode.
|
33
33
|
# * :debug -- Generates bytecode with debugging information. Set from the debug
|
34
|
-
#
|
34
|
+
# environment variable/global option.
|
35
35
|
# * :deprecation -- If true, shows deprecation messages. False by default.
|
36
36
|
# * :source -- Source code compatibility.
|
37
37
|
# * :target -- Bytecode compatibility.
|
38
38
|
# * :lint -- Lint option is one of true, false (default), name (e.g. 'cast') or array.
|
39
|
-
# * :other -- Array of options passed to the compiler
|
39
|
+
# * :other -- Array of options passed to the compiler
|
40
|
+
# (e.g. ['-implicit:none', '-encoding', 'iso-8859-1'])
|
40
41
|
class Javac < Base
|
41
42
|
|
42
43
|
OPTIONS = [:warnings, :debug, :deprecation, :source, :target, :lint, :other]
|
@@ -116,9 +117,9 @@ module Buildr
|
|
116
117
|
@sourcepath = []
|
117
118
|
@files = FileList[]
|
118
119
|
enhance do |task|
|
119
|
-
rm_rf target.to_s
|
120
|
+
rm_rf target.to_s
|
120
121
|
generate source_files, File.expand_path(target.to_s), options.merge(:classpath=>classpath, :sourcepath=>sourcepath)
|
121
|
-
touch target.to_s
|
122
|
+
touch target.to_s
|
122
123
|
end
|
123
124
|
end
|
124
125
|
|
@@ -0,0 +1,244 @@
|
|
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
|