mguymon-buildr 1.4.5-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. data/CHANGELOG +1291 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +44 -0
  6. data/_buildr +35 -0
  7. data/_jbuildr +35 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/bnd.rb +147 -0
  10. data/addon/buildr/cobertura.rb +22 -0
  11. data/addon/buildr/drb.rb +281 -0
  12. data/addon/buildr/emma.rb +22 -0
  13. data/addon/buildr/hibernate.rb +149 -0
  14. data/addon/buildr/javacc.rb +85 -0
  15. data/addon/buildr/jaxb_xjc.rb +72 -0
  16. data/addon/buildr/jdepend.rb +60 -0
  17. data/addon/buildr/jetty.rb +248 -0
  18. data/addon/buildr/jibx.rb +86 -0
  19. data/addon/buildr/nailgun.rb +221 -0
  20. data/addon/buildr/openjpa.rb +88 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  22. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  23. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  26. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  27. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  28. data/addon/buildr/protobuf.rb +88 -0
  29. data/addon/buildr/xmlbeans.rb +93 -0
  30. data/bin/buildr +19 -0
  31. data/buildr.buildfile +58 -0
  32. data/buildr.gemspec +78 -0
  33. data/doc/_config.yml +1 -0
  34. data/doc/_layouts/default.html +90 -0
  35. data/doc/_layouts/preface.html +22 -0
  36. data/doc/artifacts.textile +217 -0
  37. data/doc/building.textile +276 -0
  38. data/doc/contributing.textile +268 -0
  39. data/doc/css/default.css +236 -0
  40. data/doc/css/print.css +101 -0
  41. data/doc/css/syntax.css +23 -0
  42. data/doc/download.textile +151 -0
  43. data/doc/extending.textile +212 -0
  44. data/doc/images/1442160941-frontcover.jpg +0 -0
  45. data/doc/images/asf-logo.gif +0 -0
  46. data/doc/images/asf-logo.png +0 -0
  47. data/doc/images/buildr-hires.png +0 -0
  48. data/doc/images/buildr.png +0 -0
  49. data/doc/images/favicon.png +0 -0
  50. data/doc/images/growl-icon.tiff +0 -0
  51. data/doc/images/note.png +0 -0
  52. data/doc/images/project-structure.png +0 -0
  53. data/doc/images/tip.png +0 -0
  54. data/doc/images/zbuildr.png +0 -0
  55. data/doc/images/zbuildr.tif +0 -0
  56. data/doc/index.textile +109 -0
  57. data/doc/installing.textile +284 -0
  58. data/doc/languages.textile +599 -0
  59. data/doc/mailing_lists.textile +29 -0
  60. data/doc/more_stuff.textile +845 -0
  61. data/doc/packaging.textile +618 -0
  62. data/doc/preface.textile +54 -0
  63. data/doc/projects.textile +276 -0
  64. data/doc/quick_start.textile +210 -0
  65. data/doc/releasing.textile +117 -0
  66. data/doc/scripts/buildr-git.rb +512 -0
  67. data/doc/scripts/gitflow.rb +296 -0
  68. data/doc/scripts/install-jruby.sh +44 -0
  69. data/doc/scripts/install-linux.sh +73 -0
  70. data/doc/scripts/install-osx.sh +52 -0
  71. data/doc/settings_profiles.textile +287 -0
  72. data/doc/testing.textile +247 -0
  73. data/etc/KEYS +189 -0
  74. data/lib/buildr.rb +44 -0
  75. data/lib/buildr/clojure.rb +34 -0
  76. data/lib/buildr/clojure/shell.rb +52 -0
  77. data/lib/buildr/core.rb +34 -0
  78. data/lib/buildr/core/application.rb +700 -0
  79. data/lib/buildr/core/build.rb +516 -0
  80. data/lib/buildr/core/cc.rb +166 -0
  81. data/lib/buildr/core/checks.rb +253 -0
  82. data/lib/buildr/core/common.rb +151 -0
  83. data/lib/buildr/core/compile.rb +622 -0
  84. data/lib/buildr/core/doc.rb +276 -0
  85. data/lib/buildr/core/environment.rb +129 -0
  86. data/lib/buildr/core/filter.rb +404 -0
  87. data/lib/buildr/core/generate.rb +197 -0
  88. data/lib/buildr/core/help.rb +119 -0
  89. data/lib/buildr/core/jrebel.rb +42 -0
  90. data/lib/buildr/core/linux.rb +30 -0
  91. data/lib/buildr/core/osx.rb +46 -0
  92. data/lib/buildr/core/progressbar.rb +161 -0
  93. data/lib/buildr/core/project.rb +975 -0
  94. data/lib/buildr/core/run.rb +43 -0
  95. data/lib/buildr/core/shell.rb +137 -0
  96. data/lib/buildr/core/test.rb +843 -0
  97. data/lib/buildr/core/transports.rb +575 -0
  98. data/lib/buildr/core/util.rb +537 -0
  99. data/lib/buildr/groovy.rb +20 -0
  100. data/lib/buildr/groovy/bdd.rb +106 -0
  101. data/lib/buildr/groovy/compiler.rb +153 -0
  102. data/lib/buildr/groovy/doc.rb +76 -0
  103. data/lib/buildr/groovy/shell.rb +57 -0
  104. data/lib/buildr/ide.rb +19 -0
  105. data/lib/buildr/ide/eclipse.rb +427 -0
  106. data/lib/buildr/ide/eclipse/java.rb +53 -0
  107. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  108. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  109. data/lib/buildr/ide/idea.rb +576 -0
  110. data/lib/buildr/java.rb +25 -0
  111. data/lib/buildr/java/ant.rb +94 -0
  112. data/lib/buildr/java/bdd.rb +460 -0
  113. data/lib/buildr/java/cobertura.rb +297 -0
  114. data/lib/buildr/java/commands.rb +223 -0
  115. data/lib/buildr/java/compiler.rb +135 -0
  116. data/lib/buildr/java/deprecated.rb +141 -0
  117. data/lib/buildr/java/doc.rb +86 -0
  118. data/lib/buildr/java/ecj.rb +69 -0
  119. data/lib/buildr/java/emma.rb +244 -0
  120. data/lib/buildr/java/external.rb +73 -0
  121. data/lib/buildr/java/jruby.rb +122 -0
  122. data/lib/buildr/java/jtestr_result.rb +295 -0
  123. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  124. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  125. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  126. data/lib/buildr/java/packaging.rb +734 -0
  127. data/lib/buildr/java/pom.rb +178 -0
  128. data/lib/buildr/java/rjb.rb +154 -0
  129. data/lib/buildr/java/test_result.rb +101 -0
  130. data/lib/buildr/java/tests.rb +362 -0
  131. data/lib/buildr/java/version_requirement.rb +172 -0
  132. data/lib/buildr/packaging.rb +25 -0
  133. data/lib/buildr/packaging/archive.rb +535 -0
  134. data/lib/buildr/packaging/artifact.rb +904 -0
  135. data/lib/buildr/packaging/artifact_namespace.rb +984 -0
  136. data/lib/buildr/packaging/artifact_search.rb +140 -0
  137. data/lib/buildr/packaging/gems.rb +105 -0
  138. data/lib/buildr/packaging/package.rb +249 -0
  139. data/lib/buildr/packaging/repository_array.rb +108 -0
  140. data/lib/buildr/packaging/tar.rb +189 -0
  141. data/lib/buildr/packaging/version_requirement.rb +192 -0
  142. data/lib/buildr/packaging/zip.rb +178 -0
  143. data/lib/buildr/packaging/ziptask.rb +356 -0
  144. data/lib/buildr/resources/buildr.icns +0 -0
  145. data/lib/buildr/resources/completed.png +0 -0
  146. data/lib/buildr/resources/failed.png +0 -0
  147. data/lib/buildr/resources/icons-license.txt +17 -0
  148. data/lib/buildr/run.rb +195 -0
  149. data/lib/buildr/scala.rb +26 -0
  150. data/lib/buildr/scala/bdd.rb +118 -0
  151. data/lib/buildr/scala/compiler.rb +242 -0
  152. data/lib/buildr/scala/doc.rb +142 -0
  153. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  154. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
  155. data/lib/buildr/scala/shell.rb +52 -0
  156. data/lib/buildr/scala/tests.rb +171 -0
  157. data/lib/buildr/shell.rb +185 -0
  158. data/lib/buildr/version.rb +18 -0
  159. data/rakelib/all-in-one.rake +113 -0
  160. data/rakelib/checks.rake +57 -0
  161. data/rakelib/doc.rake +137 -0
  162. data/rakelib/metrics.rake +39 -0
  163. data/rakelib/package.rake +73 -0
  164. data/rakelib/release.rake +160 -0
  165. data/rakelib/rspec.rake +91 -0
  166. data/rakelib/setup.rake +66 -0
  167. data/rakelib/stage.rake +220 -0
  168. data/spec/addon/bnd_spec.rb +330 -0
  169. data/spec/addon/drb_spec.rb +328 -0
  170. data/spec/addon/jaxb_xjc_spec.rb +125 -0
  171. data/spec/core/application_spec.rb +631 -0
  172. data/spec/core/build_spec.rb +837 -0
  173. data/spec/core/cc_spec.rb +224 -0
  174. data/spec/core/checks_spec.rb +519 -0
  175. data/spec/core/common_spec.rb +725 -0
  176. data/spec/core/compile_spec.rb +658 -0
  177. data/spec/core/doc_spec.rb +195 -0
  178. data/spec/core/extension_spec.rb +201 -0
  179. data/spec/core/generate_spec.rb +33 -0
  180. data/spec/core/project_spec.rb +772 -0
  181. data/spec/core/run_spec.rb +93 -0
  182. data/spec/core/shell_spec.rb +146 -0
  183. data/spec/core/test_spec.rb +1320 -0
  184. data/spec/core/transport_spec.rb +544 -0
  185. data/spec/core/util_spec.rb +141 -0
  186. data/spec/groovy/bdd_spec.rb +80 -0
  187. data/spec/groovy/compiler_spec.rb +251 -0
  188. data/spec/groovy/doc_spec.rb +65 -0
  189. data/spec/ide/eclipse_spec.rb +739 -0
  190. data/spec/ide/idea_spec.rb +1145 -0
  191. data/spec/java/ant_spec.rb +37 -0
  192. data/spec/java/bdd_spec.rb +374 -0
  193. data/spec/java/cobertura_spec.rb +112 -0
  194. data/spec/java/commands_spec.rb +93 -0
  195. data/spec/java/compiler_spec.rb +252 -0
  196. data/spec/java/doc_spec.rb +56 -0
  197. data/spec/java/ecj_spec.rb +115 -0
  198. data/spec/java/emma_spec.rb +121 -0
  199. data/spec/java/external_spec.rb +56 -0
  200. data/spec/java/java_spec.rb +132 -0
  201. data/spec/java/packaging_spec.rb +1266 -0
  202. data/spec/java/run_spec.rb +78 -0
  203. data/spec/java/test_coverage_helper.rb +257 -0
  204. data/spec/java/tests_spec.rb +497 -0
  205. data/spec/packaging/archive_spec.rb +775 -0
  206. data/spec/packaging/artifact_namespace_spec.rb +743 -0
  207. data/spec/packaging/artifact_spec.rb +1074 -0
  208. data/spec/packaging/packaging_helper.rb +63 -0
  209. data/spec/packaging/packaging_spec.rb +719 -0
  210. data/spec/packaging/repository_array_spec.rb +109 -0
  211. data/spec/sandbox.rb +165 -0
  212. data/spec/scala/bdd_spec.rb +124 -0
  213. data/spec/scala/compiler_spec.rb +289 -0
  214. data/spec/scala/doc_spec.rb +88 -0
  215. data/spec/scala/scala.rb +38 -0
  216. data/spec/scala/tests_spec.rb +283 -0
  217. data/spec/spec_helpers.rb +369 -0
  218. data/spec/version_requirement_spec.rb +143 -0
  219. data/spec/xpath_matchers.rb +121 -0
  220. metadata +600 -0
@@ -0,0 +1,43 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ require 'buildr/run'
17
+ require 'buildr/java/commands'
18
+ require 'buildr/core/util'
19
+
20
+ module Buildr
21
+ module Run
22
+
23
+ class JavaRunner < Base
24
+ include Buildr::JRebel
25
+
26
+ specify :name => :java, :languages => [:java, :scala, :groovy, :clojure]
27
+
28
+ def run(task)
29
+ fail "Missing :main option" unless task.options[:main]
30
+ cp = project.compile.dependencies + [project.path_to(:target, :classes)] + task.classpath
31
+ Java::Commands.java(task.options[:main], {
32
+ :properties => jrebel_props(project).merge(task.options[:properties] || {}),
33
+ :classpath => cp,
34
+ :java_args => jrebel_args + (task.options[:java_args] || [])
35
+ })
36
+ end
37
+ end # JavaRunnner
38
+
39
+ end
40
+ end
41
+
42
+ Buildr::Run.runners << Buildr::Run::JavaRunner
43
+
@@ -0,0 +1,137 @@
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/shell'
18
+ require 'buildr/java/commands'
19
+ require 'buildr/core/util'
20
+
21
+ module Buildr
22
+
23
+ module Shell
24
+
25
+ class BeanShell < Base
26
+ include Buildr::JRebel
27
+
28
+ VERSION = '2.0b4'
29
+
30
+ specify :name => :bsh, :languages => [:java]
31
+
32
+ class << self
33
+ def version
34
+ Buildr.settings.build['bsh'] || VERSION
35
+ end
36
+
37
+ def artifact
38
+ "org.beanshell:bsh:jar:#{version}"
39
+ end
40
+ end
41
+
42
+ def launch(task)
43
+ cp = ( project.compile.dependencies +
44
+ [project.path_to(:target, :classes), Buildr.artifact(BeanShell.artifact)] +
45
+ task.classpath )
46
+ Java::Commands.java 'bsh.Console', {
47
+ :properties => jrebel_props(project).merge(task.properties),
48
+ :classpath => cp,
49
+ :java_args => jrebel_args + task.java_args
50
+ }
51
+ end
52
+
53
+ end # BeanShell
54
+
55
+
56
+ class JIRB < Base
57
+ include JRebel
58
+
59
+ JRUBY_VERSION = '1.4.0'
60
+
61
+ def launch(task)
62
+ if jruby_home # if JRuby is installed, use it
63
+ cp = project.compile.dependencies +
64
+ [project.path_to(:target, :classes)] +
65
+ Dir.glob("#{jruby_home}#{File::SEPARATOR}lib#{File::SEPARATOR}*.jar") +
66
+ task.classpath
67
+
68
+ props = {
69
+ 'jruby.home' => jruby_home,
70
+ 'jruby.lib' => "#{jruby_home}#{File::SEPARATOR}lib"
71
+ }
72
+ props.merge! jrebel_props(project)
73
+ props.merge! task.properties
74
+
75
+ if not Util.win_os?
76
+ uname = `uname -m`
77
+ cpu = if uname =~ /i[34567]86/
78
+ 'i386'
79
+ elsif uname == 'i86pc'
80
+ 'x86'
81
+ elsif uname =~ /amd64|x86_64/
82
+ 'amd64'
83
+ end
84
+
85
+ os = `uname -s | tr '[A-Z]' '[a-z]'`
86
+ path = if os == 'darwin'
87
+ 'darwin'
88
+ else
89
+ "#{os}-#{cpu}"
90
+ end
91
+
92
+ props['jna.boot.library.path'] = "#{jruby_home}/lib/native/#{path}"
93
+ end
94
+
95
+ props['jruby.script'] = if Util.win_os? then 'jruby.bat' else 'jruby' end
96
+ props['jruby.shell'] = if Util.win_os? then 'cmd.exe' else '/bin/sh' end
97
+
98
+ args = [
99
+ "-Xbootclasspath/a:#{Dir.glob("#{jruby_home}#{File::SEPARATOR}lib#{File::SEPARATOR}jruby*.jar").join File::PATH_SEPARATOR}"
100
+ ] + jrebel_args + task.java_args
101
+
102
+ Java::Commands.java 'org.jruby.Main', "#{jruby_home}#{File::SEPARATOR}bin#{File::SEPARATOR}jirb", {
103
+ :properties => props,
104
+ :classpath => cp,
105
+ :java_args => args
106
+ }
107
+ else
108
+ cp = project.compile.dependencies + [ jruby_artifact, project.path_to(:target, :classes) ] +
109
+ task.classpath
110
+ props = jrebel_props(project).merge(task.properties)
111
+ args = jrebel_args + task.java_args
112
+
113
+ Java::Commands.java 'org.jruby.Main', '--command', 'irb', {
114
+ :properties => props,
115
+ :classpath => cp,
116
+ :java_args => args
117
+ }
118
+ end
119
+ end
120
+
121
+ private
122
+ def jruby_home
123
+ @jruby_home ||= RUBY_PLATFORM =~ /java/ ? Config::CONFIG['prefix'] : ENV['JRUBY_HOME']
124
+ end
125
+
126
+ def jruby_artifact
127
+ version = Buildr.settings.build['jruby'] || JRUBY_VERSION
128
+ "org.jruby:jruby-complete:jar:#{version}"
129
+ end
130
+
131
+ end
132
+ end
133
+ end
134
+
135
+ Buildr::Shell.providers << Buildr::Shell::BeanShell
136
+ Buildr::Shell.providers << Buildr::Shell::JIRB
137
+
@@ -0,0 +1,843 @@
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/core/project'
18
+ require 'buildr/core/build'
19
+ require 'buildr/core/compile'
20
+
21
+
22
+ module Buildr
23
+
24
+ # The underlying test framework used by TestTask.
25
+ # To add a new test framework, extend TestFramework::Base and add your framework using:
26
+ # Buildr::TestFramework << MyFramework
27
+ module TestFramework
28
+
29
+ class << self
30
+
31
+ # Returns true if the specified test framework exists.
32
+ def has?(name)
33
+ frameworks.any? { |framework| framework.to_sym == name.to_sym }
34
+ end
35
+
36
+ # Select a test framework by its name.
37
+ def select(name)
38
+ frameworks.detect { |framework| framework.to_sym == name.to_sym }
39
+ end
40
+
41
+ # Identify which test framework applies for this project.
42
+ def select_from(project)
43
+ # Look for a suitable test framework based on the compiled language,
44
+ # which may return multiple candidates, e.g. JUnit and TestNG for Java.
45
+ # Pick the one used in the parent project, if not, whichever comes first.
46
+ candidates = frameworks.select { |framework| framework.applies_to?(project) }
47
+ parent = project.parent
48
+ parent && candidates.detect { |framework| framework.to_sym == parent.test.framework } || candidates.first
49
+ end
50
+
51
+ # Adds a test framework to the list of supported frameworks.
52
+ #
53
+ # For example:
54
+ # Buildr::TestFramework << Buildr::JUnit
55
+ def add(framework)
56
+ @frameworks ||= []
57
+ @frameworks |= [framework]
58
+ end
59
+ alias :<< :add
60
+
61
+ # Returns a list of available test frameworks.
62
+ def frameworks
63
+ @frameworks ||= []
64
+ end
65
+
66
+ end
67
+
68
+ # Base class for all test frameworks, with common functionality. Extend and over-ride as you see fit
69
+ # (see JUnit as an example).
70
+ class Base
71
+
72
+ class << self
73
+
74
+ # The framework's identifier (e.g. :junit). Inferred from the class name.
75
+ def to_sym
76
+ @symbol ||= name.split('::').last.downcase.to_sym
77
+ end
78
+
79
+ # Returns true if this framework applies to the current project. For example, JUnit returns
80
+ # true if the tests are written in Java.
81
+ def applies_to?(project)
82
+ raise 'Not implemented'
83
+ end
84
+
85
+ # Returns a list of dependencies for this framework. Default is an empty list,
86
+ # override to add dependencies.
87
+ def dependencies
88
+ @dependencies ||= []
89
+ end
90
+
91
+ end
92
+
93
+ # Construct a new test framework with the specified options. Note that options may
94
+ # change before the framework is run.
95
+ def initialize(test_task, options)
96
+ @options = options
97
+ @task = test_task
98
+ end
99
+
100
+ # Options for this test framework.
101
+ attr_reader :options
102
+ # The test task we belong to
103
+ attr_reader :task
104
+
105
+ # Returns a list of dependenices for this framework. Defaults to calling the #dependencies
106
+ # method on the class.
107
+ def dependencies
108
+ self.class.dependencies
109
+ end
110
+
111
+ # TestTask calls this method to return a list of test names that can be run in this project.
112
+ # It then applies the include/exclude patterns to arrive at the list of tests that will be
113
+ # run, and call the #run method with that list.
114
+ #
115
+ # This method should return a list suitable for using with the #run method, but also suitable
116
+ # for the user to manage. For example, JUnit locates all the tests in the test.compile.target
117
+ # directory, and returns the class names, which are easier to work with than file names.
118
+ def tests(dependencies)
119
+ raise 'Not implemented'
120
+ end
121
+
122
+ # TestTask calls this method to run the named (and only those) tests. This method returns
123
+ # the list of tests that ran successfully.
124
+ def run(tests, dependencies)
125
+ raise 'Not implemented'
126
+ end
127
+
128
+ end
129
+
130
+ end
131
+
132
+
133
+ # The test task controls the entire test lifecycle.
134
+ #
135
+ # You can use the test task in three ways. You can access and configure specific test tasks,
136
+ # e.g. enhance the #compile task, or run code during #setup/#teardown.
137
+ #
138
+ # You can use convenient methods that handle the most common settings. For example,
139
+ # add dependencies using #with, or include only specific tests using #include.
140
+ #
141
+ # You can also enhance this task directly. This task will first execute the #compile task, followed
142
+ # by the #setup task, run the unit tests, any other enhancements, and end by executing #teardown.
143
+ #
144
+ # The test framework is determined based on the available test files, for example, if the test
145
+ # cases are written in Java, then JUnit is selected as the test framework. You can also select
146
+ # a specific test framework, for example, to use TestNG instead of JUnit:
147
+ # test.using :testng
148
+ class TestTask < Rake::Task
149
+
150
+ class << self
151
+
152
+ # Used by the local test and integration tasks to
153
+ # a) Find the local project(s),
154
+ # b) Find all its sub-projects and narrow down to those that have either unit or integration tests,
155
+ # c) Run all the (either unit or integration) tests, and
156
+ # d) Ignore failure if necessary.
157
+ def run_local_tests(integration) #:nodoc:
158
+ Project.local_projects do |project|
159
+ # !(foo ^ bar) tests for equality and accepts nil as false (and select is less obfuscated than reject on ^).
160
+ projects = ([project] + project.projects).select { |project| !(project.test.options[:integration] ^ integration) }
161
+ projects.each do |project|
162
+ info "Testing #{project.name}"
163
+ begin
164
+ project.test.invoke
165
+ rescue
166
+ raise unless Buildr.options.test == :all
167
+ end
168
+ end
169
+ end
170
+ end
171
+
172
+ # Used by the test/integration rule to only run tests that match the specified names.
173
+ def only_run(tests) #:nodoc:
174
+ tests = wildcardify(tests)
175
+ # Since the tests may reside in a sub-project, we need to set the include/exclude pattern on
176
+ # all sub-projects, but only invoke test on the local project.
177
+ Project.projects.each { |project| project.test.send :only_run, tests }
178
+ end
179
+
180
+ # Used by the test/integration rule to only run tests that failed the last time.
181
+ def only_run_failed() #:nodoc:
182
+ # Since the tests may reside in a sub-project, we need to set the include/exclude pattern on
183
+ # all sub-projects, but only invoke test on the local project.
184
+ Project.projects.each { |project| project.test.send :only_run_failed }
185
+ end
186
+
187
+ # Used by the test/integration rule to clear all previously included/excluded tests.
188
+ def clear()
189
+ Project.projects.each do |project|
190
+ project.test.send :clear
191
+ end
192
+ end
193
+
194
+ # Used by the test/integration to include specific tests
195
+ def include(includes)
196
+ includes = wildcardify(Array(includes))
197
+ Project.projects.each do |project|
198
+ project.test.send :include, *includes if includes.size > 0
199
+ project.test.send :forced_need=, true
200
+ end
201
+ end
202
+
203
+ # Used by the test/integration to exclude specific tests
204
+ def exclude(excludes)
205
+ excludes = wildcardify(Array(excludes))
206
+ Project.projects.each do |project|
207
+ project.test.send :exclude, *excludes if excludes.size > 0
208
+ project.test.send :forced_need=, true
209
+ end
210
+ end
211
+
212
+ private
213
+
214
+ def wildcardify(strings)
215
+ strings.map { |name| name =~ /\*/ ? name : "*#{name}*" }
216
+ end
217
+ end
218
+
219
+ # Default options already set on each test task.
220
+ def default_options
221
+ { :fail_on_failure=>true, :fork=>:once, :properties=>{}, :environment=>{} }
222
+ end
223
+
224
+ def initialize(*args) #:nodoc:
225
+ super
226
+ @dependencies = FileList[]
227
+ @include = []
228
+ @exclude = []
229
+ @forced_need = false
230
+ parent_task = Project.parent_task(name)
231
+ if parent_task.respond_to?(:options)
232
+ @options = OpenObject.new { |hash, key| hash[key] = parent_task.options[key].clone rescue hash[key] = parent_task.options[key] }
233
+ else
234
+ @options = OpenObject.new(default_options)
235
+ end
236
+
237
+ unless ENV["IGNORE_BUILDFILE"] =~ /(true)|(yes)/i
238
+ enhance [ application.buildfile.name ]
239
+ enhance application.buildfile.prerequisites
240
+ end
241
+ enhance do
242
+ run_tests if framework
243
+ end
244
+ end
245
+
246
+ # The dependencies used for running the tests. Includes the compiled files (compile.target)
247
+ # and their dependencies. Will also include anything you pass to #with, shared between the
248
+ # testing compile and run dependencies.
249
+ attr_accessor :dependencies
250
+
251
+ # *Deprecated*: Use dependencies instead.
252
+ def classpath
253
+ Buildr.application.deprecated 'Use dependencies instead.'
254
+ @dependencies
255
+ end
256
+
257
+ # *Deprecated*: Use dependencies= instead.
258
+ def classpath=(artifacts)
259
+ Buildr.application.deprecated 'Use dependencies= instead.'
260
+ @dependencies = artifacts
261
+ end
262
+
263
+ def execute(args) #:nodoc:
264
+ if Buildr.options.test == false
265
+ info "Skipping tests for #{project.name}"
266
+ return
267
+ end
268
+ setup.invoke
269
+ begin
270
+ super
271
+ rescue RuntimeError
272
+ raise if options[:fail_on_failure] && Buildr.options.test != :all
273
+ ensure
274
+ teardown.invoke
275
+ end
276
+ end
277
+
278
+ # :call-seq:
279
+ # compile(*sources) => CompileTask
280
+ # compile(*sources) { |task| .. } => CompileTask
281
+ #
282
+ # The compile task is similar to the Project's compile task. However, it compiles all
283
+ # files found in the src/test/{source} directory into the target/test/{code} directory.
284
+ # This task is executed by the test task before running any tests.
285
+ #
286
+ # Once the project definition is complete, all dependencies from the regular
287
+ # compile task are copied over, so you only need to specify dependencies
288
+ # specific to your tests. You can do so by calling #with on the test task.
289
+ # The dependencies used here are also copied over to the junit task.
290
+ def compile(*sources, &block)
291
+ @project.task('test:compile').from(sources).enhance &block
292
+ end
293
+
294
+ # :call-seq:
295
+ # resources(*prereqs) => ResourcesTask
296
+ # resources(*prereqs) { |task| .. } => ResourcesTask
297
+ #
298
+ # Executes by the #compile task to copy resource files over. See Project#resources.
299
+ def resources(*prereqs, &block)
300
+ @project.task('test:resources').enhance prereqs, &block
301
+ end
302
+
303
+ # :call-seq:
304
+ # setup(*prereqs) => task
305
+ # setup(*prereqs) { |task| .. } => task
306
+ #
307
+ # Returns the setup task. The setup task is executed at the beginning of the test task,
308
+ # after compiling the test files.
309
+ def setup(*prereqs, &block)
310
+ @project.task('test:setup').enhance prereqs, &block
311
+ end
312
+
313
+ # :call-seq:
314
+ # teardown(*prereqs) => task
315
+ # teardown(*prereqs) { |task| .. } => task
316
+ #
317
+ # Returns the teardown task. The teardown task is executed at the end of the test task.
318
+ def teardown(*prereqs, &block)
319
+ @project.task('test:teardown').enhance prereqs, &block
320
+ end
321
+
322
+ # :call-seq:
323
+ # with(*specs) => self
324
+ #
325
+ # Specify artifacts (specs, tasks, files, etc) to include in the dependencies list
326
+ # when compiling and running tests.
327
+ def with(*artifacts)
328
+ @dependencies |= Buildr.artifacts(artifacts.flatten).uniq
329
+ compile.with artifacts
330
+ self
331
+ end
332
+
333
+ # Returns various test options.
334
+ attr_reader :options
335
+
336
+ # :call-seq:
337
+ # using(options) => self
338
+ #
339
+ # Sets various test options from a hash and returns self. For example:
340
+ # test.using :fork=>:each, :properties=>{ 'url'=>'http://localhost:8080' }
341
+ #
342
+ # Can also be used to select the test framework, or to run these tests as
343
+ # integration tests. For example:
344
+ # test.using :testng
345
+ # test.using :integration
346
+ #
347
+ # The :fail_on_failure option specifies whether the task should fail if
348
+ # any of the tests fail (default), or should report the failures but continue
349
+ # running the build (when set to false).
350
+ #
351
+ # All other options depend on the capability of the test framework. These options
352
+ # should be used the same way across all frameworks that support them:
353
+ # * :fork -- Fork once for each project (:once, default), for each test in each
354
+ # project (:each), or don't fork at all (false).
355
+ # * :properties -- Properties pass to the test, e.g. in Java as system properties.
356
+ # * :environment -- Environment variables. This hash is made available in the
357
+ # form of environment variables.
358
+ def using(*args)
359
+ args.pop.each { |key, value| options[key.to_sym] = value } if Hash === args.last
360
+ args.each do |name|
361
+ if TestFramework.has?(name)
362
+ self.framework = name
363
+ elsif name == :integration
364
+ options[:integration] = true
365
+ else
366
+ Buildr.application.deprecated "Please replace with using(:#{name}=>true)"
367
+ options[name.to_sym] = true
368
+ end
369
+ end
370
+ self
371
+ end
372
+
373
+ # :call-seq:
374
+ # include(*names) => self
375
+ #
376
+ # Include only the specified tests. Unless specified, the default is to include
377
+ # all tests identified by the test framework. This method accepts multiple arguments
378
+ # and returns self.
379
+ #
380
+ # Tests are specified by their full name, but you can use glob patterns to select
381
+ # multiple tests, for example:
382
+ # test.include 'com.example.FirstTest' # FirstTest only
383
+ # test.include 'com.example.*' # All tests under com/example
384
+ # test.include 'com.example.Module*' # All tests starting with Module
385
+ # test.include '*.{First,Second}Test' # FirstTest, SecondTest
386
+ def include(*names)
387
+ @include += names
388
+ self
389
+ end
390
+
391
+ # :call-seq:
392
+ # exclude(*names) => self
393
+ #
394
+ # Exclude the specified tests. This method accepts multiple arguments and returns self.
395
+ # See #include for the type of arguments you can use.
396
+ def exclude(*names)
397
+ @exclude += names
398
+ self
399
+ end
400
+
401
+ # Clear all test includes and excludes and returns self
402
+ def clear
403
+ @include = []
404
+ @exclude = []
405
+ self
406
+ end
407
+
408
+ # *Deprecated*: Use tests instead.
409
+ def classes
410
+ Buildr.application.deprecated 'Call tests instead of classes'
411
+ tests
412
+ end
413
+
414
+ # After running the task, returns all tests selected to run, based on availability and include/exclude pattern.
415
+ attr_reader :tests
416
+ # After running the task, returns all the tests that failed, empty array if all tests passed.
417
+ attr_reader :failed_tests
418
+ # After running the task, returns all the tests that passed, empty array if no tests passed.
419
+ attr_reader :passed_tests
420
+
421
+ # :call-seq:
422
+ # framework => symbol
423
+ #
424
+ # Returns the test framework, e.g. :junit, :testng.
425
+ def framework
426
+ unless @framework
427
+ # Start with all frameworks that apply (e.g. JUnit and TestNG for Java),
428
+ # and pick the first (default) one, unless already specified in parent project.
429
+ candidates = TestFramework.frameworks.select { |cls| cls.applies_to?(@project) }
430
+ candidate = @project.parent && candidates.detect { |framework| framework.to_sym == @project.parent.test.framework } ||
431
+ candidates.first
432
+ self.framework = candidate if candidate
433
+ end
434
+ @framework && @framework.class.to_sym
435
+ end
436
+
437
+ # :call-seq:
438
+ # report_to => file
439
+ #
440
+ # Test frameworks that can produce reports, will write them to this directory.
441
+ #
442
+ # This is framework dependent, so unless you use the default test framework, call this method
443
+ # after setting the test framework.
444
+ def report_to
445
+ @report_to ||= file(@project.path_to(:reports, framework)=>self)
446
+ end
447
+
448
+ # :call-seq:
449
+ # failures_to => file
450
+ #
451
+ # We record the list of failed tests for the current framework in this file.
452
+ #
453
+ #
454
+ def failures_to
455
+ @failures_to ||= file(@project.path_to(:target, "#{framework}-failed")=>self)
456
+ end
457
+
458
+ # :call-seq:
459
+ # last_failures => array
460
+ #
461
+ # We read the last test failures if any and return them.
462
+ #
463
+ def last_failures
464
+ @last_failures ||= failures_to.exist? ? File.read(failures_to.to_s).split("\n") : []
465
+ end
466
+
467
+ # The path to the file that stores the time stamp of the last successful test run.
468
+ def last_successful_run_file #:nodoc:
469
+ File.join(report_to.to_s, 'last_successful_run')
470
+ end
471
+
472
+ # The time stamp of the last successful test run. Or Rake::EARLY if no successful test run recorded.
473
+ def timestamp #:nodoc:
474
+ File.exist?(last_successful_run_file) ? File.mtime(last_successful_run_file) : Rake::EARLY
475
+ end
476
+
477
+ # The project this task belongs to.
478
+ attr_reader :project
479
+
480
+ # Whether the tests are forced
481
+ attr_accessor :forced_need
482
+
483
+ protected
484
+
485
+ def associate_with(project)
486
+ @project = project
487
+ end
488
+
489
+ def framework=(name)
490
+ cls = TestFramework.select(name) or raise ArgumentError, "No #{name} test framework available. Did you install it?"
491
+ #cls.inherit_options.reject { |name| options.has_key?(name) }.
492
+ # each { |name| options[name] = @parent_task.options[name] } if @parent_task.respond_to?(:options)
493
+ @framework = cls.new(self, options)
494
+ # Test framework dependency.
495
+ with @framework.dependencies
496
+ end
497
+
498
+ # :call-seq:
499
+ # include?(name) => boolean
500
+ #
501
+ # Returns true if the specified test name matches the inclusion/exclusion pattern. Used to determine
502
+ # which tests to execute.
503
+ def include?(name)
504
+ ((@include.empty? && !@forced_need)|| @include.any? { |pattern| File.fnmatch(pattern, name) }) &&
505
+ !@exclude.any? { |pattern| File.fnmatch(pattern, name) }
506
+ end
507
+
508
+ # Runs the tests using the selected test framework.
509
+ def run_tests
510
+ dependencies = (Buildr.artifacts(self.dependencies + compile.dependencies) + [compile.target]).map(&:to_s).uniq
511
+ rm_rf report_to.to_s
512
+ rm_rf failures_to.to_s
513
+ @tests = @framework.tests(dependencies).select { |test| include?(test) }.sort
514
+ if @tests.empty?
515
+ @passed_tests, @failed_tests = [], []
516
+ else
517
+ info "Running tests in #{@project.name}"
518
+ begin
519
+ # set the baseDir system property if not set
520
+ @framework.options[:properties] = { 'baseDir' => compile.target.to_s }.merge(@framework.options[:properties] || {})
521
+ @passed_tests = @framework.run(@tests, dependencies)
522
+ rescue Exception=>ex
523
+ error "Test framework error: #{ex.message}"
524
+ error ex.backtrace.join("\n") if trace?
525
+ @passed_tests = []
526
+ end
527
+ @failed_tests = @tests - @passed_tests
528
+ unless @failed_tests.empty?
529
+ Buildr::write(failures_to.to_s, @failed_tests.join("\n"))
530
+ error "The following tests failed:\n#{@failed_tests.join("\n")}"
531
+ fail 'Tests failed!'
532
+ end
533
+ end
534
+ record_successful_run unless @forced_need
535
+ end
536
+
537
+ # Call this method when a test run is successful to record the current system time.
538
+ def record_successful_run #:nodoc:
539
+ mkdir_p report_to.to_s
540
+ touch last_successful_run_file
541
+ end
542
+
543
+ # Limit running tests to specific list.
544
+ def only_run(tests)
545
+ @include = Array(tests)
546
+ @exclude.clear
547
+ @forced_need = true
548
+ end
549
+
550
+ # Limit running tests to those who failed the last time.
551
+ def only_run_failed()
552
+ @include = Array(last_failures)
553
+ @forced_need = true
554
+ end
555
+
556
+ def invoke_prerequisites(args, chain) #:nodoc:
557
+ @prerequisites |= FileList[@dependencies.uniq]
558
+ super
559
+ end
560
+
561
+ def needed? #:nodoc:
562
+ latest_prerequisite = @prerequisites.map { |p| application[p, @scope] }.max { |a,b| a.timestamp<=>b.timestamp }
563
+ needed = (timestamp == Rake::EARLY) || latest_prerequisite.timestamp > timestamp
564
+ trace "Testing#{needed ? ' ' : ' not '}needed. " +
565
+ "Latest prerequisite change: #{latest_prerequisite.timestamp} (#{latest_prerequisite.to_s}). " +
566
+ "Last successful test run: #{timestamp}."
567
+ return needed || @forced_need || Buildr.options.test == :all
568
+ end
569
+ end
570
+
571
+
572
+ # The integration tests task. Buildr has one such task (see Buildr#integration) that runs
573
+ # all tests marked with :integration=>true, and has a setup/teardown tasks separate from
574
+ # the unit tests.
575
+ class IntegrationTestsTask < Rake::Task
576
+
577
+ def initialize(*args) #:nodoc:
578
+ super
579
+ @setup = task("#{name}:setup")
580
+ @teardown = task("#{name}:teardown")
581
+ enhance do
582
+ info 'Running integration tests...'
583
+ TestTask.run_local_tests true
584
+ end
585
+ end
586
+
587
+ def execute(args) #:nodoc:
588
+ setup.invoke
589
+ begin
590
+ super
591
+ ensure
592
+ teardown.invoke
593
+ end
594
+ end
595
+
596
+ # :call-seq:
597
+ # setup(*prereqs) => task
598
+ # setup(*prereqs) { |task| .. } => task
599
+ #
600
+ # Returns the setup task. The setup task is executed before running the integration tests.
601
+ def setup(*prereqs, &block)
602
+ @setup.enhance prereqs, &block
603
+ end
604
+
605
+ # :call-seq:
606
+ # teardown(*prereqs) => task
607
+ # teardown(*prereqs) { |task| .. } => task
608
+ #
609
+ # Returns the teardown task. The teardown task is executed after running the integration tests.
610
+ def teardown(*prereqs, &block)
611
+ @teardown.enhance prereqs, &block
612
+ end
613
+
614
+ end
615
+
616
+
617
+ # Methods added to Project to support compilation and running of tests.
618
+ module Test
619
+
620
+ include Extension
621
+
622
+ first_time do
623
+ desc 'Run all tests'
624
+ task('test') { TestTask.run_local_tests false }
625
+
626
+ desc 'Run failed tests'
627
+ task('test:failed') {
628
+ TestTask.only_run_failed
629
+ task('test').invoke
630
+ }
631
+
632
+ # This rule takes a suffix and runs that tests in the current project. For example;
633
+ # buildr test:MyTest
634
+ # will run the test com.example.MyTest, if such a test exists for this project.
635
+ #
636
+ # If you want to run multiple test, separate them with a comma. You can also use glob
637
+ # (* and ?) patterns to match multiple tests, see the TestTask#include method.
638
+ rule /^test:.*$/ do |task|
639
+ # The map works around a JRuby bug whereby the string looks fine, but fails in fnmatch.
640
+ tests = task.name.scan(/test:(.*)/)[0][0].split(',').map(&:to_s)
641
+ excludes, includes = tests.partition { |t| t =~ /^-/ }
642
+ if excludes.empty?
643
+ TestTask.only_run includes
644
+ else
645
+ # remove leading '-'
646
+ excludes.map! { |t| t[1..-1] }
647
+
648
+ TestTask.clear
649
+ TestTask.include(includes.empty? ? ['*'] : includes)
650
+ TestTask.exclude excludes
651
+ end
652
+ task('test').invoke
653
+ end
654
+
655
+ IntegrationTestsTask.define_task('integration')
656
+
657
+ # Similar to test:[pattern] but for integration tests.
658
+ rule /^integration:.*$/ do |task|
659
+ unless task.name.split(':')[1] =~ /^(setup|teardown)$/
660
+ # The map works around a JRuby bug whereby the string looks fine, but fails in fnmatch.
661
+ TestTask.only_run task.name[/integration:(.*)/, 1].split(',').map { |t| "#{t}" }
662
+ task('integration').invoke
663
+ end
664
+ end
665
+
666
+ end
667
+
668
+ before_define(:test) do |project|
669
+ # Define a recursive test task, and pass it a reference to the project so it can discover all other tasks.
670
+ test = TestTask.define_task('test')
671
+ test.send :associate_with, project
672
+
673
+ # Similar to the regular resources task but using different paths.
674
+ resources = ResourcesTask.define_task('test:resources')
675
+ resources.send :associate_with, project, :test
676
+ project.path_to(:source, :test, :resources).tap { |dir| resources.from dir if File.exist?(dir) }
677
+
678
+ # We define a module inline that will inject cancelling the task if tests are skipped.
679
+ module SkipIfNoTest
680
+
681
+ def self.extended(base)
682
+ base.instance_eval {alias :execute_before_skip_if_no_test :execute}
683
+ base.instance_eval {alias :execute :execute_after_skip_if_no_test}
684
+ end
685
+
686
+ def execute_after_skip_if_no_test(args) #:nodoc:
687
+ if Buildr.options.test == false
688
+ trace "Skipping #{to_s} for #{project.name} as tests are skipped"
689
+ return
690
+ end
691
+ execute_before_skip_if_no_test(args)
692
+ end
693
+ end
694
+
695
+ # Similar to the regular compile task but using different paths.
696
+ compile = CompileTask.define_task('test:compile'=>[project.compile, resources])
697
+ compile.extend SkipIfNoTest
698
+ compile.send :associate_with, project, :test
699
+ test.enhance [compile]
700
+
701
+ # Define these tasks once, otherwise we may get a namespace error.
702
+ test.setup ; test.teardown
703
+ end
704
+
705
+
706
+
707
+ after_define(:test => :compile) do |project|
708
+ test = project.test
709
+ # Dependency on compiled tests and resources. Dependencies added using with.
710
+ test.dependencies.concat [test.compile.target, test.resources.target].compact
711
+ test.dependencies.concat test.compile.dependencies
712
+ # Dependency on compiled code, its dependencies and resources.
713
+ test.with [project.compile.target, project.resources.target].compact
714
+ test.with project.compile.dependencies
715
+ # Picking up the test frameworks adds further dependencies.
716
+ test.framework
717
+
718
+ project.build test unless test.options[:integration] || Buildr.options.test == :only
719
+
720
+ project.clean do
721
+ rm_rf test.compile.target.to_s if test.compile.target
722
+ rm_rf test.report_to.to_s
723
+ end
724
+ end
725
+
726
+
727
+ # :call-seq:
728
+ # test(*prereqs) => TestTask
729
+ # test(*prereqs) { |task| .. } => TestTask
730
+ #
731
+ # Returns the test task. The test task controls the entire test lifecycle.
732
+ #
733
+ # You can use the test task in three ways. You can access and configure specific
734
+ # test tasks, e.g. enhance the compile task by calling test.compile, setup for
735
+ # the tests by enhancing test.setup and so forth.
736
+ #
737
+ # You can use convenient methods that handle the most common settings. For example,
738
+ # add dependencies using test.with, or include only specific tests using test.include.
739
+ #
740
+ # You can also enhance this task directly. This method accepts a list of arguments
741
+ # that are used as prerequisites and an optional block that will be executed by the
742
+ # test task.
743
+ #
744
+ # This task compiles the project and the tests (in that order) before running any tests.
745
+ # It execute the setup task, runs all the tests, any enhancements, and ends with the
746
+ # teardown tasks.
747
+ def test(*prereqs, &block)
748
+ task('test').enhance prereqs, &block
749
+ end
750
+
751
+ # :call-seq:
752
+ # integration { |task| .... }
753
+ # integration => IntegrationTestTask
754
+ #
755
+ # Use this method to return the integration tests task, or enhance it with a block to execute.
756
+ #
757
+ # There is one integration tests task you can execute directly, or as a result of running the package
758
+ # task (or tasks that depend on it, like install and upload). It contains all the tests marked with
759
+ # :integration=>true, all other tests are considered unit tests and run by the test task before packaging.
760
+ # So essentially: build=>test=>packaging=>integration=>install/upload.
761
+ #
762
+ # You add new tests from projects that define integration tests using the regular test task,
763
+ # but with the following addition:
764
+ # test.using :integration
765
+ #
766
+ # Use this method to enhance the setup and teardown tasks that are executed before (and after) all
767
+ # integration tests are run, for example, to start a Web server or create a database.
768
+ def integration(*deps, &block)
769
+ Rake::Task['rake:integration'].enhance deps, &block
770
+ end
771
+
772
+ end
773
+
774
+
775
+ # :call-seq:
776
+ # integration { |task| .... }
777
+ # integration => IntegrationTestTask
778
+ #
779
+ # Use this method to return the integration tests task.
780
+ def integration(*deps, &block)
781
+ Rake::Task['rake:integration'].enhance deps, &block
782
+ end
783
+
784
+ class Options
785
+
786
+ # Runs tests after the build when true (default). This forces tests to execute
787
+ # after the build, including when running build related tasks like install, upload and release.
788
+ #
789
+ # Set to false to not run any tests. Set to :all to run all tests, ignoring failures.
790
+ #
791
+ # This option is set from the environment variable 'test', so you can also do:
792
+
793
+ # Returns the test option (environment variable TEST). Possible values are:
794
+ # * :false -- Do not run any tests (also accepts 'no' and 'skip').
795
+ # * :true -- Run all tests, stop on failure (default if not set).
796
+ # * :all -- Run all tests, ignore failures.
797
+ def test
798
+ case value = ENV['TEST'] || ENV['test']
799
+ when /^(no|off|false|skip)$/i
800
+ false
801
+ when /^all$/i
802
+ :all
803
+ when /^only$/i
804
+ :only
805
+ when /^(yes|on|true)$/i, nil
806
+ true
807
+ else
808
+ 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 tests and stop at failure."
809
+ true
810
+ end
811
+ end
812
+
813
+ # Sets the test option (environment variable TEST). Possible values are true, false or :all.
814
+ #
815
+ # You can also set this from the environment variable, e.g.:
816
+ #
817
+ # buildr # With tests
818
+ # buildr test=no # Without tests
819
+ # buildr test=all # Ignore failures
820
+ # set TEST=no
821
+ # buildr # Without tests
822
+ def test=(flag)
823
+ ENV['test'] = nil
824
+ ENV['TEST'] = flag.to_s
825
+ end
826
+
827
+ end
828
+
829
+ Buildr.help << <<-HELP
830
+ To run a full build without running any tests:
831
+ buildr test=no
832
+ To run specific test:
833
+ buildr test:MyTest
834
+ To run integration tests:
835
+ buildr integration
836
+ HELP
837
+
838
+ end
839
+
840
+
841
+ class Buildr::Project
842
+ include Buildr::Test
843
+ end