buildr 1.3.5-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGELOG +998 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +45 -0
  6. data/_buildr +29 -0
  7. data/_jbuildr +29 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +22 -0
  10. data/addon/buildr/drb.rb +281 -0
  11. data/addon/buildr/emma.rb +22 -0
  12. data/addon/buildr/hibernate.rb +142 -0
  13. data/addon/buildr/javacc.rb +85 -0
  14. data/addon/buildr/jdepend.rb +60 -0
  15. data/addon/buildr/jetty.rb +248 -0
  16. data/addon/buildr/jibx.rb +86 -0
  17. data/addon/buildr/nailgun.rb +221 -0
  18. data/addon/buildr/openjpa.rb +90 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  26. data/addon/buildr/xmlbeans.rb +93 -0
  27. data/bin/buildr +19 -0
  28. data/buildr.buildfile +58 -0
  29. data/buildr.gemspec +65 -0
  30. data/doc/_config.yml +1 -0
  31. data/doc/_layouts/default.html +88 -0
  32. data/doc/_layouts/preface.html +22 -0
  33. data/doc/artifacts.textile +211 -0
  34. data/doc/building.textile +244 -0
  35. data/doc/contributing.textile +252 -0
  36. data/doc/css/default.css +236 -0
  37. data/doc/css/print.css +101 -0
  38. data/doc/css/syntax.css +23 -0
  39. data/doc/download.textile +79 -0
  40. data/doc/extending.textile +186 -0
  41. data/doc/images/1442160941-frontcover.jpg +0 -0
  42. data/doc/images/asf-logo.gif +0 -0
  43. data/doc/images/asf-logo.png +0 -0
  44. data/doc/images/buildr-hires.png +0 -0
  45. data/doc/images/buildr.png +0 -0
  46. data/doc/images/favicon.png +0 -0
  47. data/doc/images/growl-icon.tiff +0 -0
  48. data/doc/images/note.png +0 -0
  49. data/doc/images/project-structure.png +0 -0
  50. data/doc/images/tip.png +0 -0
  51. data/doc/images/zbuildr.png +0 -0
  52. data/doc/images/zbuildr.tif +0 -0
  53. data/doc/index.textile +69 -0
  54. data/doc/installing.textile +266 -0
  55. data/doc/languages.textile +459 -0
  56. data/doc/mailing_lists.textile +25 -0
  57. data/doc/more_stuff.textile +457 -0
  58. data/doc/packaging.textile +430 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +271 -0
  61. data/doc/quick_start.textile +210 -0
  62. data/doc/scripts/buildr-git.rb +512 -0
  63. data/doc/scripts/gitflow.rb +296 -0
  64. data/doc/scripts/install-jruby.sh +44 -0
  65. data/doc/scripts/install-linux.sh +72 -0
  66. data/doc/scripts/install-osx.sh +52 -0
  67. data/doc/settings_profiles.textile +280 -0
  68. data/doc/testing.textile +222 -0
  69. data/etc/KEYS +151 -0
  70. data/lib/buildr.rb +36 -0
  71. data/lib/buildr/core.rb +35 -0
  72. data/lib/buildr/core/application.rb +656 -0
  73. data/lib/buildr/core/build.rb +452 -0
  74. data/lib/buildr/core/checks.rb +254 -0
  75. data/lib/buildr/core/common.rb +150 -0
  76. data/lib/buildr/core/compile.rb +608 -0
  77. data/lib/buildr/core/environment.rb +129 -0
  78. data/lib/buildr/core/filter.rb +362 -0
  79. data/lib/buildr/core/generate.rb +195 -0
  80. data/lib/buildr/core/help.rb +119 -0
  81. data/lib/buildr/core/osx.rb +46 -0
  82. data/lib/buildr/core/progressbar.rb +156 -0
  83. data/lib/buildr/core/project.rb +866 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +723 -0
  86. data/lib/buildr/core/transports.rb +559 -0
  87. data/lib/buildr/core/util.rb +449 -0
  88. data/lib/buildr/groovy.rb +19 -0
  89. data/lib/buildr/groovy/bdd.rb +106 -0
  90. data/lib/buildr/groovy/compiler.rb +138 -0
  91. data/lib/buildr/groovy/shell.rb +48 -0
  92. data/lib/buildr/ide.rb +19 -0
  93. data/lib/buildr/ide/eclipse.rb +334 -0
  94. data/lib/buildr/ide/eclipse/java.rb +53 -0
  95. data/lib/buildr/ide/eclipse/plugin.rb +68 -0
  96. data/lib/buildr/ide/eclipse/scala.rb +66 -0
  97. data/lib/buildr/ide/idea.ipr.template +300 -0
  98. data/lib/buildr/ide/idea.rb +190 -0
  99. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  100. data/lib/buildr/ide/idea7x.rb +212 -0
  101. data/lib/buildr/java.rb +23 -0
  102. data/lib/buildr/java/ant.rb +94 -0
  103. data/lib/buildr/java/bdd.rb +459 -0
  104. data/lib/buildr/java/cobertura.rb +274 -0
  105. data/lib/buildr/java/commands.rb +213 -0
  106. data/lib/buildr/java/compiler.rb +349 -0
  107. data/lib/buildr/java/deprecated.rb +141 -0
  108. data/lib/buildr/java/emma.rb +244 -0
  109. data/lib/buildr/java/jruby.rb +117 -0
  110. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  111. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +137 -0
  113. data/lib/buildr/java/packaging.rb +716 -0
  114. data/lib/buildr/java/pom.rb +174 -0
  115. data/lib/buildr/java/rjb.rb +155 -0
  116. data/lib/buildr/java/test_result.rb +353 -0
  117. data/lib/buildr/java/tests.rb +333 -0
  118. data/lib/buildr/java/version_requirement.rb +172 -0
  119. data/lib/buildr/packaging.rb +24 -0
  120. data/lib/buildr/packaging/archive.rb +488 -0
  121. data/lib/buildr/packaging/artifact.rb +749 -0
  122. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  123. data/lib/buildr/packaging/artifact_search.rb +140 -0
  124. data/lib/buildr/packaging/gems.rb +102 -0
  125. data/lib/buildr/packaging/package.rb +238 -0
  126. data/lib/buildr/packaging/tar.rb +186 -0
  127. data/lib/buildr/packaging/version_requirement.rb +172 -0
  128. data/lib/buildr/packaging/zip.rb +73 -0
  129. data/lib/buildr/packaging/ziptask.rb +316 -0
  130. data/lib/buildr/resources/buildr.icns +0 -0
  131. data/lib/buildr/scala.rb +25 -0
  132. data/lib/buildr/scala/bdd.rb +109 -0
  133. data/lib/buildr/scala/compiler.rb +195 -0
  134. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  137. data/lib/buildr/scala/shell.rb +55 -0
  138. data/lib/buildr/scala/tests.rb +157 -0
  139. data/lib/buildr/shell.rb +180 -0
  140. data/rakelib/checks.rake +57 -0
  141. data/rakelib/doc.rake +92 -0
  142. data/rakelib/jekylltask.rb +120 -0
  143. data/rakelib/package.rake +73 -0
  144. data/rakelib/release.rake +149 -0
  145. data/rakelib/rspec.rake +73 -0
  146. data/rakelib/setup.rake +54 -0
  147. data/rakelib/stage.rake +213 -0
  148. data/rakelib/stage.rake~ +213 -0
  149. data/spec/addon/drb_spec.rb +328 -0
  150. data/spec/core/application_spec.rb +502 -0
  151. data/spec/core/build_spec.rb +677 -0
  152. data/spec/core/checks_spec.rb +519 -0
  153. data/spec/core/common_spec.rb +670 -0
  154. data/spec/core/compile_spec.rb +583 -0
  155. data/spec/core/extension_spec.rb +93 -0
  156. data/spec/core/generate_spec.rb +33 -0
  157. data/spec/core/project_spec.rb +762 -0
  158. data/spec/core/test_spec.rb +1098 -0
  159. data/spec/core/transport_spec.rb +537 -0
  160. data/spec/core/util_spec.rb +67 -0
  161. data/spec/groovy/bdd_spec.rb +80 -0
  162. data/spec/groovy/compiler_spec.rb +240 -0
  163. data/spec/ide/eclipse_spec.rb +501 -0
  164. data/spec/ide/idea7x_spec.rb +84 -0
  165. data/spec/java/ant_spec.rb +33 -0
  166. data/spec/java/bdd_spec.rb +382 -0
  167. data/spec/java/cobertura_spec.rb +85 -0
  168. data/spec/java/compiler_spec.rb +446 -0
  169. data/spec/java/emma_spec.rb +119 -0
  170. data/spec/java/java_spec.rb +124 -0
  171. data/spec/java/packaging_spec.rb +1134 -0
  172. data/spec/java/test_coverage_helper.rb +257 -0
  173. data/spec/java/tests_spec.rb +493 -0
  174. data/spec/packaging/archive_spec.rb +527 -0
  175. data/spec/packaging/artifact_namespace_spec.rb +654 -0
  176. data/spec/packaging/artifact_spec.rb +795 -0
  177. data/spec/packaging/packaging_helper.rb +63 -0
  178. data/spec/packaging/packaging_spec.rb +684 -0
  179. data/spec/sandbox.rb +142 -0
  180. data/spec/scala/bdd_spec.rb +119 -0
  181. data/spec/scala/compiler_spec.rb +284 -0
  182. data/spec/scala/scala.rb +38 -0
  183. data/spec/scala/tests_spec.rb +261 -0
  184. data/spec/spec_helpers.rb +340 -0
  185. data/spec/version_requirement_spec.rb +129 -0
  186. metadata +383 -0
@@ -0,0 +1,280 @@
1
+ ---
2
+ layout: default
3
+ title: Settings/Profiles
4
+ ---
5
+
6
+
7
+ h2(#env_vars). Environment Variables
8
+
9
+ Buildr uses several environment variables that help you control how it works. Some environment variables you will only set once or change infrequently. You can set these in your profile, OS settings or any tool you use to launch Buildr (e.g. continuous integration).
10
+
11
+ For example:
12
+
13
+ {% highlight sh %}
14
+ $ export HTTP_PROXY=http://myproxy:8080
15
+ {% endhighlight %}
16
+
17
+ There are other environment variables you will want to set when running Buildr, for example, to do a full build without running the tests:
18
+
19
+ {% highlight sh %}
20
+ $ buildr test=no
21
+ {% endhighlight %}
22
+
23
+ For convenience, the environment variables @TEST@ and @DEBUG@ are case insensitive, you can use either @test=no@ or @TEST=no@. Any other environment variable names are case sensitive.
24
+
25
+ You can also set environment variables from within your Buildfile. For example, if you discover that building your project requires gobs of JVM heap space, and you want all other team members to run with the same settings:
26
+
27
+ {% highlight ruby %}
28
+ # This project builds a lot of code.
29
+ ENV['JAVA_OPTS'] ||= '-Xms1g -Xmx1g'
30
+ {% endhighlight %}
31
+
32
+ Make sure to set any environment variables at the very top of the Buildfile, above any Ruby statement (even @require@).
33
+
34
+ p(tip). Using @||=@ sets the environment variable, if not already set, so it's still possible for other developers to override this environment variable without modifying the Buildfile.
35
+
36
+ Buildr supports the following environment variables:
37
+
38
+ |_. Variable |_. Description |
39
+ | @BUILDR_ENV@ | Environment name (development, production, test, etc). Another way to set this is using the @-e@ command line option. |
40
+ | @DEBUG@ | Set to @no/off@ if you want Buildr to compile without debugging information (default when running the @release@ task, see "Compiling":building.html#compiling). |
41
+ | @HOME@ | Your home directory. |
42
+ | @HTTP_PROXY@ | URL for HTTP proxy server (see "Specifying Repositories":artifacts.html#repositories). |
43
+ | @HTTPS_PROXY@ | URL for HTTPS proxy server (see "Specifying Repositories":artifacts.html#repositories). |
44
+ | @JAVA_HOME@ | Points to your JDK, required when using Java and Ant. |
45
+ | @JAVA_OPTS@ | Command line options to pass to the JDK (e.g. @'-Xms1g'@). |
46
+ | @M2_REPO@ | Location of the Maven2 local repository. Defaults to the @.m2@ directory in your home directory (@ENV['HOME']@). |
47
+ | @NO_PROXY@ | Comma separated list of hosts and domain that should not be proxied (see "Specifying Repositories":artifacts.html#repositories). |
48
+ | @TEST@ | Set to @no/off@ to tell Buildr to skip tests, or @all@ to tell Buildr to run all tests and ignore failures (see "Running Tests":testing.html#running). |
49
+ | @USER@ | Tasks that need your user name, for example to log to remote servers, will use this environment variable. |
50
+
51
+ p(note). Buildr does not check any of the arguments in @JAVA_OPTS@. A common mistake is to pass an option like @mx512mb@, where it should be @Xmx512mb@. Make sure to double check @JAVA_OPTS@.
52
+
53
+ Some extensions may use additional environment variables, and of course, you can always add your own. This example uses two environment variables for specifying the username and password:
54
+
55
+ {% highlight ruby %}
56
+ repositories.upload_to[:username] = ENV['USERNAME']
57
+ repositories.upload_to[:password] = ENV['PASSWORD']
58
+ {% endhighlight %}
59
+
60
+
61
+ h2(#personal). Personal Settings
62
+
63
+ Some things clearly do not belong in the Buildfile. For example, the username and password you use to upload releases. If you're working in a team or on an open source project, you'd want to keep these in a separate place.
64
+
65
+ You may want to use personal settings for picking up a different location for the local repository, or use a different set of preferred remote repositories, and so forth.
66
+
67
+ The prefered way to store personal settings is to create a @.buildr/settings.yaml@ file under your home directory. Settings stored there will be applied the same across all builds.
68
+
69
+ Here's an example @settings.yaml@:
70
+
71
+ {% highlight yaml %}
72
+ # The repositories hash is read automatically by buildr.
73
+ repositories:
74
+
75
+ # customize user local maven2 repository location
76
+ local: some/path/to/my_repo
77
+
78
+ # prefer the local or nearest mirrors
79
+ remote:
80
+ - https://intra.net/maven2
81
+ - http://example.com
82
+
83
+ relase_to:
84
+ url: http://intra.net/maven2
85
+ username: john
86
+ password: secret
87
+
88
+ # You can place settings of your own, and reference them
89
+ # on buildfiles.
90
+ im:
91
+ server: jabber.company.com
92
+ usr: notifier@company-jabber.com
93
+ pwd: secret
94
+ {% endhighlight %}
95
+
96
+ Later your buildfile or addons can reference user preferences using the hash returned by the @Buildr.settings.user@ accessor.
97
+
98
+ {% highlight ruby %}
99
+ task 'relase-notification' do
100
+ usr, pwd, server = settings.user['im'].values_at('usr', 'pwd', 'server')
101
+ jabber = JabberAPI.new(server, usr, pwd)
102
+ jabber.msg("We are pleased to announce the last stable version #{VERSION}")
103
+ end
104
+ {% endhighlight %}
105
+
106
+
107
+ h2(#build). Build Settings
108
+
109
+ Build settings are local to the project being built, and are placed in the @build.yaml@ file located in the same directory that the @buildfile@. Normally this file would be managed by the project revision control system, so settings here are shared between developers.
110
+
111
+ They help keep the buildfile and build.yaml file simple and readable, working to the advantages of each one. Example for build settings are gems, repositories and artifacts used by that build.
112
+
113
+ {% highlight yaml %}
114
+ # This project requires the following ruby gems, buildr addons
115
+ gems:
116
+ # Suppose we want to notify developers when testcases fail.
117
+ - buildr-twitter-notifier-addon >=1
118
+ # we test with ruby mock objects
119
+ - mocha
120
+ - ci_reporter
121
+
122
+ # The artifact declarations will be automatically loaded by buildr, so that
123
+ # you can reference artifacts by name (a ruby-symbol) on your buildfile.
124
+ artifacts:
125
+ spring: org.springframework:spring:jar:2.0
126
+ log4j: log4j:log4j:jar:1.0
127
+ j2ee: geronimo-spec:geronimo-spec-j2ee:jar:1.4-rc4
128
+
129
+ # Of course project settings can be defined here
130
+ twitter:
131
+ notify:
132
+ test_failure: unless-modified
133
+ compile_failure: never
134
+ developers:
135
+ - joe
136
+ - jane
137
+
138
+ jira:
139
+ uri: https://jira.corp.org
140
+ {% endhighlight %}
141
+
142
+ When buildr is loaded, required ruby gems will be installed if needed, thus adding features like the imaginary twitter notifier addon.
143
+
144
+ Artifacts defined on @build.yaml@ can be referenced on your buildfile by supplying the ruby symbol to the @Buildr.artifact@ and @Buildr.artifacts@ methods. The @compile.with@, @test.with@ methods can also be given these names.
145
+
146
+ {% highlight ruby %}
147
+ define 'my_project' do
148
+ compile.with artifacts(:log4j, :j2ee)
149
+ test.with :spring, :j2ee
150
+ end
151
+ {% endhighlight %}
152
+
153
+ Build settings can be retreived using the @Buildr.settings.build@ accessor.
154
+
155
+ {% highlight ruby %}
156
+ task 'create_patch' do
157
+ patch = Git.create_patch :interactive => true
158
+ if patch && agree("Would you like to request inclusion of #{patch}")
159
+ jira = Jira.new( Buildr.settings.build['jira']['uri'] ) # submit a patch
160
+ jira.create(:improvement, patch.summary, :attachment => patch.blob)
161
+ end
162
+ end
163
+ {% endhighlight %}
164
+
165
+
166
+ h2(#variable). Non constant settings
167
+
168
+ Before loading the Buildfile, Buildr will attempt to load two other files: the @buildr.rb@ file it finds in your home directory, followed by the @buildr.rb@ file it finds in the build directory.
169
+
170
+ The loading order allows you to place global settings that affect all your builds in your home directory's @buildr.rb@, but also over-ride those with settings for a given project.
171
+
172
+ Here's an example @buildr.rb@:
173
+
174
+ {% highlight ruby %}
175
+ # Only I should know that
176
+ repositories.upload_to[:username] = 'assaf'
177
+ repositories.upload_to[:password] = 'supersecret'
178
+ # Search here first, it's faster
179
+ repositories.remote << 'http://inside-the-firewall'
180
+ {% endhighlight %}
181
+
182
+
183
+ h2(#environments). Environments
184
+
185
+ One common use case is adapting the build to different environments. For example, to compile code with debugging information during development and testing, but strip it for production. Another example is using different databases for development, testing and production, or running services at different URLs.
186
+
187
+ So let's start by talking about the build environment. Buildr has a global attributes that indicates which environment it's running in, accessible from the @environment@ method. You can set the current build environment in one of two ways. Using the @-e/--environment@ command line option:
188
+
189
+ {% highlight sh %}
190
+ $ buildr -e test
191
+ (in /home/john/project, test)
192
+ {% endhighlight %}
193
+
194
+ Or by setting the environment variable @BUILDR_ENV@:
195
+
196
+ {% highlight text %}
197
+ $ export BUILDR_ENV=production
198
+ $ buildr
199
+ (in /home/john/project, production)
200
+ {% endhighlight %}
201
+
202
+ Unless you tell it otherwise, Buildr assumes you're developing and sets the environment to @development@.
203
+
204
+ Here's a simple example for handling different environments within the Buildfile:
205
+
206
+ {% highlight ruby %}
207
+ project 'db-module' do
208
+ db = (environment == 'production' ? 'oracle' : 'hsql')
209
+ resources.from(_("src/main/#{db}"))
210
+ end
211
+ {% endhighlight %}
212
+
213
+ We recommend picking a convention for your different environments and following it across all your projects. For example:
214
+
215
+ |_. Environment |_. Use when ... |
216
+ | development | Developing on your machine. |
217
+ | test | Running in test environment, continuous integration. |
218
+ | production | Building for release/production. |
219
+
220
+
221
+ h2(#profiles). Profiles
222
+
223
+ Different environments may require different configurations, some you will want to control with code, others you will want to specify in the profiles file.
224
+
225
+ The profiles file is a YAML file called @profiles.yaml@ that you place in the same directory as the Buildfile. We selected YAML because it's easier to read and edit than XML.
226
+
227
+ For example, to support three different database configurations, we could write:
228
+
229
+ {% highlight yaml %}
230
+ # HSQL, don't bother storing to disk.
231
+ development:
232
+ db: hsql
233
+ jdbc: hsqldb:mem:devdb
234
+
235
+ # Make sure we're not messing with bigstrong.
236
+ test:
237
+ db: oracle
238
+ jdbc: oracle:thin:@localhost:1521:test
239
+
240
+ # The real deal.
241
+ production:
242
+ db: oracle
243
+ jdbc: oracle:thin:@bigstrong:1521:mighty
244
+ {% endhighlight %}
245
+
246
+ Here's a simple example for a buildfile that uses the profile information:
247
+
248
+ {% highlight ruby %}
249
+ project 'db-module' do
250
+ # Copy SQL files specific for the database we're using,
251
+ # for example, everything under src/main/hsql.
252
+ resources.from(_("src/main/#{Buildr.settings.profile['db']}"))
253
+ # Set the JDBC URL in copied resource files (config.xml needs this).
254
+ resources.filter.using :jdbc=>Buildr.settings.profile['jdbc']
255
+ end
256
+ {% endhighlight %}
257
+
258
+ The @profile@ method returns the current profile, selected based on the current "environment":#environments. You can get a list of all profiles by calling @profiles@.
259
+
260
+ When you run the above example in @development@, the current profile will return the hash @{ 'db'=>'hsql', 'jdbc'=>'hsqldb:mem:devdb' }@.
261
+
262
+ We recommend following conventions and using the same environments in all your projects, but sometimes the profiles end up being the same, so here's a trick you can use to keep your profiles DRY.
263
+
264
+ YAML allows you to use anchors (@&@), similar to ID attributes in XML, reference the anchored element (@*@) elsewhere, and merge one element into another (@<<@). For example:
265
+
266
+ {% highlight yaml %}
267
+ # We'll reference this one as common.
268
+ development: &common
269
+ db: hsql
270
+ jdbc: hsqldb:mem:devdb
271
+ resources:
272
+ copyright: Me (C) 2008
273
+ # Merge the values from common, override JDBC URL.
274
+ test:
275
+ <<: *common
276
+ jdbc: hsqldb:file:testdb
277
+ {% endhighlight %}
278
+
279
+
280
+ You can "learn more about YAML here":http://www.yaml.org, and use this handy "YAML quick reference":http://www.yaml.org/refcard.html.
@@ -0,0 +1,222 @@
1
+ ---
2
+ layout: default
3
+ title: Testing
4
+ ---
5
+
6
+
7
+ Untested code is broken code, so we take testing seriously. Off the bat you get to use either JUnit or TestNG for writing unit tests and integration tests. And you can also add your own framework, or even script tests using Ruby. But= first, let's start with the basics.
8
+
9
+
10
+ h2(#writing). Writing Tests
11
+
12
+ Each project has a @TestTask@ that you can access using the @test@ method. @TestTask@ reflects on the fact that each project has one task responsible for getting the tests to run and acting on the results. But in fact there are several tasks that do all the work, and a @test@ task coordinates all of that.
13
+
14
+ The first two tasks to execute are @test.compile@ and @test.resources@. They work similar to @compile@ and @resources@, but uses a different set of directories. For example, Java tests compile from the @src/test/java@ directory into the @target/test/classes@ directory, while resources are copied from @src/test/resources@ into @target/test/resources@.
15
+
16
+ The @test.compile@ task will run the @compile@ task first, then use the same dependencies to compile the test classes. That much you already assumed. It also adds the test framework (e.g. JUnit, TestNG) and JMock to the dependency list. Less work for you.
17
+
18
+ If you need more dependencies, the best way to add them is by calling @test.with@. This method adds dependencies to both @compile.dependencies@ (for compiling) and @test.dependencies@ (for running). You can manage these two dependency lists separately, but using @test.with@ is good enough in more cases.
19
+
20
+ Once compiled, the @test@ task runs all the tests.
21
+
22
+ Different languages use different test frameworks. You can find out more about available test frameworks in the "Languages":languages.html section.
23
+
24
+
25
+ h2(#ignoring). Excluding Tests and Ignoring Failures
26
+
27
+ If you have a lot of tests that are failing or just hanging there collecting dusts, you can tell Buildr to ignore them. You can either tell Buildr to only run specific tests, for example:
28
+
29
+ {% highlight ruby %}
30
+ test.include 'com.acme.tests.passing.*'
31
+ {% endhighlight %}
32
+
33
+ Or tell it to exclude specific tests, for example:
34
+
35
+ {% highlight ruby %}
36
+ test.exclude '*FailingTest', '*FailingWorseTest'
37
+ {% endhighlight %}
38
+
39
+ Note that we're always using the package qualified class name, and you can use star (@*@) to substitute for any set of characters.
40
+
41
+ When tests fail, Buildr fails the @test@ task. This is usually a good thing, but you can also tell Buildr to ignore failures by resetting the @:fail_on_failure@ option:
42
+
43
+ {% highlight ruby %}
44
+ test.using :fail_on_failure=>false
45
+ {% endhighlight %}
46
+
47
+ Besides giving you a free pass to ignore failures, you can use it for other causes, for example, to be somewhat forgiving:
48
+
49
+ {% highlight ruby %}
50
+ test do
51
+ fail 'More than 3 tests failed!' if test.failed_tests.size > 3
52
+ end
53
+ {% endhighlight %}
54
+
55
+ The @failed_tests@ collection holds the names of all classes with failed tests. And there's @classes@, which holds the names of all test classes. Ruby arithmetic allows you to get the name of all passed test classes with a simple @test.classes – test.failed_tests@. We'll let you imagine creative use for these two.
56
+
57
+
58
+ h2(#running). Running Tests
59
+
60
+ It's a good idea to run tests every time you change the source code, so we wired the @build@ task to run the @test@ task at the end of the build. And conveniently enough, the @build@ task is the default task, so another way to build changes in your code and run your tests:
61
+
62
+ {% highlight sh %}
63
+ $ buildr
64
+ {% endhighlight %}
65
+
66
+ That only works with the local @build@ task and any local task that depends on it, like @package@, @install@ and @upload@. Each project also has its own @build@ task that does not invoke the @test@ task, so @buildr build@ will run the tests cases, but @buildr foo:build@ will not.
67
+
68
+ While it's a good idea to always run your tests, it's not always possible. There are two ways you can get @build@ to not run the @test@ task. You can set the environment variable @test@ to @no@ (but @skip@ and @off@ will also work). You can do that when running Buildr:
69
+
70
+ {% highlight sh %}
71
+ $ buildr test=no
72
+ {% endhighlight %}
73
+
74
+ Or set it once in your environment:
75
+
76
+ {% highlight sh %}
77
+ $ export TEST=no
78
+ $ buildr
79
+ {% endhighlight %}
80
+
81
+ If you're feeling really adventurous, you can also disable tests from your Buildfile or @buildr.rb@ file, by setting @options.test = false@. We didn't say it's a good idea, we're just giving you the option.
82
+
83
+ The @test@ task is just smart enough to run all the tests it finds, but will accept include/exclude patterns. Often enough you're only working on one broken test and you only want to run that one test. Better than changing your Buildfile, you can run the @test@ task with a pattern. For example:
84
+
85
+ {% highlight sh %}
86
+ $ buildr test:KillerAppTest
87
+ {% endhighlight %}
88
+
89
+ Buildr will then run only tests that match the pattern @KillerAppTest@. It uses pattern matching, so @test:Foo@ will run @com.acme.FooTest@ and @com.acme.FooBarTest@. With Java, you can use this to pick a class name, or a package name to run all tests in that package, or any such combination. In fact, you can specify several patterns separated with commas. For example:
90
+
91
+ {% highlight sh %}
92
+ $ buildr test:FooTest,BarTest
93
+ {% endhighlight %}
94
+
95
+ Buildr forcefully runs all tests that match the pattern. If you want to re-run all tests even if your sources have not changed, you can execute:
96
+
97
+ {% highlight sh %}
98
+ $ buildr test:*
99
+ {% endhighlight %}
100
+
101
+ As you probably noticed, Buildr will stop your build at the first test that fails. We think it's a good idea, except when it's not. If you're using a continuous build system, you'll want a report of all the failed tests without stopping at the first failure. To make that happen, set the environment variable @test@ to "all", or the Buildr @options.test@ option to @:all@. For example:
102
+
103
+ {% highlight sh %}
104
+ $ buildr package test=all
105
+ {% endhighlight %}
106
+
107
+ We're using @package@ and not @build@ above. When using a continuous build system, you want to make sure that packages are created, contain the right files, and also run the integration tests.
108
+
109
+
110
+ h2(#integration). Integration Tests
111
+
112
+ So far we talked about unit tests. Unit tests are run in isolation on the specific project they test, in an isolated environment, generally with minimal setup and teardown. You get a sense of that when we told you tests run after the @build@ task, and include JMock in the dependency list.
113
+
114
+ In contrast, integration tests are run with a number of components, in an environment that resembles production, often with more complicates setup and teardown procedures. In this section we'll talk about the differences between running unit and integration tests.
115
+
116
+ You write integration tests much the same way as you write unit tests, using @test.compile@ and @test.resources@. However, you need to tell Buildr that your tests will execute during integration test. To do so, add the following line in your project definition:
117
+
118
+ {% highlight ruby %}
119
+ test.using :integration
120
+ {% endhighlight %}
121
+
122
+ Typically you'll use unit tests in projects that create internal modules, such as JARs, and integration tests in projects that create components, such as WARs and EARs. You only need to use the @:integration@ option with the later.
123
+
124
+ To run integration tests on the current project:
125
+
126
+ {% highlight sh %}
127
+ $ buildr integration
128
+ {% endhighlight %}
129
+
130
+ You can also run specific tests cases, for example:
131
+
132
+ {% highlight sh %}
133
+ $ buildr integration:ClientTest
134
+ {% endhighlight %}
135
+
136
+ If you run the @package@ task (or any task that depends on it, like @install@ and @upload@), Buildr will first run the @build@ task and all its unit tests, and then create the packages and run the integration tests. That gives you full coverage for your tests and ready to release packages. As with unit tests, you can set the environment variable @test@ to "no" to skip integration tests, or "all" to ignore failures.
137
+
138
+
139
+ h2(#setup_teardown). Using Setup and Teardown
140
+
141
+ Some tests need you to setup an environment before they run, and tear it down afterwards. The test frameworks (JUnit, TestNG) allow you to do that for each test. Buildr provides two additional mechanisms for dealing with more complicated setup and teardown procedures.
142
+
143
+ Integration tests run a setup task before the tests, and a teardown task afterwards. You can use this task to setup a Web server for testing your Web components, or a database server for testing persistence. You can access either task by calling @integration.setup@ and @integration.teardown@. For example:
144
+
145
+ {% highlight ruby %}
146
+ integration.setup { server.start ; server.deploy }
147
+ integration.teardown { server.stop }
148
+ {% endhighlight %}
149
+
150
+ Depending on your build, you may want to enhance the setup/teardown tasks from within a project, for example, to populate the database with data used by that project's test, or from outside the project definition, for example, to start and stop the Web server.
151
+
152
+ Likewise, each project has its own setup and teardown tasks that are run before and after tests for that specific project. You can access these tasks using @test.setup@ and @test.teardown@.
153
+
154
+
155
+ h2(#checks). Testing Your Build
156
+
157
+ So you got the build running and all the tests pass, binaries are shipping when you find out some glaring omissions. The license file is empty, the localized messages for Japanese are missing, the CSS files are not where you expect them to be. The fact is, some errors slip by unit and integration tests. So how do we make sure the same mistake doesn't happen again?
158
+
159
+ Each project has a @check@ task that runs just after packaging. You can use this task to verify that your build created the files you wanted it to create. And to make it extremely convenient, we introduced the notion of expectations.
160
+
161
+ You use the @check@ method to express and expectation. Buildr will then run all these expectations against your project, and fail at the first expectation that doesn't match. An expectation says three things. Let's look at a few examples:
162
+
163
+ {% highlight ruby %}
164
+ check package(:war), 'should exist' do
165
+ it.should exist
166
+ end
167
+ check package(:war), 'should contain a manifest' do
168
+ it.should contain('META-INF/MANIFEST.MF')
169
+ end
170
+ check package(:war).path('WEB-INF'), 'should contain files' do
171
+ it.should_not be_empty
172
+ end
173
+ check package(:war).path('WEB-INF/classes'), 'should contain classes' do
174
+ it.should contain('**/*.class')
175
+ end
176
+ check package(:war).entry('META-INF/MANIFEST'), 'should have license' do
177
+ it.should contain(/Copyright (C) 2007/)
178
+ end
179
+ check file('target/classes'), 'should contain class files' do
180
+ it.should contain('**/*.class')
181
+ end
182
+ check file('target/classes/killerapp/Code.class'), 'should exist' do
183
+ it.should exist
184
+ end
185
+ {% endhighlight %}
186
+
187
+ The first argument is the subject, or the project if you skip the first argument. The second argument is the description, optional, but we recommend using it. The method @it@ returns the subject.
188
+
189
+ You can also write the first expectation like this:
190
+
191
+ {% highlight ruby %}
192
+ check do
193
+ package(:jar).should exist
194
+ end
195
+ {% endhighlight %}
196
+
197
+ We recommend using the subject and description, they make your build easier to read and maintain, and produce better error messages.
198
+
199
+ There are two methods you can call on just about any object, called @should@ and @should_not@. Each method takes an argument, a matcher, and executes that matcher. If the matcher returns false, @should@ fails. You can figure out what @should_not@ does in the same case.
200
+
201
+ Buildr provides the following matchers:
202
+
203
+ |_. Method |_. Checks that ... |
204
+ | @exist@ | Given a file task checks that the file (or directory) exists. |
205
+ | @empty@ | Given a file task checks that the file (or directory) is empty. |
206
+ | @contain@ | Given a file task referencing a file, checks its contents, using string or regular expression. For a file task referencing a directory, checks that it contains the specified files; global patterns using @*@ and @**@ are allowed. |
207
+
208
+ All these matchers operate against a file task. If you run them against a ZipTask (including JAR, WAR, etc) or a TarTask, they can also check the contents of the archive. And as you can see in the examples above, you can also run them against a path in an archive, checking its contents as if it was a directory, or against an entry in an archive, checking the content of that file.
209
+
210
+ p(note). The @package@ method returns a package task based on packaging type, identifier, group, version and classifier. The last four are inferred, but if you create a package with different specifications (for example, you specify a classifier) your checks must call @package@ with the same qualifying arguments to return the very same package task.
211
+
212
+ Buildr expectations are based on RSpec. "RSpec":http://rspec.info/ is the behavior-driven development framework we use to test Buildr itself. Check the RSpec documentation if want to see all the supported matchers, or want to write your own.
213
+
214
+
215
+ h2(#bdd). Behaviour-Driven Development
216
+
217
+ Buildr supports several Behaviour-Driven Development(BDD) frameworks for testing your projects. Buildr follows each framework naming conventions, searching for files under the @src/spec/{lang}@ directory.
218
+
219
+ You can learn more about each BDD framework in the "Languages":languages.html section.
220
+
221
+
222
+ Next, let's talk about "customizing your environment and using profiles":settings_profiles.html