buildr 1.2.10 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. data/CHANGELOG +566 -268
  2. data/DISCLAIMER +7 -1
  3. data/KEYS +151 -0
  4. data/NOTICE +23 -8
  5. data/README +122 -22
  6. data/Rakefile +49 -229
  7. data/{lib → addon}/buildr/antlr.rb +23 -10
  8. data/addon/buildr/cobertura.rb +232 -0
  9. data/{lib → addon}/buildr/hibernate.rb +20 -4
  10. data/{lib → addon}/buildr/javacc.rb +27 -12
  11. data/addon/buildr/jdepend.rb +60 -0
  12. data/{lib → addon}/buildr/jetty.rb +34 -18
  13. data/addon/buildr/nailgun.rb +892 -0
  14. data/{lib → addon}/buildr/openjpa.rb +23 -6
  15. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  16. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  17. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  18. data/{lib/buildr/jetty → addon/buildr/org/apache/buildr}/JettyWrapper.java +19 -0
  19. data/{lib → addon}/buildr/xmlbeans.rb +39 -14
  20. data/bin/buildr +21 -7
  21. data/buildr.gemspec +50 -0
  22. data/doc/css/default.css +225 -0
  23. data/doc/css/print.css +95 -0
  24. data/doc/css/syntax.css +43 -0
  25. data/doc/images/apache-incubator-logo.png +0 -0
  26. data/doc/images/buildr-hires.png +0 -0
  27. data/doc/images/buildr.png +0 -0
  28. data/doc/images/note.png +0 -0
  29. data/doc/images/tip.png +0 -0
  30. data/doc/images/zbuildr.tif +0 -0
  31. data/doc/pages/artifacts.textile +317 -0
  32. data/doc/pages/building.textile +501 -0
  33. data/doc/pages/contributing.textile +178 -0
  34. data/doc/pages/download.textile +25 -0
  35. data/doc/pages/extending.textile +229 -0
  36. data/doc/pages/getting_started.textile +337 -0
  37. data/doc/pages/index.textile +63 -0
  38. data/doc/pages/mailing_lists.textile +17 -0
  39. data/doc/pages/more_stuff.textile +367 -0
  40. data/doc/pages/packaging.textile +592 -0
  41. data/doc/pages/projects.textile +449 -0
  42. data/doc/pages/recipes.textile +127 -0
  43. data/doc/pages/settings_profiles.textile +339 -0
  44. data/doc/pages/testing.textile +475 -0
  45. data/doc/pages/troubleshooting.textile +121 -0
  46. data/doc/pages/whats_new.textile +389 -0
  47. data/doc/print.haml +52 -0
  48. data/doc/print.toc.yaml +28 -0
  49. data/doc/scripts/buildr-git.rb +411 -0
  50. data/doc/scripts/install-jruby.sh +44 -0
  51. data/doc/scripts/install-linux.sh +64 -0
  52. data/doc/scripts/install-osx.sh +52 -0
  53. data/doc/site.haml +55 -0
  54. data/doc/site.toc.yaml +44 -0
  55. data/lib/buildr.rb +28 -45
  56. data/lib/buildr/core.rb +27 -0
  57. data/lib/buildr/core/application.rb +373 -0
  58. data/lib/buildr/core/application_cli.rb +134 -0
  59. data/lib/{core → buildr/core}/build.rb +91 -77
  60. data/lib/{core → buildr/core}/checks.rb +116 -95
  61. data/lib/buildr/core/common.rb +155 -0
  62. data/lib/buildr/core/compile.rb +594 -0
  63. data/lib/buildr/core/environment.rb +120 -0
  64. data/lib/buildr/core/filter.rb +258 -0
  65. data/lib/{core → buildr/core}/generate.rb +22 -5
  66. data/lib/buildr/core/help.rb +118 -0
  67. data/lib/buildr/core/progressbar.rb +156 -0
  68. data/lib/{core → buildr/core}/project.rb +468 -213
  69. data/lib/buildr/core/test.rb +690 -0
  70. data/lib/{core → buildr/core}/transports.rb +107 -127
  71. data/lib/buildr/core/util.rb +235 -0
  72. data/lib/buildr/ide.rb +19 -0
  73. data/lib/{java → buildr/ide}/eclipse.rb +86 -60
  74. data/lib/{java → buildr/ide}/idea.ipr.template +16 -0
  75. data/lib/buildr/ide/idea.rb +194 -0
  76. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  77. data/lib/buildr/ide/idea7x.rb +210 -0
  78. data/lib/buildr/java.rb +26 -0
  79. data/lib/buildr/java/ant.rb +71 -0
  80. data/lib/buildr/java/bdd_frameworks.rb +267 -0
  81. data/lib/buildr/java/commands.rb +210 -0
  82. data/lib/buildr/java/compilers.rb +432 -0
  83. data/lib/buildr/java/deprecated.rb +141 -0
  84. data/lib/buildr/java/groovyc.rb +137 -0
  85. data/lib/buildr/java/jruby.rb +99 -0
  86. data/lib/buildr/java/org/apache/buildr/BuildrNail$Main.class +0 -0
  87. data/lib/buildr/java/org/apache/buildr/BuildrNail.class +0 -0
  88. data/lib/buildr/java/org/apache/buildr/BuildrNail.java +41 -0
  89. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  90. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +116 -0
  91. data/lib/buildr/java/packaging.rb +706 -0
  92. data/lib/{java → buildr/java}/pom.rb +20 -4
  93. data/lib/buildr/java/rjb.rb +142 -0
  94. data/lib/buildr/java/test_frameworks.rb +290 -0
  95. data/lib/buildr/java/version_requirement.rb +172 -0
  96. data/lib/buildr/packaging.rb +21 -0
  97. data/lib/{java → buildr/packaging}/artifact.rb +170 -179
  98. data/lib/buildr/packaging/artifact_namespace.rb +957 -0
  99. data/lib/buildr/packaging/artifact_search.rb +140 -0
  100. data/lib/buildr/packaging/gems.rb +102 -0
  101. data/lib/buildr/packaging/package.rb +233 -0
  102. data/lib/{tasks → buildr/packaging}/tar.rb +18 -1
  103. data/lib/{tasks → buildr/packaging}/zip.rb +153 -105
  104. data/rakelib/apache.rake +126 -0
  105. data/rakelib/changelog.rake +56 -0
  106. data/rakelib/doc.rake +103 -0
  107. data/rakelib/package.rake +44 -0
  108. data/rakelib/release.rake +53 -0
  109. data/rakelib/rspec.rake +81 -0
  110. data/rakelib/rubyforge.rake +45 -0
  111. data/rakelib/scm.rake +49 -0
  112. data/rakelib/setup.rake +59 -0
  113. data/rakelib/stage.rake +45 -0
  114. data/spec/application_spec.rb +316 -0
  115. data/spec/archive_spec.rb +494 -0
  116. data/spec/artifact_namespace_spec.rb +635 -0
  117. data/spec/artifact_spec.rb +738 -0
  118. data/spec/build_spec.rb +193 -0
  119. data/spec/checks_spec.rb +537 -0
  120. data/spec/common_spec.rb +579 -0
  121. data/spec/compile_spec.rb +561 -0
  122. data/spec/groovy_compilers_spec.rb +239 -0
  123. data/spec/java_bdd_frameworks_spec.rb +238 -0
  124. data/spec/java_compilers_spec.rb +446 -0
  125. data/spec/java_packaging_spec.rb +1042 -0
  126. data/spec/java_test_frameworks_spec.rb +414 -0
  127. data/spec/packaging_helper.rb +63 -0
  128. data/spec/packaging_spec.rb +589 -0
  129. data/spec/project_spec.rb +739 -0
  130. data/spec/sandbox.rb +116 -0
  131. data/spec/scala_compilers_spec.rb +239 -0
  132. data/spec/spec.opts +6 -0
  133. data/spec/spec_helpers.rb +283 -0
  134. data/spec/test_spec.rb +871 -0
  135. data/spec/transport_spec.rb +300 -0
  136. data/spec/version_requirement_spec.rb +115 -0
  137. metadata +188 -77
  138. data/lib/buildr/cobertura.rb +0 -89
  139. data/lib/buildr/jdepend.rb +0 -40
  140. data/lib/buildr/jetty/JettyWrapper$1.class +0 -0
  141. data/lib/buildr/jetty/JettyWrapper$BuildrHandler.class +0 -0
  142. data/lib/buildr/jetty/JettyWrapper.class +0 -0
  143. data/lib/buildr/scala.rb +0 -368
  144. data/lib/core/application.rb +0 -188
  145. data/lib/core/common.rb +0 -562
  146. data/lib/core/help.rb +0 -72
  147. data/lib/core/rake_ext.rb +0 -81
  148. data/lib/java/ant.rb +0 -71
  149. data/lib/java/compile.rb +0 -589
  150. data/lib/java/idea.rb +0 -159
  151. data/lib/java/java.rb +0 -432
  152. data/lib/java/packaging.rb +0 -581
  153. data/lib/java/test.rb +0 -795
  154. data/lib/tasks/concat.rb +0 -35
@@ -1,795 +0,0 @@
1
- require "core/build"
2
- require "java/compile"
3
- require "java/ant"
4
- require "core/help"
5
-
6
-
7
- module Buildr
8
- module Java
9
-
10
- # *Deprecated:* Use the test task directly instead of calling test.junit.
11
- class JUnitTask < Rake::Task #:nodoc:
12
-
13
- # The classpath used for running the tests. Includes the compile classpath,
14
- # compiled classes (target). For everything else, add by calling #with.
15
- attr_accessor :classpath
16
-
17
- def initialize(*args) #:nodoc:
18
- super
19
- @parent = Rake::Task["#{name.split(":")[0...-1].join(":")}"]
20
- end
21
-
22
- # :call-seq:
23
- # include(*classes) => self
24
- #
25
- # Include only the specified test cases. Unless specified, the default is to include
26
- # all test cases. This method accepts multiple arguments and returns self.
27
- #
28
- # Test cases are specified using the fully qualified class name. You can also use file-like
29
- # patterns (glob) to specify collection of classes. For example:
30
- # test.include "com.example.FirstTest"
31
- # test.include "com.example.*"
32
- # test.include "com.example.Module*"
33
- # test.include "*.{First,Second}Test"
34
- #
35
- # By default, all classes that have a name ending with Test or Suite are included.
36
- # Use these suffixes for your test and test suite classes respectively, to distinguish them
37
- # from stubs, helper classes, etc.
38
- def include(*classes)
39
- @parent.include *classes
40
- self
41
- end
42
-
43
- # :call-seq:
44
- # exclude(*classes) => self
45
- #
46
- # Exclude the specified test cases. This method accepts multiple arguments and returns self.
47
- # See #include for the type of arguments you can use.
48
- def exclude(*classes)
49
- @parent.exclude *classes
50
- self
51
- end
52
-
53
- # :call-seq:
54
- # from(*paths) => self
55
- #
56
- # Specify one or more directories that include test cases.
57
- def from(*files)
58
- self
59
- end
60
-
61
- # :call-seq:
62
- # with(*specs) => self
63
- #
64
- # Specify artifacts (specs, tasks, files, etc) to include in the classpath when running
65
- # the test cases.
66
- def with(*files)
67
- (@parent.options[:classpath] ||= []).concat files.flatten
68
- self
69
- end
70
-
71
- # Returns the JUnit options.
72
- def options()
73
- @parent.options
74
- end
75
-
76
- # :call-seq:
77
- # using(options) => self
78
- #
79
- # Sets the JUnit options from a hash and returns self. Right now supports passing :properties to JUnit,
80
- # and :java_args to the JVM.
81
- #
82
- # For example:
83
- # test.junit.using :properties=>{ "root"=>base_dir }
84
- def using(options)
85
- @parent.using options
86
- self
87
- end
88
-
89
- end
90
-
91
-
92
- # The test task controls the entire test lifecycle.
93
- #
94
- # You can use the test task in three ways. You can access and configure specific test tasks,
95
- # e.g. enhance the #compile task, or run code during #setup/#teardown.
96
- #
97
- # You can use convenient methods that handle the most common settings. For example, add classpath
98
- # dependencies using #with, or include only specific test cases using #include.
99
- #
100
- # You can also enhance this task directly. This task will first execute the #compile task, followed
101
- # by the #setup task, run the unit tests, any other enhancements, and end by executing #teardown.
102
- #
103
- # Unit tests are fun from classed compiled by the test.compile class that match the TEST_FILE_PATTERN
104
- # (i.e. MyClassTest, MyClassTestSuite, etc). The test framework is determined by setting one of the
105
- # test framework options to true, for example:
106
- # test.unsing :testng
107
- class TestTask < Rake::Task
108
-
109
- class << self
110
-
111
- # Used by the local test and integration tasks to
112
- # a) Find the local project(s),
113
- # b) Find all its sub-projects and narrow down to those that have either unit or integration tests,
114
- # c) Run all the (either unit or integration) tests, and
115
- # d) Ignore failure if necessary.
116
- def run_local_tests(integration) #:nodoc:
117
- Project.local_projects do |project|
118
- # !(foo ^ bar) tests for equality and accepts nil as false (and select is less obfuscated than reject on ^).
119
- projects = ([project] + project.projects).select { |project| !(project.test.options[:integration] ^ integration) }
120
- projects.each do |project|
121
- puts "Testing #{project.name}" if verbose
122
- begin
123
- project.test.invoke
124
- rescue
125
- raise unless Buildr.options.test == :all
126
- end
127
- end
128
- end
129
- end
130
-
131
- # Used by the test/integration rule to only run tests that match the specified names.
132
- def only_run(tests) #:nodoc:
133
- tests = tests.map { |name| name =~ /\*/ ? name : "*#{name}*" }
134
- # Since the test case may reside in a sub-project, we need to set the include/exclude pattern on
135
- # all sub-projects, but only invoke test on the local project.
136
- Project.projects.each { |project| project.test.instance_eval { @include = tests ; @exclude.clear } }
137
- end
138
- end
139
-
140
- # List of supported test framework, first one being a default. Test frameworks are added by
141
- # including them in TestTask (e.g. JUnit, TestNG).
142
- TEST_FRAMEWORKS = []
143
-
144
- # Default options already set on each test task.
145
- DEFAULT_OPTIONS = { :fail_on_failure=>true, :fork=>:once, :properties=>{}, :environment=>{} }
146
-
147
- # JMock version..
148
- JMOCK_VERSION = "1.2.0"
149
- # JMock specification.
150
- JMOCK_REQUIRES = "jmock:jmock:jar:#{JMOCK_VERSION}"
151
-
152
- # The classpath used for running the tests. Includes the compiled classes (compile.target) and
153
- # their classpath dependencies. Will also include anything you pass to #with, shared between the
154
- # testing compile and run classpath dependencies.
155
- attr_reader :classpath
156
-
157
- def initialize(*args) #:nodoc:
158
- super
159
- @classpath = []
160
- @include = []
161
- @exclude = []
162
- parent = Project.task_in_parent_project(name)
163
- @options = parent && parent.respond_to?(:options) ? parent.options.clone : DEFAULT_OPTIONS.clone
164
- enhance { run_tests }
165
- end
166
-
167
- def execute() #:nodoc:
168
- setup.invoke
169
- begin
170
- super
171
- @project.task("test:junit").invoke # In case someone enhanced it
172
- rescue RuntimeError
173
- raise if options[:fail_on_failure]
174
- ensure
175
- teardown.invoke
176
- end
177
- end
178
-
179
- # *Deprecated* Add a prerequisite to the compile task instead.
180
- def prepare(*prereqs, &block)
181
- warn_deprecated "Add a prerequisite to the compile task instead of using the prepare task."
182
- @project.task("test:prepare").enhance prereqs, &block
183
- end
184
-
185
- # :call-seq:
186
- # compile(*sources) => CompileTask
187
- # compile(*sources) { |task| .. } => CompileTask
188
- #
189
- # The compile task is similar to the Project's compile task. However, it compiles all
190
- # files found in the src/java/test directory into the target/test-classes directory.
191
- # This task is executed by the test task before running any test cases.
192
- #
193
- # Once the project definition is complete, all classpath dependencies from the regular
194
- # compile task are copied over, so you only need to specify classpath dependencies
195
- # specific to your test cases. You can do so by calling #with on the test task.
196
- # The classpath dependencies used here are also copied over to the junit task.
197
- def compile(*sources, &block)
198
- @project.task("test:compile").from(sources).enhance &block
199
- end
200
-
201
- # :call-seq:
202
- # resources(*prereqs) => ResourcesTask
203
- # resources(*prereqs) { |task| .. } => ResourcesTask
204
- #
205
- # Executes by the #compile task to copy resource files over. See Project#resources.
206
- def resources(*prereqs, &block)
207
- @project.task("test:resources").enhance prereqs, &block
208
- end
209
-
210
- # *Deprecated* Use the test task directly instead of calling test.junit.
211
- def junit()
212
- warn_deprecated "Use the test task directly instead of calling test.junit."
213
- @project.task("test:junit")
214
- end
215
-
216
- # :call-seq:
217
- # setup(*prereqs) => task
218
- # setup(*prereqs) { |task| .. } => task
219
- #
220
- # Returns the setup task. The setup task is executed at the beginning of the test task,
221
- # after compiling the test files.
222
- def setup(*prereqs, &block)
223
- @project.task("test:setup").enhance prereqs, &block
224
- end
225
-
226
- # :call-seq:
227
- # teardown(*prereqs) => task
228
- # teardown(*prereqs) { |task| .. } => task
229
- #
230
- # Returns the teardown task. The teardown task is executed at the end of the test task.
231
- def teardown(*prereqs, &block)
232
- @project.task("test:teardown").enhance prereqs, &block
233
- end
234
-
235
- # :call-seq:
236
- # with(*specs) => self
237
- #
238
- # Specify artifacts (specs, tasks, files, etc) to include in the classpath when compiling
239
- # and running test cases.
240
- def with(*artifacts)
241
- @classpath |= Buildr.artifacts(artifacts.flatten).uniq
242
- compile.with artifacts
243
- self
244
- end
245
-
246
- # Returns various test options.
247
- attr_reader :options
248
-
249
- # :call-seq:
250
- # using(options) => self
251
- #
252
- # Sets various test options and returns self. Accepts a hash of options, or symbols (a symbol sets that
253
- # option to true). For example:
254
- # test.using :testng, :fork=>:each, :properties=>{ "url"=>"http://localhost:8080" }
255
- #
256
- # Currently supports the following options:
257
- # * :fail_on_failure -- True to fail on test failure (default is true).
258
- # * :fork -- Fork test cases (JUnit only).
259
- # * :java_args -- Java arguments when forking a new JVM.
260
- # * :properties -- System properties.
261
- # * :environment -- Environment variables.
262
- #
263
- # The :fork option takes the following values:
264
- # * :once -- Fork one JVM for each project (default).
265
- # * :each -- Fork one JVM for each test case.
266
- # * false -- Do not fork, running all test cases in the same JVM.
267
- def using(*args)
268
- args.pop.each { |key, value| options[key.to_sym] = value } if Hash === args.last
269
- args.each { |key| options[key.to_sym] = true }
270
- self
271
- end
272
-
273
- # :call-seq:
274
- # include(*classes) => self
275
- #
276
- # Include only the specified test cases. Unless specified, the default is to include
277
- # all test cases. This method accepts multiple arguments and returns self.
278
- #
279
- # Test cases are specified using the fully qualified class name. You can also use file-like
280
- # patterns (glob) to specify collection of classes. For example:
281
- # test.include "com.example.FirstTest"
282
- # test.include "com.example.*"
283
- # test.include "com.example.Module*"
284
- # test.include "*.{First,Second}Test"
285
- #
286
- # By default, all classes that have a name ending with Test or Suite are included.
287
- # Use these suffixes for your test and test suite classes respectively, to distinguish them
288
- # from stubs, helper classes, etc.
289
- def include(*classes)
290
- @include += classes
291
- self
292
- end
293
-
294
- # :call-seq:
295
- # exclude(*classes) => self
296
- #
297
- # Exclude the specified test cases. This method accepts multiple arguments and returns self.
298
- # See #include for the type of arguments you can use.
299
- def exclude(*classes)
300
- @exclude += classes
301
- self
302
- end
303
-
304
- # :call-seq:
305
- # classes() => strings
306
- #
307
- # List of test classes to run. Determined by finding all the test classes in the target directory,
308
- # and reducing based on the include/exclude patterns.
309
- def classes()
310
- base = Pathname.new(compile.target.to_s)
311
- patterns = self.class.const_get("#{framework.to_s.upcase}_TESTS_PATTERN").to_a
312
- FileList[patterns.map { |pattern| "#{base}/**/#{pattern}.class" }].
313
- map { |file| Pathname.new(file).relative_path_from(base).to_s.ext("").gsub(File::SEPARATOR, ".") }.
314
- select { |name| include?(name) }.reject { |name| name =~ /\$/ }.sort
315
- end
316
-
317
- # List of failed test classes. Set after running the tests.
318
- attr_reader :failed_tests
319
-
320
- # :call-seq:
321
- # include?(name) => boolean
322
- #
323
- # Returns true if the specified class name matches the inclusion/exclusion pattern. Used to determine
324
- # which tests to execute.
325
- def include?(name)
326
- (@include.empty? || @include.any? { |pattern| File.fnmatch(pattern, name) }) &&
327
- !@exclude.any? { |pattern| File.fnmatch(pattern, name) }
328
- end
329
-
330
- # :call-seq:
331
- # requires() => classpath
332
- #
333
- # Returns the classpath for the selected test frameworks. Necessary for compiling and running test cases.
334
- def requires()
335
- self.class.const_get("#{framework.to_s.upcase}_REQUIRES").to_a + [JMOCK_REQUIRES]
336
- end
337
-
338
- # :call-seq:
339
- # framework() => symbol
340
- #
341
- # Returns the test framework, e.g. :junit, :testng.
342
- def framework()
343
- @framework ||= TEST_FRAMEWORKS.detect { |name| options[name] } || TEST_FRAMEWORKS.first
344
- end
345
-
346
- # :call-seq:
347
- # report_to() => file
348
- #
349
- # Test frameworks that can produce reports, will write them to this directory.
350
- #
351
- # This is framework dependent, so unless you use the default test framework, call this method
352
- # after setting the test framework.
353
- def report_to()
354
- @report_to ||= file(@project.path_to(:reports, "#{framework}")=>self)
355
- end
356
-
357
- protected
358
-
359
- # :call-seq:
360
- # run_tests()
361
- #
362
- # Runs the test cases using the selected test framework. Executes as part of the task.
363
- def run_tests()
364
- classes = self.classes
365
- if classes.empty?
366
- @failed_tests = []
367
- else
368
- puts "Running tests in #{@project.name}" if verbose
369
- @failed_tests = send("#{framework}_run",
370
- :classes => classes,
371
- :classpath => @classpath + [compile.target],
372
- :properties => { 'baseDir' => compile.target.to_s }.merge(options[:properties] || {}),
373
- :environment=> options[:environment] || {},
374
- :java_args => options[:java_args] || Buildr.options.java_args)
375
- unless @failed_tests.empty?
376
- warn "The following tests failed:\n#{@failed_tests.join("\n")}" if verbose
377
- fail "Tests failed!"
378
- end
379
- end
380
- end
381
-
382
- end
383
-
384
-
385
- # The JUnit test framework. This is the default test framework, but you can force it by
386
- # adding the following to your project:
387
- # test.using :testng
388
- #
389
- # You can use the report method to control the junit:report task.
390
- module JUnit
391
-
392
- # Used by the junit:report task. Access through JUnit#report if you want to set various
393
- # options for that task, for example:
394
- # JUnit.report.frames = false
395
- class Report
396
-
397
- # Ant-Trax required for running the JUnitReport task.
398
- Java.wrapper.setup { |jw| jw.classpath << "org.apache.ant:ant-trax:jar:#{Ant::VERSION}" }
399
-
400
- # Parameters passed to the Ant JUnitReport task.
401
- attr_reader :params
402
- # True (default) to produce a report using frames, false to produce a single-page report.
403
- attr_accessor :frames
404
- # Directory for the report style (defaults to using the internal style).
405
- attr_accessor :style_dir
406
- # Target directory for generated report.
407
- attr_accessor :target
408
-
409
- def initialize()
410
- @params = {}
411
- @frames = true
412
- @target = "reports/junit"
413
- end
414
-
415
- # :call-seq:
416
- # generate(projects, target?)
417
- #
418
- # Generates a JUnit report for these projects (must run JUnit tests first) into the
419
- # target directory. You can specify a target, or let it pick the default one from the
420
- # target attribute.
421
- def generate(projects, target = @target.to_s)
422
- html_in = File.join(target, "html")
423
- rm_rf html_in ; mkpath html_in
424
-
425
- Buildr.ant("junit-report") do |ant|
426
- ant.junitreport :todir=>target do
427
- projects.select { |project| project.test.framework == :junit }.
428
- map { |project| project.test.report_to.to_s }.select { |path| File.exist?(path) }.
429
- each { |path| ant.fileset(:dir=>path) { ant.include :name=>"TEST-*.xml" } }
430
- options = { :format=>frames ? "frames" : "noframes" }
431
- options[:styledir] = style_dir if style_dir
432
- ant.report options.merge(:todir=>html_in) do
433
- params.each { |key, value| ant.param :name=>key, :expression=>value }
434
- end
435
- end
436
- end
437
- end
438
-
439
- end
440
-
441
- # JUnit version number.
442
- JUNIT_VERSION = "4.3.1"
443
- # JUnit specification.
444
- JUNIT_REQUIRES = "junit:junit:jar:#{JUNIT_VERSION}"
445
- # Pattern for selecting JUnit test classes. Regardless of include/exclude patterns, only classes
446
- # that match this pattern are used.
447
- JUNIT_TESTS_PATTERN = [ "Test*", "*Test" ]
448
-
449
- # Ant-JUnit requires for JUnit and JUnit reports tasks.
450
- Java.wrapper.setup { |jw| jw.classpath << "org.apache.ant:ant-junit:jar:#{Ant::VERSION}" }
451
-
452
- class << self
453
-
454
- # :call-seq:
455
- # report()
456
- #
457
- # Returns the Report object used by the junit:report task. You can use this object to set
458
- # various options that affect your report, for example:
459
- # JUnit.report.frames = false
460
- # JUnit.report.params["title"] = "My App"
461
- def report()
462
- @report ||= Report.new
463
- end
464
-
465
- def included(mod)
466
- mod::TEST_FRAMEWORKS << :junit
467
- end
468
- private :included
469
-
470
- end
471
-
472
- private
473
-
474
- def junit_run(args)
475
- rm_rf report_to.to_s ; mkpath report_to.to_s
476
- # Use Ant to execute the Junit tasks, gives us performance and reporting.
477
- Buildr.ant("junit") do |ant|
478
- case options[:fork]
479
- when false
480
- forking = {}
481
- when :each
482
- forking = { :fork=>true, :forkmode=>"perTest" }
483
- when true, :once
484
- forking = { :fork=>true, :forkmode=>"once" }
485
- else
486
- fail "Option fork must be :once, :each or false."
487
- end
488
- ant.junit forking.merge(:clonevm=>options[:clonevm] || false, :dir=>@project.path_to) do
489
- ant.classpath :path=>args[:classpath].map(&:to_s).each { |path| file(path).invoke }.join(File::PATH_SEPARATOR)
490
- args[:properties].each { |key, value| ant.sysproperty :key=>key, :value=>value }
491
- args[:environment].each { |key, value| ant.env :key=>key, :value=>value }
492
- java_args = args[:java_args]
493
- java_args = java_args.split(" ") if String === java_args
494
- java_args.each { |value| ant.jvmarg :value=>value } if java_args
495
- ant.formatter :type=>"plain"
496
- ant.formatter :type=>"xml"
497
- ant.formatter :type=>"plain", :usefile=>false # log test
498
- ant.formatter :type=>"xml"
499
- ant.batchtest :todir=>report_to.to_s, :failureproperty=>"failed" do
500
- ant.fileset :dir=>compile.target.to_s do
501
- args[:classes].each { |cls| ant.include :name=>cls.gsub(".", "/").ext("class") }
502
- end
503
- end
504
- end
505
- return [] unless ant.project.getProperty("failed")
506
- end
507
- # But Ant doesn't tell us what went kaput, so we'll have to parse the test files.
508
- args[:classes].inject([]) do |failed, name|
509
- if report = File.read(File.join(report_to.to_s, "TEST-#{name}.txt")) rescue nil
510
- # The second line (if exists) is the status line and we scan it for its values.
511
- status = (report.split("\n")[1] || "").scan(/(run|failures|errors):\s*(\d+)/i).
512
- inject(Hash.new(0)) { |hash, pair| hash[pair[0].downcase.to_sym] = pair[1].to_i ; hash }
513
- failed << name if status[:failures] > 0 || status[:errors] > 0
514
- end
515
- failed
516
- end
517
- end
518
-
519
- namespace "junit" do
520
- desc "Generate JUnit tests report in #{report.target}"
521
- task("report") do |task|
522
- report.generate Project.projects
523
- puts "Generated JUnit tests report in #{report.target}"
524
- end
525
- end
526
-
527
- task("clean") { rm_rf report.target.to_s }
528
-
529
- end
530
-
531
-
532
- # The TestNG test framework. Use by adding the following to your project:
533
- # test.using :testng
534
- module TestNG
535
-
536
- # TestNG version number.
537
- TESTNG_VERSION = "5.5"
538
- # TestNG specification.
539
- TESTNG_REQUIRES = "org.testng:testng:jar:jdk15:#{TESTNG_VERSION}"
540
- # Pattern for selecting TestNG test classes. Regardless of include/exclude patterns, only classes
541
- # that match this pattern are used.
542
- TESTNG_TESTS_PATTERN = [ "Test*", "*Test", "*TestCase" ]
543
-
544
- class << self
545
-
546
- def included(mod)
547
- mod::TEST_FRAMEWORKS << :testng
548
- end
549
- private :included
550
-
551
- end
552
-
553
- private
554
-
555
- def testng_run(args)
556
- cmd_args = [ "org.testng.TestNG", "-sourcedir", compile.sources.join(";"), "-suitename", @project.name ]
557
- cmd_args << "-d" << report_to.to_s
558
- cmd_options = args.only(:classpath, :properties, :java_args)
559
- args[:classes].inject([]) do |failed, test|
560
- begin
561
- Buildr.java cmd_args, "-testclass", test, cmd_options.merge(:name=>test)
562
- failed
563
- rescue
564
- failed << test
565
- end
566
- end
567
- end
568
-
569
- end
570
-
571
- class TestTask ; include JUnit ; include TestNG ; end
572
-
573
- end
574
-
575
-
576
- class Project
577
-
578
- # :call-seq:
579
- # test(*prereqs) => TestTask
580
- # test(*prereqs) { |task| .. } => TestTask
581
- #
582
- # Returns the test task. The test task controls the entire test lifecycle.
583
- #
584
- # You can use the test task in three ways. You can access and configure specific
585
- # test tasks, e.g. enhance the compile task by calling test.compile, setup for
586
- # the test cases by enhancing test.setup and so forth.
587
- #
588
- # You can use convenient methods that handle the most common settings. For example,
589
- # add classpath dependencies using test.with, or include only specific test cases
590
- # using test.include.
591
- #
592
- # You can also enhance this task directly. This method accepts a list of arguments
593
- # that are used as prerequisites and an optional block that will be executed by the
594
- # test task.
595
- #
596
- # This task compiles the project and the test cases (in that order) before running any tests.
597
- # It execute the setup task, runs all the test cases, any enhancements, and ends with the
598
- # teardown tasks.
599
- def test(*prereqs, &block)
600
- task("test").enhance prereqs, &block
601
- end
602
-
603
- end
604
-
605
-
606
- Project.on_define do |project|
607
- # Define a recursive test task, and pass it a reference to the project so it can discover all other tasks.
608
- Java::TestTask.define_task("test")
609
- project.test.instance_eval { instance_variable_set :@project, project }
610
- #project.recursive_task("test")
611
- # Similar to the regular resources task but using different paths.
612
- resources = Java::ResourcesTask.define_task("test:resources")
613
- project.path_to("src/test/resources").tap { |dir| resources.from dir if File.exist?(dir) }
614
- # Similar to the regular compile task but using different paths.
615
- compile = Java::CompileTask.define_task("test:compile"=>[project.compile, task("test:prepare"), project.test.resources])
616
- project.path_to("src/test/java").tap { |dir| compile.from dir if File.exist?(dir) }
617
- compile.into project.path_to(:target, "test-classes")
618
- resources.filter.into compile.target
619
- project.test.enhance [compile]
620
- # Define the JUnit task here, otherwise we get a normal task.
621
- Java::JUnitTask.define_task("test:junit")
622
- # Define these tasks once, otherwise we may get a namespace error.
623
- project.test.setup ; project.test.teardown
624
-
625
- project.enhance do |project|
626
- # Copy the regular compile classpath over, and also include the generated classes, both of which
627
- # can be used in the test cases. And don't forget the classpath required by the test framework (e.g. JUnit).
628
- project.test.with project.compile.classpath, project.compile.target, project.test.requires
629
- project.clean do
630
- verbose(false) do
631
- rm_rf project.test.compile.target.to_s
632
- rm_rf project.test.report_to.to_s
633
- end
634
- end
635
- end
636
- end
637
-
638
-
639
- class Options
640
-
641
- # Runs test cases after the build when true (default). This forces test cases to execute
642
- # after the build, including when running build related tasks like install, deploy and release.
643
- #
644
- # Set to false to not run any test cases. Set to :all to run all test cases, ignoring failures.
645
- #
646
- # This option is set from the environment variable "test", so you can also do:
647
-
648
- # Returns the test option (environment variable TEST). Possible values are:
649
- # * :false -- Do not run any test cases (also accepts "no" and "skip").
650
- # * :true -- Run all test cases, stop on failure (default if not set).
651
- # * :all -- Run all test cases, ignore failures.
652
- def test()
653
- case value = ENV["TEST"] || ENV["test"]
654
- when /^(no|off|false|skip)$/i
655
- false
656
- when /^all$/i
657
- :all
658
- when /^(yes|on|true)$/i, nil
659
- true
660
- else
661
- warn "Expecting the environment variable test to be 'no' or 'all', not sure what to do with #{value}, so I'm just going to run all the test cases and stop at failure."
662
- true
663
- end
664
- end
665
-
666
- # Sets the test option (environment variable TEST). Possible values are true, false or :all.
667
- #
668
- # You can also set this from the environment variable, e.g.:
669
- #
670
- # buildr # With tests
671
- # buildr test=no # Without tests
672
- # buildr test=all # Ignore failures
673
- # set TEST=no
674
- # buildr # Without tests
675
- def test=(flag)
676
- ENV["test"] = nil
677
- ENV["TEST"] = flag.to_s
678
- end
679
-
680
- end
681
-
682
-
683
- desc "Run all test cases"
684
- task("test") { TestTask.run_local_tests false }
685
-
686
- # This rule takes a suffix and runs that test case in the current project. For example;
687
- # buildr test:MyTest
688
- # will run the test case class com.example.MyTest, if found in the current project.
689
- #
690
- # If you want to run multiple test cases, separate tham with a comma. You can also use glob
691
- # (* and ?) patterns to match multiple tests, e.g. com.example.* to run all test cases in
692
- # a given package. If you don't specify a glob pattern, asterisks are added for you.
693
- rule /^test:.*$/ do |task|
694
- TestTask.only_run task.name.scan(/test:(.*)/)[0][0].split(",")
695
- task("test").invoke
696
- end
697
-
698
- task "build" do |task|
699
- # Make sure this happens as the last action on the build, so all other enhancements
700
- # are made to run before starting the test cases.
701
- task.enhance do
702
- task("test").invoke unless Buildr.options.test == false
703
- end
704
- end
705
-
706
-
707
- # The integration tests task. Buildr has one such task (see Buildr#integration) that runs
708
- # all tests marked with :integration=>true, and has a setup/teardown tasks separate from
709
- # the unit tests.
710
- class IntegrationTestsTask < Rake::Task
711
-
712
- def initialize(*args) #:nodoc:
713
- super
714
- task "#{name}-setup"
715
- task "#{name}-teardown"
716
- enhance { puts "Running integration tests..." if verbose }
717
- end
718
-
719
- def execute() #:nodoc:
720
- setup.invoke
721
- begin
722
- super
723
- ensure
724
- teardown.invoke
725
- end
726
- end
727
-
728
- # :call-seq:
729
- # setup(*prereqs) => task
730
- # setup(*prereqs) { |task| .. } => task
731
- #
732
- # Returns the setup task. The setup task is executed before running the integration tests.
733
- def setup(*prereqs, &block)
734
- Rake::Task["rake:integration-setup"].enhance prereqs, &block
735
- end
736
-
737
- # :call-seq:
738
- # teardown(*prereqs) => task
739
- # teardown(*prereqs) { |task| .. } => task
740
- #
741
- # Returns the teardown task. The teardown task is executed after running the integration tests.
742
- def teardown(*prereqs, &block)
743
- Rake::Task["rake:integration-teardown"].enhance prereqs, &block
744
- end
745
-
746
- end
747
-
748
- # :call-seq:
749
- # integration() { |task| .... }
750
- # integration() => IntegrationTestTask
751
- #
752
- # Use this method to return the integration tests task, or enhance it with a block to execute.
753
- #
754
- # There is one integration tests task you can execute directly, or as a result of running the package
755
- # task (or tasks that depend on it, like install and deploy). It contains all the tests marked with
756
- # :integration=>true, all other tests are considered unit tests and run by the test task before packaging.
757
- # So essentially: build=>test=>packaging=>integration=>install/deploy.
758
- #
759
- # You add new test cases from projects that define integration tests using the regular test task,
760
- # but with the following addition:
761
- # test.using :integration
762
- #
763
- # Use this method to enhance the setup and teardown tasks that are executed before (and after) all
764
- # integration tests are run, for example, to start a Web server or create a database.
765
- def integration(*deps, &block)
766
- Rake::Task["rake:integration"].enhance deps, &block
767
- end
768
-
769
- IntegrationTestsTask.define_task("integration") { TestTask.run_local_tests true }
770
-
771
- # Similar to test:[pattern] but for integration tests.
772
- rule /^integration:.*$/ do |task|
773
- TestTask.only_run task.name.scan(/integration:(.*)/)[0][0].split(",")
774
- task("integration").invoke
775
- end
776
-
777
- # Anything that comes after local packaging (install, deploy) executes the integration tests,
778
- # which do not conflict with integration invoking the project's own packaging (package=>
779
- # integration=>foo:package is not circular, just confusing to debug.)
780
- task "package" do |task|
781
- integration.invoke if Buildr.options.test && Rake.application.original_dir == Dir.pwd
782
- end
783
-
784
-
785
- task("help") do
786
- puts
787
- puts "To run a full build without running any test cases:"
788
- puts " buildr test=no"
789
- puts "To run specific test case:"
790
- puts " buildr test:MyTest"
791
- puts "To run integration tests:"
792
- puts " buildr integration"
793
- end
794
-
795
- end