assaf-buildr 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/CHANGELOG +887 -0
  2. data/DISCLAIMER +7 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.rdoc +146 -0
  6. data/Rakefile +62 -0
  7. data/_buildr +38 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +236 -0
  10. data/addon/buildr/emma.rb +238 -0
  11. data/addon/buildr/hibernate.rb +142 -0
  12. data/addon/buildr/javacc.rb +85 -0
  13. data/addon/buildr/jdepend.rb +60 -0
  14. data/addon/buildr/jetty.rb +248 -0
  15. data/addon/buildr/jibx.rb +86 -0
  16. data/addon/buildr/nailgun.rb +817 -0
  17. data/addon/buildr/openjpa.rb +90 -0
  18. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  21. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  25. data/addon/buildr/xmlbeans.rb +93 -0
  26. data/bin/buildr +28 -0
  27. data/buildr.buildfile +53 -0
  28. data/buildr.gemspec +58 -0
  29. data/doc/css/default.css +228 -0
  30. data/doc/css/print.css +100 -0
  31. data/doc/css/syntax.css +52 -0
  32. data/doc/images/apache-incubator-logo.png +0 -0
  33. data/doc/images/buildr-hires.png +0 -0
  34. data/doc/images/buildr.png +0 -0
  35. data/doc/images/favicon.png +0 -0
  36. data/doc/images/growl-icon.tiff +0 -0
  37. data/doc/images/note.png +0 -0
  38. data/doc/images/project-structure.png +0 -0
  39. data/doc/images/tip.png +0 -0
  40. data/doc/images/zbuildr.tif +0 -0
  41. data/doc/pages/artifacts.textile +207 -0
  42. data/doc/pages/building.textile +240 -0
  43. data/doc/pages/contributing.textile +208 -0
  44. data/doc/pages/download.textile +62 -0
  45. data/doc/pages/extending.textile +175 -0
  46. data/doc/pages/getting_started.textile +273 -0
  47. data/doc/pages/index.textile +42 -0
  48. data/doc/pages/languages.textile +407 -0
  49. data/doc/pages/mailing_lists.textile +17 -0
  50. data/doc/pages/more_stuff.textile +286 -0
  51. data/doc/pages/packaging.textile +427 -0
  52. data/doc/pages/projects.textile +274 -0
  53. data/doc/pages/recipes.textile +103 -0
  54. data/doc/pages/settings_profiles.textile +274 -0
  55. data/doc/pages/testing.textile +212 -0
  56. data/doc/pages/troubleshooting.textile +103 -0
  57. data/doc/pages/whats_new.textile +323 -0
  58. data/doc/print.haml +51 -0
  59. data/doc/print.toc.yaml +29 -0
  60. data/doc/scripts/buildr-git.rb +412 -0
  61. data/doc/scripts/install-jruby.sh +44 -0
  62. data/doc/scripts/install-linux.sh +64 -0
  63. data/doc/scripts/install-osx.sh +52 -0
  64. data/doc/site.haml +56 -0
  65. data/doc/site.toc.yaml +47 -0
  66. data/etc/KEYS +151 -0
  67. data/etc/git-svn-authors +16 -0
  68. data/lib/buildr.rb +35 -0
  69. data/lib/buildr/core.rb +27 -0
  70. data/lib/buildr/core/application.rb +489 -0
  71. data/lib/buildr/core/application_cli.rb +139 -0
  72. data/lib/buildr/core/build.rb +311 -0
  73. data/lib/buildr/core/checks.rb +382 -0
  74. data/lib/buildr/core/common.rb +154 -0
  75. data/lib/buildr/core/compile.rb +596 -0
  76. data/lib/buildr/core/environment.rb +120 -0
  77. data/lib/buildr/core/filter.rb +362 -0
  78. data/lib/buildr/core/generate.rb +195 -0
  79. data/lib/buildr/core/help.rb +118 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +892 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +558 -0
  84. data/lib/buildr/core/util.rb +289 -0
  85. data/lib/buildr/groovy.rb +18 -0
  86. data/lib/buildr/groovy/bdd.rb +105 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/ide.rb +19 -0
  89. data/lib/buildr/ide/eclipse.rb +212 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +189 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +210 -0
  94. data/lib/buildr/java.rb +23 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +449 -0
  97. data/lib/buildr/java/commands.rb +211 -0
  98. data/lib/buildr/java/compiler.rb +348 -0
  99. data/lib/buildr/java/deprecated.rb +141 -0
  100. data/lib/buildr/java/jruby.rb +117 -0
  101. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  102. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  103. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  104. data/lib/buildr/java/packaging.rb +713 -0
  105. data/lib/buildr/java/pom.rb +178 -0
  106. data/lib/buildr/java/rjb.rb +155 -0
  107. data/lib/buildr/java/test_result.rb +308 -0
  108. data/lib/buildr/java/tests.rb +324 -0
  109. data/lib/buildr/java/version_requirement.rb +172 -0
  110. data/lib/buildr/packaging.rb +21 -0
  111. data/lib/buildr/packaging/artifact.rb +730 -0
  112. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  113. data/lib/buildr/packaging/artifact_search.rb +140 -0
  114. data/lib/buildr/packaging/gems.rb +102 -0
  115. data/lib/buildr/packaging/package.rb +233 -0
  116. data/lib/buildr/packaging/tar.rb +104 -0
  117. data/lib/buildr/packaging/zip.rb +722 -0
  118. data/lib/buildr/resources/buildr.icns +0 -0
  119. data/lib/buildr/scala.rb +19 -0
  120. data/lib/buildr/scala/compiler.rb +109 -0
  121. data/lib/buildr/scala/tests.rb +203 -0
  122. data/rakelib/apache.rake +191 -0
  123. data/rakelib/changelog.rake +57 -0
  124. data/rakelib/doc.rake +103 -0
  125. data/rakelib/package.rake +73 -0
  126. data/rakelib/release.rake +65 -0
  127. data/rakelib/rspec.rake +83 -0
  128. data/rakelib/rubyforge.rake +53 -0
  129. data/rakelib/scm.rake +49 -0
  130. data/rakelib/setup.rake +86 -0
  131. data/rakelib/stage.rake +48 -0
  132. data/spec/addon/cobertura_spec.rb +77 -0
  133. data/spec/addon/emma_spec.rb +120 -0
  134. data/spec/addon/test_coverage_spec.rb +255 -0
  135. data/spec/core/application_spec.rb +412 -0
  136. data/spec/core/artifact_namespace_spec.rb +646 -0
  137. data/spec/core/build_spec.rb +415 -0
  138. data/spec/core/checks_spec.rb +537 -0
  139. data/spec/core/common_spec.rb +664 -0
  140. data/spec/core/compile_spec.rb +566 -0
  141. data/spec/core/generate_spec.rb +33 -0
  142. data/spec/core/project_spec.rb +754 -0
  143. data/spec/core/test_spec.rb +1091 -0
  144. data/spec/core/transport_spec.rb +500 -0
  145. data/spec/groovy/bdd_spec.rb +80 -0
  146. data/spec/groovy/compiler_spec.rb +239 -0
  147. data/spec/ide/eclipse_spec.rb +243 -0
  148. data/spec/java/ant.rb +28 -0
  149. data/spec/java/bdd_spec.rb +358 -0
  150. data/spec/java/compiler_spec.rb +446 -0
  151. data/spec/java/java_spec.rb +88 -0
  152. data/spec/java/packaging_spec.rb +1103 -0
  153. data/spec/java/tests_spec.rb +466 -0
  154. data/spec/packaging/archive_spec.rb +503 -0
  155. data/spec/packaging/artifact_spec.rb +754 -0
  156. data/spec/packaging/packaging_helper.rb +63 -0
  157. data/spec/packaging/packaging_spec.rb +589 -0
  158. data/spec/sandbox.rb +137 -0
  159. data/spec/scala/compiler_spec.rb +228 -0
  160. data/spec/scala/tests_spec.rb +215 -0
  161. data/spec/spec_helpers.rb +304 -0
  162. data/spec/version_requirement_spec.rb +123 -0
  163. metadata +369 -0
@@ -0,0 +1,65 @@
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
+ # Provides ANTLR grammar generation tasks. Require explicitly using <code>require "buildr/antlr"</code>.
22
+ module ANTLR
23
+ REQUIRES = [ "org.antlr:antlr:jar:3.0", "antlr:antlr:jar:2.7.7", "org.antlr:stringtemplate:jar:3.0" ]
24
+
25
+ Java.classpath << REQUIRES
26
+
27
+ class << self
28
+ def antlr(*args)
29
+ options = Hash === args.last ? args.pop : {}
30
+ rake_check_options options, :output, :token
31
+
32
+ args = args.flatten.map(&:to_s).collect { |f| File.directory?(f) ? FileList[f + "/**/*.g"] : f }.flatten
33
+ args = ["-o", options[:output]] + args if options[:output]
34
+ if options[:token]
35
+ # antlr expects the token directory to exist when it starts
36
+ mkdir_p options[:token]
37
+ args = ["-lib", options[:token]] + args
38
+ end
39
+ Java.load
40
+ #Java.org.antlr.Tool.new_with_sig("[Ljava.lang.String;", args).process
41
+ Java.org.antlr.Tool.new(args.to_java(Java.java.lang.String)).process
42
+ end
43
+ end
44
+
45
+ def antlr(*args)
46
+ if Hash === args.last
47
+ options = args.pop
48
+ in_package = options[:in_package].split(".")
49
+ token = options[:token].split(".") if options[:token]
50
+ else
51
+ in_package = []; token = nil
52
+ end
53
+ file(path_to(:target, :generated, :antlr)=>args.flatten) do |task|
54
+ args = {:output=>File.join(task.name, in_package)}
55
+ args.merge!({:token=>File.join(task.name, token)}) if token
56
+ ANTLR.antlr task.prerequisites, args
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ class Project
63
+ include ANTLR
64
+ end
65
+ end
@@ -0,0 +1,236 @@
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
+ class << self
43
+
44
+ REQUIRES = ["net.sourceforge.cobertura:cobertura:jar:1.9", "log4j:log4j:jar:1.2.9",
45
+ "asm:asm:jar:2.2.1", "asm:asm-tree:jar:2.2.1", "oro:oro:jar:2.0.8"] unless const_defined?('REQUIRES')
46
+
47
+ def requires()
48
+ @requires ||= Buildr.artifacts(REQUIRES).each(&:invoke).map(&:to_s)
49
+ end
50
+
51
+ def report_to(file = nil)
52
+ File.expand_path(File.join(*["reports/cobertura", file.to_s].compact))
53
+ end
54
+
55
+ def data_file()
56
+ File.expand_path("reports/cobertura.ser")
57
+ end
58
+
59
+ end
60
+
61
+ class CoberturaConfig # :nodoc:
62
+
63
+ def initialize(project)
64
+ @project = project
65
+ end
66
+
67
+ attr_reader :project
68
+ private :project
69
+
70
+ attr_writer :data_file, :instrumented_dir, :report_dir
71
+
72
+ def data_file
73
+ @data_file ||= project.path_to(:reports, 'cobertura.ser')
74
+ end
75
+
76
+ def instrumented_dir
77
+ @instrumented_dir ||= project.path_to(:target, :instrumented, :classes)
78
+ end
79
+
80
+ def report_dir
81
+ @report_dir ||= project.path_to(:reports, :cobertura)
82
+ end
83
+
84
+ def report_to(file = nil)
85
+ File.expand_path(File.join(*[report_dir, file.to_s].compact))
86
+ end
87
+
88
+ # :call-seq:
89
+ # project.cobertura.include(*classPatterns)
90
+ #
91
+ def include(*classPatterns)
92
+ includes.push(*classPatterns.map { |p| String === p ? Regexp.new(p) : p })
93
+ self
94
+ end
95
+
96
+ def includes
97
+ @includeClasses ||= []
98
+ end
99
+
100
+ # :call-seq:
101
+ # project.cobertura.exclude(*classPatterns)
102
+ #
103
+ def exclude(*classPatterns)
104
+ excludes.push(*classPatterns.map { |p| String === p ? Regexp.new(p) : p })
105
+ self
106
+ end
107
+
108
+ def excludes
109
+ @excludeClasses ||= []
110
+ end
111
+
112
+ def sources
113
+ project.compile.sources
114
+ end
115
+ end
116
+
117
+ module CoberturaExtension # :nodoc:
118
+ include Buildr::Extension
119
+
120
+ def cobertura
121
+ @cobertura_config ||= CoberturaConfig.new(self)
122
+ end
123
+
124
+ after_define do |project|
125
+ cobertura = project.cobertura
126
+
127
+ namespace 'cobertura' do
128
+ unless project.compile.target.nil?
129
+ # Instrumented bytecode goes in a different directory. This task creates before running the test
130
+ # cases and monitors for changes in the generate bytecode.
131
+ instrumented = project.file(cobertura.instrumented_dir => project.compile.target) do |task|
132
+ mkdir_p task.to_s, :verbose => false
133
+ unless project.compile.sources.empty?
134
+ info "Instrumenting classes with cobertura data file #{cobertura.data_file}"
135
+ Buildr.ant "cobertura" do |ant|
136
+ ant.taskdef :classpath=>Cobertura.requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
137
+ ant.send "cobertura-instrument", :todir=>task.to_s, :datafile=>cobertura.data_file do
138
+ includes, excludes = cobertura.includes, cobertura.excludes
139
+
140
+ classes_dir = project.compile.target.to_s
141
+ if includes.empty? && excludes.empty?
142
+ ant.fileset :dir => classes_dir do
143
+ ant.include :name => "**/*.class"
144
+ end
145
+ else
146
+ includes = [//] if includes.empty?
147
+ Dir.glob(File.join(classes_dir, "**/*.class")) do |cls|
148
+ cls_name = cls.gsub(/#{classes_dir}\/?|\.class$/, '').gsub('/', '.')
149
+ if includes.any? { |p| p === cls_name } && !excludes.any? { |p| p === cls_name }
150
+ ant.fileset :file => cls
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
157
+ touch task.to_s, :verbose=>false
158
+ end
159
+
160
+ task 'instrument' => instrumented
161
+
162
+ # We now have two target directories with bytecode. It would make sense to remove compile.target
163
+ # and add instrumented instead, but apparently Cobertura only creates some of the classes, so
164
+ # we need both directories and instrumented must come first.
165
+ project.test.dependencies.unshift cobertura.instrumented_dir
166
+ project.test.with Cobertura.requires
167
+ project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = cobertura.data_file
168
+
169
+ [:xml, :html].each do |format|
170
+ task format => ['instrument', 'test'] do
171
+ info "Creating test coverage reports in #{cobertura.report_to(format)}"
172
+ Buildr.ant "cobertura" do |ant|
173
+ ant.taskdef :classpath=>Cobertura.requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
174
+ ant.send "cobertura-report", :format=>format,
175
+ :destdir=>cobertura.report_to(format), :datafile=>cobertura.data_file do
176
+ cobertura.sources.flatten.each do |src|
177
+ ant.fileset(:dir=>src.to_s) if File.exist?(src.to_s)
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
184
+
185
+ end
186
+
187
+ project.clean do
188
+ rm_rf [cobertura.report_to, cobertura.data_file, cobertura.instrumented_dir], :verbose=>false
189
+ end
190
+
191
+ end
192
+
193
+ end
194
+
195
+ class Buildr::Project
196
+ include CoberturaExtension
197
+ end
198
+
199
+ namespace "cobertura" do
200
+
201
+ task "instrument" do
202
+ Buildr.projects.each do |project|
203
+ project.cobertura.data_file = data_file
204
+ project.test.options[:properties]["net.sourceforge.cobertura.datafile"] = data_file
205
+ instrument_task ="#{project.name}:cobertura:instrument"
206
+ task(instrument_task).invoke if Rake::Task.task_defined?(instrument_task)
207
+ end
208
+ end
209
+
210
+ [:xml, :html].each do |format|
211
+ report_target = report_to(format)
212
+ desc "Run the test cases and produce code coverage reports in #{report_target}"
213
+ task format => ["instrument", "test"] do
214
+ info "Creating test coverage reports in #{report_target}"
215
+ Buildr.ant "cobertura" do |ant|
216
+ ant.taskdef :classpath=>requires.join(File::PATH_SEPARATOR), :resource=>"tasks.properties"
217
+ ant.send "cobertura-report", :destdir=>report_target, :format=>format, :datafile=>data_file do
218
+ Buildr.projects.map(&:cobertura).map(&:sources).flatten.each do |src|
219
+ ant.fileset :dir=>src.to_s if File.exist?(src.to_s)
220
+ end
221
+ end
222
+ end
223
+ end
224
+ end
225
+
226
+ task "clean" do
227
+ rm_rf [report_to, data_file], :verbose=>false
228
+ end
229
+ end
230
+
231
+ task "clean" do
232
+ task("cobertura:clean").invoke if Dir.pwd == Rake.application.original_dir
233
+ end
234
+
235
+ end
236
+ end
@@ -0,0 +1,238 @@
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
+ class << self
41
+
42
+ REQUIRES = ['emma:emma_ant:jar:2.0.5312', 'emma:emma:jar:2.0.5312'] unless const_defined?('REQUIRES')
43
+
44
+ def requires()
45
+ @requires ||= Buildr.artifacts(REQUIRES).each(&:invoke).map(&:to_s)
46
+ end
47
+
48
+ def report_to format=nil
49
+ File.expand_path('reports/emma')
50
+ end
51
+
52
+ def data_file()
53
+ File.join(report_to, 'coverage.es')
54
+ end
55
+
56
+ def ant
57
+ Buildr.ant 'emma' do |ant|
58
+ ant.taskdef :classpath=>requires.join(File::PATH_SEPARATOR), :resource=>'emma_ant.properties'
59
+ ant.emma :verbosity=>(Buildr.application.options.trace ? 'verbose' : 'warning') do
60
+ yield ant
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ class EmmaConfig # :nodoc:
67
+
68
+ def initialize(project)
69
+ @project = project
70
+ end
71
+
72
+ attr_reader :project
73
+ private :project
74
+
75
+ attr_writer :metadata_file, :coverage_file, :instrumented_dir, :report_dir
76
+
77
+ def coverage_file
78
+ @coverage_file ||= File.join(report_dir, 'coverage.ec')
79
+ end
80
+
81
+ def metadata_file
82
+ @metadata_file ||= File.join(report_dir, 'coverage.em')
83
+ end
84
+
85
+ def instrumented_dir
86
+ @instrumented_dir ||= project.path_to(:target, :instrumented, :classes)
87
+ end
88
+
89
+ def report_dir
90
+ @report_dir ||= project.path_to(:reports, :emma)
91
+ end
92
+
93
+ def report_to format
94
+ report_dir
95
+ end
96
+
97
+ # :call-seq:
98
+ # project.emma.include(*classPatterns)
99
+ #
100
+ def include(*classPatterns)
101
+ includes.push(*classPatterns)
102
+ self
103
+ end
104
+
105
+ def includes
106
+ @includeClasses ||= []
107
+ end
108
+
109
+ # :call-seq:
110
+ # project.emma.exclude(*classPatterns)
111
+ #
112
+ def exclude(*classPatterns)
113
+ excludes.push(*classPatterns)
114
+ self
115
+ end
116
+
117
+ def excludes
118
+ @excludeClasses ||= []
119
+ end
120
+
121
+ def sources
122
+ project.compile.sources
123
+ end
124
+ end
125
+
126
+ module EmmaExtension # :nodoc:
127
+ include Buildr::Extension
128
+
129
+ def emma
130
+ @emma_config ||= EmmaConfig.new(self)
131
+ end
132
+
133
+ after_define do |project|
134
+ emma = project.emma
135
+
136
+ namespace 'emma' do
137
+ unless project.compile.target.nil?
138
+ # Instrumented bytecode goes in a different directory. This task creates before running the test
139
+ # cases and monitors for changes in the generate bytecode.
140
+ instrumented = project.file(emma.instrumented_dir => project.compile.target) do |task|
141
+ unless project.compile.sources.empty?
142
+ info "Instrumenting classes with emma metadata file #{emma.metadata_file}"
143
+ Emma.ant do |ant|
144
+ ant.instr :instrpath=>project.compile.target.to_s, :destdir=>task.to_s, :metadatafile=>emma.metadata_file do
145
+ ant.filter :includes=>emma.includes.join(', ') unless emma.includes.empty?
146
+ ant.filter :excludes=>emma.excludes.join(', ') unless emma.excludes.empty?
147
+ end
148
+ end
149
+ touch task.to_s, :verbose=>false
150
+ end
151
+ end
152
+
153
+ task 'instrument' => instrumented
154
+
155
+ # We now have two target directories with bytecode.
156
+ project.test.dependencies.unshift emma.instrumented_dir
157
+ project.test.with Emma.requires
158
+ project.test.options[:properties]["emma.coverage.out.file"] = emma.coverage_file
159
+
160
+ [:xml, :html].each do |format|
161
+ task format => ['instrument', 'test'] do
162
+ missing_required_files = [emma.metadata_file, emma.coverage_file].reject { |f| File.exist?(f) }
163
+ if missing_required_files.empty?
164
+ info "Creating test coverage reports in #{emma.report_dir}"
165
+ mkdir_p emma.report_dir, :verbose=>false
166
+ Emma.ant do |ant|
167
+ ant.report do
168
+ ant.infileset :file=>emma.metadata_file
169
+ ant.infileset :file=>emma.coverage_file
170
+ ant.send format, :outfile=>File.join(emma.report_to(format),"coverage.#{format}")
171
+ ant.sourcepath do
172
+ emma.sources.flatten.each do |src|
173
+ ant.dirset(:dir=>src.to_s) if File.exist?(src.to_s)
174
+ end
175
+ end
176
+ end
177
+ end
178
+ else
179
+ info "No test coverage report for #{project}. Missing: #{missing_required_files.join(', ')}"
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
185
+
186
+ project.clean do
187
+ rm_rf [emma.report_dir, emma.coverage_file, emma.metadata_file, emma.instrumented_dir], :verbose=>false
188
+ end
189
+
190
+ end
191
+
192
+ end
193
+
194
+ class Buildr::Project
195
+ include EmmaExtension
196
+ end
197
+
198
+ namespace "emma" do
199
+
200
+ Project.local_task('instrument') { |name| "Instrumenting #{name}" }
201
+
202
+ [:xml, :html].each do |format|
203
+ desc "Run the test cases and produce code coverage reports in #{format}"
204
+ task format => ['instrument', 'test'] do
205
+ info "Creating test coverage reports in #{format}"
206
+ mkdir_p report_to(format), :verbose=>false
207
+ Emma.ant do |ant|
208
+ ant.merge :outfile=>data_file do
209
+ Buildr.projects.each do |project|
210
+ [project.emma.metadata_file, project.emma.coverage_file].each do |data_file|
211
+ ant.fileset :file=>data_file if File.exist?(data_file)
212
+ end
213
+ end
214
+ end
215
+ ant.report do
216
+ ant.infileset :file=>data_file
217
+ ant.send format, :outfile=>File.join(report_to(format), "coverage.#{format}")
218
+ ant.sourcepath do
219
+ Buildr.projects.map(&:emma).map(&:sources).flatten.map(&:to_s).each do |src|
220
+ ant.dirset :dir=>src if File.exist?(src)
221
+ end
222
+ end
223
+ end
224
+ end
225
+ end
226
+ end
227
+
228
+ task :clean do
229
+ rm_rf [report_to, data_file], :verbose=>false
230
+ end
231
+ end
232
+
233
+ task :clean do
234
+ task('emma:clean').invoke if Dir.pwd == Rake.application.original_dir
235
+ end
236
+
237
+ end
238
+ end