novoda-buildr 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/CHANGELOG +1050 -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 +245 -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 +90 -0
  40. data/doc/extending.textile +205 -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 +265 -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 +429 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +276 -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 +287 -0
  68. data/doc/testing.textile +233 -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 +662 -0
  73. data/lib/buildr/core/build.rb +463 -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 +363 -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 +971 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +774 -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 +424 -0
  94. data/lib/buildr/ide/eclipse.rb~ +424 -0
  95. data/lib/buildr/ide/eclipse/java.rb +53 -0
  96. data/lib/buildr/ide/eclipse/plugin.rb +71 -0
  97. data/lib/buildr/ide/eclipse/scala.rb +68 -0
  98. data/lib/buildr/ide/idea.ipr.template +300 -0
  99. data/lib/buildr/ide/idea.rb +190 -0
  100. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  101. data/lib/buildr/ide/idea7x.rb +212 -0
  102. data/lib/buildr/java.rb +23 -0
  103. data/lib/buildr/java/ant.rb +94 -0
  104. data/lib/buildr/java/bdd.rb +464 -0
  105. data/lib/buildr/java/cobertura.rb +274 -0
  106. data/lib/buildr/java/commands.rb +217 -0
  107. data/lib/buildr/java/compiler.rb +349 -0
  108. data/lib/buildr/java/deprecated.rb +141 -0
  109. data/lib/buildr/java/emma.rb +244 -0
  110. data/lib/buildr/java/jruby.rb +117 -0
  111. data/lib/buildr/java/jtestr_runner.rb.erb +118 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  113. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
  114. data/lib/buildr/java/packaging.rb +717 -0
  115. data/lib/buildr/java/pom.rb +174 -0
  116. data/lib/buildr/java/rjb.rb +155 -0
  117. data/lib/buildr/java/test_result.rb +327 -0
  118. data/lib/buildr/java/tests.rb +341 -0
  119. data/lib/buildr/java/version_requirement.rb +172 -0
  120. data/lib/buildr/packaging.rb +24 -0
  121. data/lib/buildr/packaging/archive.rb +491 -0
  122. data/lib/buildr/packaging/artifact.rb +750 -0
  123. data/lib/buildr/packaging/artifact_namespace.rb +980 -0
  124. data/lib/buildr/packaging/artifact_search.rb +140 -0
  125. data/lib/buildr/packaging/gems.rb +106 -0
  126. data/lib/buildr/packaging/package.rb +241 -0
  127. data/lib/buildr/packaging/tar.rb +186 -0
  128. data/lib/buildr/packaging/version_requirement.rb +172 -0
  129. data/lib/buildr/packaging/zip.rb +73 -0
  130. data/lib/buildr/packaging/ziptask.rb +316 -0
  131. data/lib/buildr/resources/buildr.icns +0 -0
  132. data/lib/buildr/scala.rb +25 -0
  133. data/lib/buildr/scala/bdd.rb +114 -0
  134. data/lib/buildr/scala/compiler.rb +196 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  137. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  138. data/lib/buildr/scala/shell.rb +60 -0
  139. data/lib/buildr/scala/tests.rb +157 -0
  140. data/lib/buildr/shell.rb +180 -0
  141. data/rakelib/all-in-one.rake +84 -0
  142. data/rakelib/checks.rake +57 -0
  143. data/rakelib/doc.rake +92 -0
  144. data/rakelib/jekylltask.rb +120 -0
  145. data/rakelib/package.rake +73 -0
  146. data/rakelib/release.rake +152 -0
  147. data/rakelib/rspec.rake +73 -0
  148. data/rakelib/setup.rake +54 -0
  149. data/rakelib/stage.rake +214 -0
  150. data/spec/addon/drb_spec.rb +328 -0
  151. data/spec/core/application_spec.rb +509 -0
  152. data/spec/core/build_spec.rb +678 -0
  153. data/spec/core/checks_spec.rb +519 -0
  154. data/spec/core/common_spec.rb +670 -0
  155. data/spec/core/compile_spec.rb +624 -0
  156. data/spec/core/extension_spec.rb +201 -0
  157. data/spec/core/generate_spec.rb +33 -0
  158. data/spec/core/project_spec.rb +762 -0
  159. data/spec/core/test_spec.rb +1175 -0
  160. data/spec/core/transport_spec.rb +537 -0
  161. data/spec/core/util_spec.rb +67 -0
  162. data/spec/groovy/bdd_spec.rb +80 -0
  163. data/spec/groovy/compiler_spec.rb +240 -0
  164. data/spec/ide/eclipse_spec.rb +650 -0
  165. data/spec/ide/idea7x_spec.rb +84 -0
  166. data/spec/java/ant_spec.rb +33 -0
  167. data/spec/java/bdd_spec.rb +379 -0
  168. data/spec/java/cobertura_spec.rb +85 -0
  169. data/spec/java/compiler_spec.rb +446 -0
  170. data/spec/java/emma_spec.rb +119 -0
  171. data/spec/java/java_spec.rb +124 -0
  172. data/spec/java/packaging_spec.rb +1140 -0
  173. data/spec/java/test_coverage_helper.rb +257 -0
  174. data/spec/java/tests_spec.rb +493 -0
  175. data/spec/packaging/archive_spec.rb +538 -0
  176. data/spec/packaging/artifact_namespace_spec.rb +697 -0
  177. data/spec/packaging/artifact_spec.rb +802 -0
  178. data/spec/packaging/packaging_helper.rb +63 -0
  179. data/spec/packaging/packaging_spec.rb +684 -0
  180. data/spec/sandbox.rb +148 -0
  181. data/spec/scala/bdd_spec.rb +119 -0
  182. data/spec/scala/compiler_spec.rb +284 -0
  183. data/spec/scala/scala.rb +38 -0
  184. data/spec/scala/tests_spec.rb +263 -0
  185. data/spec/spec_helpers.rb +340 -0
  186. data/spec/version_requirement_spec.rb +143 -0
  187. metadata +384 -0
@@ -0,0 +1,287 @@
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
+ | @IGNORE_BUILDFILE@ | Set to "true" or "yes" to ignore changes in Buildfile or its dependencies when running tests. |
45
+ | @JAVA_HOME@ | Points to your JDK, required when using Java and Ant. |
46
+ | @JAVA_OPTS@ | Command line options to pass to the JDK (e.g. @'-Xms1g'@). |
47
+ | @M2_REPO@ | Location of the Maven2 local repository. Defaults to the @.m2@ directory in your home directory (@ENV['HOME']@). |
48
+ | @NO_PROXY@ | Comma separated list of hosts and domain that should not be proxied (see "Specifying Repositories":artifacts.html#repositories). |
49
+ | @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). |
50
+ | @USER@ | Tasks that need your user name, for example to log to remote servers, will use this environment variable. |
51
+
52
+ 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@.
53
+
54
+ 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:
55
+
56
+ {% highlight ruby %}
57
+ repositories.upload_to[:username] = ENV['USERNAME']
58
+ repositories.upload_to[:password] = ENV['PASSWORD']
59
+ {% endhighlight %}
60
+
61
+
62
+ h2(#personal). Personal Settings
63
+
64
+ 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.
65
+
66
+ 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.
67
+
68
+ 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.
69
+
70
+ Here's an example @settings.yaml@:
71
+
72
+ {% highlight yaml %}
73
+ # The repositories hash is read automatically by buildr.
74
+ repositories:
75
+
76
+ # customize user local maven2 repository location
77
+ local: some/path/to/my_repo
78
+
79
+ # prefer the local or nearest mirrors
80
+ remote:
81
+ - https://intra.net/maven2
82
+ - http://example.com
83
+
84
+ relase_to:
85
+ url: http://intra.net/maven2
86
+ username: john
87
+ password: secret
88
+
89
+ # You can place settings of your own, and reference them
90
+ # on buildfiles.
91
+ im:
92
+ server: jabber.company.com
93
+ usr: notifier@company-jabber.com
94
+ pwd: secret
95
+ {% endhighlight %}
96
+
97
+ Later your buildfile or addons can reference user preferences using the hash returned by the @Buildr.settings.user@ accessor.
98
+
99
+ {% highlight ruby %}
100
+ task 'relase-notification' do
101
+ usr, pwd, server = settings.user['im'].values_at('usr', 'pwd', 'server')
102
+ jabber = JabberAPI.new(server, usr, pwd)
103
+ jabber.msg("We are pleased to announce the last stable version #{VERSION}")
104
+ end
105
+ {% endhighlight %}
106
+
107
+
108
+ h2(#build). Build Settings
109
+
110
+ 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.
111
+
112
+ 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.
113
+
114
+ {% highlight yaml %}
115
+ # This project requires the following ruby gems, buildr addons
116
+ gems:
117
+ # Suppose we want to notify developers when testcases fail.
118
+ - buildr-twitter-notifier-addon >=1
119
+ # we test with ruby mock objects
120
+ - mocha
121
+ - ci_reporter
122
+
123
+ # The artifact declarations will be automatically loaded by buildr, so that
124
+ # you can reference artifacts by name (a ruby-symbol) on your buildfile.
125
+ artifacts:
126
+ spring: org.springframework:spring:jar:2.0
127
+ log4j: log4j:log4j:jar:1.0
128
+ j2ee: geronimo-spec:geronimo-spec-j2ee:jar:1.4-rc4
129
+
130
+ # Of course project settings can be defined here
131
+ twitter:
132
+ notify:
133
+ test_failure: unless-modified
134
+ compile_failure: never
135
+ developers:
136
+ - joe
137
+ - jane
138
+
139
+ jira:
140
+ uri: https://jira.corp.org
141
+ {% endhighlight %}
142
+
143
+ When buildr is loaded, required ruby gems will be installed if needed, thus adding features like the imaginary twitter notifier addon.
144
+
145
+ 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.
146
+
147
+ {% highlight ruby %}
148
+ define 'my_project' do
149
+ compile.with artifacts(:log4j, :j2ee)
150
+ test.with :spring, :j2ee
151
+ end
152
+ {% endhighlight %}
153
+
154
+ Build settings can be retreived using the @Buildr.settings.build@ accessor.
155
+
156
+ {% highlight ruby %}
157
+ task 'create_patch' do
158
+ patch = Git.create_patch :interactive => true
159
+ if patch && agree("Would you like to request inclusion of #{patch}")
160
+ jira = Jira.new( Buildr.settings.build['jira']['uri'] ) # submit a patch
161
+ jira.create(:improvement, patch.summary, :attachment => patch.blob)
162
+ end
163
+ end
164
+ {% endhighlight %}
165
+
166
+
167
+ h2(#variable). Non constant settings
168
+
169
+ Before loading the Buildfile, Buildr will attempt to load two other files: the @buildr.rb@ file in the @.buildr@ directory under your home directory, followed by the @buildr.rb@ file it finds in the build directory.
170
+
171
+ The loading order allows you to place global settings that affect all your builds in your @buildr.rb@, but also over-ride those with settings for a given project.
172
+
173
+ Here's an example @buildr.rb@:
174
+
175
+ {% highlight ruby %}
176
+ # Only I should know that
177
+ repositories.upload_to[:username] = 'assaf'
178
+ repositories.upload_to[:password] = 'supersecret'
179
+ # Search here first, it's faster
180
+ repositories.remote << 'http://inside-the-firewall'
181
+ {% endhighlight %}
182
+
183
+ p(note). Buildr 1.3 and earlier used the file @buildr.rb@ directly in your home directory. Starting with version 1.4, Buildr loads @buildr.rb@ from the @.buildr@ directory under your home directory in preference. If you use Buildr 1.3 and earlier and don't want to duplicate your settings, you can move you existing @buildr.rb@ under the @.buildr@ directory and create a new @buildr.rb@ in your home directory containing:
184
+
185
+ {% highlight ruby %}
186
+ # Backward compatibility: Buildr 1.4+ uses $HOME/.buildr/buildr.rb
187
+ load File.expand_path('buildr.rb', Buildr.application.home_dir)
188
+ {% endhighlight %}
189
+
190
+ h2(#environments). Environments
191
+
192
+ 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.
193
+
194
+ 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:
195
+
196
+ {% highlight sh %}
197
+ $ buildr -e test
198
+ (in /home/john/project, test)
199
+ {% endhighlight %}
200
+
201
+ Or by setting the environment variable @BUILDR_ENV@:
202
+
203
+ {% highlight text %}
204
+ $ export BUILDR_ENV=production
205
+ $ buildr
206
+ (in /home/john/project, production)
207
+ {% endhighlight %}
208
+
209
+ Unless you tell it otherwise, Buildr assumes you're developing and sets the environment to @development@.
210
+
211
+ Here's a simple example for handling different environments within the Buildfile:
212
+
213
+ {% highlight ruby %}
214
+ project 'db-module' do
215
+ db = (environment == 'production' ? 'oracle' : 'hsql')
216
+ resources.from(_("src/main/#{db}"))
217
+ end
218
+ {% endhighlight %}
219
+
220
+ We recommend picking a convention for your different environments and following it across all your projects. For example:
221
+
222
+ |_. Environment |_. Use when ... |
223
+ | development | Developing on your machine. |
224
+ | test | Running in test environment, continuous integration. |
225
+ | production | Building for release/production. |
226
+
227
+
228
+ h2(#profiles). Profiles
229
+
230
+ Different environments may require different configurations, some you will want to control with code, others you will want to specify in the profiles file.
231
+
232
+ 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.
233
+
234
+ For example, to support three different database configurations, we could write:
235
+
236
+ {% highlight yaml %}
237
+ # HSQL, don't bother storing to disk.
238
+ development:
239
+ db: hsql
240
+ jdbc: hsqldb:mem:devdb
241
+
242
+ # Make sure we're not messing with bigstrong.
243
+ test:
244
+ db: oracle
245
+ jdbc: oracle:thin:@localhost:1521:test
246
+
247
+ # The real deal.
248
+ production:
249
+ db: oracle
250
+ jdbc: oracle:thin:@bigstrong:1521:mighty
251
+ {% endhighlight %}
252
+
253
+ Here's a simple example for a buildfile that uses the profile information:
254
+
255
+ {% highlight ruby %}
256
+ project 'db-module' do
257
+ # Copy SQL files specific for the database we're using,
258
+ # for example, everything under src/main/hsql.
259
+ resources.from(_("src/main/#{Buildr.settings.profile['db']}"))
260
+ # Set the JDBC URL in copied resource files (config.xml needs this).
261
+ resources.filter.using :jdbc=>Buildr.settings.profile['jdbc']
262
+ end
263
+ {% endhighlight %}
264
+
265
+ 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@.
266
+
267
+ When you run the above example in @development@, the current profile will return the hash @{ 'db'=>'hsql', 'jdbc'=>'hsqldb:mem:devdb' }@.
268
+
269
+ 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.
270
+
271
+ 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:
272
+
273
+ {% highlight yaml %}
274
+ # We'll reference this one as common.
275
+ development: &common
276
+ db: hsql
277
+ jdbc: hsqldb:mem:devdb
278
+ resources:
279
+ copyright: Me (C) 2008
280
+ # Merge the values from common, override JDBC URL.
281
+ test:
282
+ <<: *common
283
+ jdbc: hsqldb:file:testdb
284
+ {% endhighlight %}
285
+
286
+
287
+ 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,233 @@
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
+ During development, if you want to re-run only tests that have failed during the last test execution, you can execute:
110
+
111
+ {% highlight sh %}
112
+ $ buildr test:failed
113
+ {% endhighlight %}
114
+
115
+ One last note on running tests. By default when you run tests, Buildr will automatically run all transitive test dependencies. This mean if you run "buildr test" inside project @bar@ and @bar@ depends on project @foo@, Buildr will first run tests in project @foo@ if there have been any changes affecting @foo@ that haven't been taken into account yet. This behavior often surprises people, especially when they are trying to get things done and only care about tests in @bar@ at that moment. For those times when you'd like to focus your testing on specific projects, Buildr has the @only@ option that will only run tests for projects specified on the command line,
116
+
117
+ {% highlight sh %}
118
+ $ buildr test=only bar:test
119
+ {% endhighlight %}
120
+
121
+ h2(#integration). Integration Tests
122
+
123
+ 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.
124
+
125
+ 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.
126
+
127
+ 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:
128
+
129
+ {% highlight ruby %}
130
+ test.using :integration
131
+ {% endhighlight %}
132
+
133
+ 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.
134
+
135
+ To run integration tests on the current project:
136
+
137
+ {% highlight sh %}
138
+ $ buildr integration
139
+ {% endhighlight %}
140
+
141
+ You can also run specific tests cases, for example:
142
+
143
+ {% highlight sh %}
144
+ $ buildr integration:ClientTest
145
+ {% endhighlight %}
146
+
147
+ 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.
148
+
149
+
150
+ h2(#setup_teardown). Using Setup and Teardown
151
+
152
+ 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.
153
+
154
+ 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:
155
+
156
+ {% highlight ruby %}
157
+ integration.setup { server.start ; server.deploy }
158
+ integration.teardown { server.stop }
159
+ {% endhighlight %}
160
+
161
+ 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.
162
+
163
+ 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@.
164
+
165
+
166
+ h2(#checks). Testing Your Build
167
+
168
+ 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?
169
+
170
+ 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.
171
+
172
+ 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:
173
+
174
+ {% highlight ruby %}
175
+ check package(:war), 'should exist' do
176
+ it.should exist
177
+ end
178
+ check package(:war), 'should contain a manifest' do
179
+ it.should contain('META-INF/MANIFEST.MF')
180
+ end
181
+ check package(:war).path('WEB-INF'), 'should contain files' do
182
+ it.should_not be_empty
183
+ end
184
+ check package(:war).path('WEB-INF/classes'), 'should contain classes' do
185
+ it.should contain('**/*.class')
186
+ end
187
+ check package(:war).entry('META-INF/MANIFEST'), 'should have license' do
188
+ it.should contain(/Copyright (C) 2007/)
189
+ end
190
+ check file('target/classes'), 'should contain class files' do
191
+ it.should contain('**/*.class')
192
+ end
193
+ check file('target/classes/killerapp/Code.class'), 'should exist' do
194
+ it.should exist
195
+ end
196
+ {% endhighlight %}
197
+
198
+ 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.
199
+
200
+ You can also write the first expectation like this:
201
+
202
+ {% highlight ruby %}
203
+ check do
204
+ package(:jar).should exist
205
+ end
206
+ {% endhighlight %}
207
+
208
+ We recommend using the subject and description, they make your build easier to read and maintain, and produce better error messages.
209
+
210
+ 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.
211
+
212
+ Buildr provides the following matchers:
213
+
214
+ |_. Method |_. Checks that ... |
215
+ | @exist@ | Given a file task checks that the file (or directory) exists. |
216
+ | @empty@ | Given a file task checks that the file (or directory) is empty. |
217
+ | @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. |
218
+
219
+ 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.
220
+
221
+ 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.
222
+
223
+ 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.
224
+
225
+
226
+ h2(#bdd). Behaviour-Driven Development
227
+
228
+ 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.
229
+
230
+ You can learn more about each BDD framework in the "Languages":languages.html section.
231
+
232
+
233
+ Next, let's talk about "customizing your environment and using profiles":settings_profiles.html