mguymon-buildr 1.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1291 -0
- data/LICENSE +176 -0
- data/NOTICE +26 -0
- data/README.rdoc +134 -0
- data/Rakefile +44 -0
- data/_buildr +35 -0
- data/_jbuildr +35 -0
- data/addon/buildr/antlr.rb +65 -0
- data/addon/buildr/bnd.rb +147 -0
- data/addon/buildr/cobertura.rb +22 -0
- data/addon/buildr/drb.rb +281 -0
- data/addon/buildr/emma.rb +22 -0
- data/addon/buildr/hibernate.rb +149 -0
- data/addon/buildr/javacc.rb +85 -0
- data/addon/buildr/jaxb_xjc.rb +72 -0
- data/addon/buildr/jdepend.rb +60 -0
- data/addon/buildr/jetty.rb +248 -0
- data/addon/buildr/jibx.rb +86 -0
- data/addon/buildr/nailgun.rb +221 -0
- data/addon/buildr/openjpa.rb +88 -0
- data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
- data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
- data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
- data/addon/buildr/protobuf.rb +88 -0
- data/addon/buildr/xmlbeans.rb +93 -0
- data/bin/buildr +19 -0
- data/buildr.buildfile +58 -0
- data/buildr.gemspec +78 -0
- data/doc/_config.yml +1 -0
- data/doc/_layouts/default.html +90 -0
- data/doc/_layouts/preface.html +22 -0
- data/doc/artifacts.textile +217 -0
- data/doc/building.textile +276 -0
- data/doc/contributing.textile +268 -0
- data/doc/css/default.css +236 -0
- data/doc/css/print.css +101 -0
- data/doc/css/syntax.css +23 -0
- data/doc/download.textile +151 -0
- data/doc/extending.textile +212 -0
- data/doc/images/1442160941-frontcover.jpg +0 -0
- data/doc/images/asf-logo.gif +0 -0
- data/doc/images/asf-logo.png +0 -0
- data/doc/images/buildr-hires.png +0 -0
- data/doc/images/buildr.png +0 -0
- data/doc/images/favicon.png +0 -0
- data/doc/images/growl-icon.tiff +0 -0
- data/doc/images/note.png +0 -0
- data/doc/images/project-structure.png +0 -0
- data/doc/images/tip.png +0 -0
- data/doc/images/zbuildr.png +0 -0
- data/doc/images/zbuildr.tif +0 -0
- data/doc/index.textile +109 -0
- data/doc/installing.textile +284 -0
- data/doc/languages.textile +599 -0
- data/doc/mailing_lists.textile +29 -0
- data/doc/more_stuff.textile +845 -0
- data/doc/packaging.textile +618 -0
- data/doc/preface.textile +54 -0
- data/doc/projects.textile +276 -0
- data/doc/quick_start.textile +210 -0
- data/doc/releasing.textile +117 -0
- data/doc/scripts/buildr-git.rb +512 -0
- data/doc/scripts/gitflow.rb +296 -0
- data/doc/scripts/install-jruby.sh +44 -0
- data/doc/scripts/install-linux.sh +73 -0
- data/doc/scripts/install-osx.sh +52 -0
- data/doc/settings_profiles.textile +287 -0
- data/doc/testing.textile +247 -0
- data/etc/KEYS +189 -0
- data/lib/buildr.rb +44 -0
- data/lib/buildr/clojure.rb +34 -0
- data/lib/buildr/clojure/shell.rb +52 -0
- data/lib/buildr/core.rb +34 -0
- data/lib/buildr/core/application.rb +700 -0
- data/lib/buildr/core/build.rb +516 -0
- data/lib/buildr/core/cc.rb +166 -0
- data/lib/buildr/core/checks.rb +253 -0
- data/lib/buildr/core/common.rb +151 -0
- data/lib/buildr/core/compile.rb +622 -0
- data/lib/buildr/core/doc.rb +276 -0
- data/lib/buildr/core/environment.rb +129 -0
- data/lib/buildr/core/filter.rb +404 -0
- data/lib/buildr/core/generate.rb +197 -0
- data/lib/buildr/core/help.rb +119 -0
- data/lib/buildr/core/jrebel.rb +42 -0
- data/lib/buildr/core/linux.rb +30 -0
- data/lib/buildr/core/osx.rb +46 -0
- data/lib/buildr/core/progressbar.rb +161 -0
- data/lib/buildr/core/project.rb +975 -0
- data/lib/buildr/core/run.rb +43 -0
- data/lib/buildr/core/shell.rb +137 -0
- data/lib/buildr/core/test.rb +843 -0
- data/lib/buildr/core/transports.rb +575 -0
- data/lib/buildr/core/util.rb +537 -0
- data/lib/buildr/groovy.rb +20 -0
- data/lib/buildr/groovy/bdd.rb +106 -0
- data/lib/buildr/groovy/compiler.rb +153 -0
- data/lib/buildr/groovy/doc.rb +76 -0
- data/lib/buildr/groovy/shell.rb +57 -0
- data/lib/buildr/ide.rb +19 -0
- data/lib/buildr/ide/eclipse.rb +427 -0
- data/lib/buildr/ide/eclipse/java.rb +53 -0
- data/lib/buildr/ide/eclipse/plugin.rb +71 -0
- data/lib/buildr/ide/eclipse/scala.rb +68 -0
- data/lib/buildr/ide/idea.rb +576 -0
- data/lib/buildr/java.rb +25 -0
- data/lib/buildr/java/ant.rb +94 -0
- data/lib/buildr/java/bdd.rb +460 -0
- data/lib/buildr/java/cobertura.rb +297 -0
- data/lib/buildr/java/commands.rb +223 -0
- data/lib/buildr/java/compiler.rb +135 -0
- data/lib/buildr/java/deprecated.rb +141 -0
- data/lib/buildr/java/doc.rb +86 -0
- data/lib/buildr/java/ecj.rb +69 -0
- data/lib/buildr/java/emma.rb +244 -0
- data/lib/buildr/java/external.rb +73 -0
- data/lib/buildr/java/jruby.rb +122 -0
- data/lib/buildr/java/jtestr_result.rb +295 -0
- data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
- data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +142 -0
- data/lib/buildr/java/packaging.rb +734 -0
- data/lib/buildr/java/pom.rb +178 -0
- data/lib/buildr/java/rjb.rb +154 -0
- data/lib/buildr/java/test_result.rb +101 -0
- data/lib/buildr/java/tests.rb +362 -0
- data/lib/buildr/java/version_requirement.rb +172 -0
- data/lib/buildr/packaging.rb +25 -0
- data/lib/buildr/packaging/archive.rb +535 -0
- data/lib/buildr/packaging/artifact.rb +904 -0
- data/lib/buildr/packaging/artifact_namespace.rb +984 -0
- data/lib/buildr/packaging/artifact_search.rb +140 -0
- data/lib/buildr/packaging/gems.rb +105 -0
- data/lib/buildr/packaging/package.rb +249 -0
- data/lib/buildr/packaging/repository_array.rb +108 -0
- data/lib/buildr/packaging/tar.rb +189 -0
- data/lib/buildr/packaging/version_requirement.rb +192 -0
- data/lib/buildr/packaging/zip.rb +178 -0
- data/lib/buildr/packaging/ziptask.rb +356 -0
- data/lib/buildr/resources/buildr.icns +0 -0
- data/lib/buildr/resources/completed.png +0 -0
- data/lib/buildr/resources/failed.png +0 -0
- data/lib/buildr/resources/icons-license.txt +17 -0
- data/lib/buildr/run.rb +195 -0
- data/lib/buildr/scala.rb +26 -0
- data/lib/buildr/scala/bdd.rb +118 -0
- data/lib/buildr/scala/compiler.rb +242 -0
- data/lib/buildr/scala/doc.rb +142 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
- data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
- data/lib/buildr/scala/shell.rb +52 -0
- data/lib/buildr/scala/tests.rb +171 -0
- data/lib/buildr/shell.rb +185 -0
- data/lib/buildr/version.rb +18 -0
- data/rakelib/all-in-one.rake +113 -0
- data/rakelib/checks.rake +57 -0
- data/rakelib/doc.rake +137 -0
- data/rakelib/metrics.rake +39 -0
- data/rakelib/package.rake +73 -0
- data/rakelib/release.rake +160 -0
- data/rakelib/rspec.rake +91 -0
- data/rakelib/setup.rake +66 -0
- data/rakelib/stage.rake +220 -0
- data/spec/addon/bnd_spec.rb +330 -0
- data/spec/addon/drb_spec.rb +328 -0
- data/spec/addon/jaxb_xjc_spec.rb +125 -0
- data/spec/core/application_spec.rb +631 -0
- data/spec/core/build_spec.rb +837 -0
- data/spec/core/cc_spec.rb +224 -0
- data/spec/core/checks_spec.rb +519 -0
- data/spec/core/common_spec.rb +725 -0
- data/spec/core/compile_spec.rb +658 -0
- data/spec/core/doc_spec.rb +195 -0
- data/spec/core/extension_spec.rb +201 -0
- data/spec/core/generate_spec.rb +33 -0
- data/spec/core/project_spec.rb +772 -0
- data/spec/core/run_spec.rb +93 -0
- data/spec/core/shell_spec.rb +146 -0
- data/spec/core/test_spec.rb +1320 -0
- data/spec/core/transport_spec.rb +544 -0
- data/spec/core/util_spec.rb +141 -0
- data/spec/groovy/bdd_spec.rb +80 -0
- data/spec/groovy/compiler_spec.rb +251 -0
- data/spec/groovy/doc_spec.rb +65 -0
- data/spec/ide/eclipse_spec.rb +739 -0
- data/spec/ide/idea_spec.rb +1145 -0
- data/spec/java/ant_spec.rb +37 -0
- data/spec/java/bdd_spec.rb +374 -0
- data/spec/java/cobertura_spec.rb +112 -0
- data/spec/java/commands_spec.rb +93 -0
- data/spec/java/compiler_spec.rb +252 -0
- data/spec/java/doc_spec.rb +56 -0
- data/spec/java/ecj_spec.rb +115 -0
- data/spec/java/emma_spec.rb +121 -0
- data/spec/java/external_spec.rb +56 -0
- data/spec/java/java_spec.rb +132 -0
- data/spec/java/packaging_spec.rb +1266 -0
- data/spec/java/run_spec.rb +78 -0
- data/spec/java/test_coverage_helper.rb +257 -0
- data/spec/java/tests_spec.rb +497 -0
- data/spec/packaging/archive_spec.rb +775 -0
- data/spec/packaging/artifact_namespace_spec.rb +743 -0
- data/spec/packaging/artifact_spec.rb +1074 -0
- data/spec/packaging/packaging_helper.rb +63 -0
- data/spec/packaging/packaging_spec.rb +719 -0
- data/spec/packaging/repository_array_spec.rb +109 -0
- data/spec/sandbox.rb +165 -0
- data/spec/scala/bdd_spec.rb +124 -0
- data/spec/scala/compiler_spec.rb +289 -0
- data/spec/scala/doc_spec.rb +88 -0
- data/spec/scala/scala.rb +38 -0
- data/spec/scala/tests_spec.rb +283 -0
- data/spec/spec_helpers.rb +369 -0
- data/spec/version_requirement_spec.rb +143 -0
- data/spec/xpath_matchers.rb +121 -0
- metadata +649 -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.release_to[:username] = ENV['USERNAME']
|
58
|
+
repositories.release_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.release_to[:username] = 'assaf'
|
178
|
+
repositories.release_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 = (Buildr.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.
|
data/doc/testing.textile
ADDED
@@ -0,0 +1,247 @@
|
|
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, as a gentle reminder:
|
48
|
+
|
49
|
+
{% highlight ruby %}
|
50
|
+
test do
|
51
|
+
warn "Did you forget something?" if test.tests.nil? || test.tests.empty?
|
52
|
+
end
|
53
|
+
{% endhighlight %}
|
54
|
+
|
55
|
+
The @tests@ collection holds the names of all classes with tests, if any. And there's @classes@, which holds the names of all test classes. 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
|
+
You can exclude tests by preceeding them with a minus sign ('-'):
|
102
|
+
|
103
|
+
{% highlight sh %}
|
104
|
+
$ buildr test:-Bar
|
105
|
+
{% endhighlight %}
|
106
|
+
|
107
|
+
The above would run all tests except those with a name containing @Bar@. Exclusions can be combined with inclusions:
|
108
|
+
|
109
|
+
{% highlight sh %}
|
110
|
+
$ buildr test:Foo,-Bar
|
111
|
+
{% endhighlight %}
|
112
|
+
|
113
|
+
Buildr would then run tests with names containing @Foo@ but not @Bar@.
|
114
|
+
|
115
|
+
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:
|
116
|
+
|
117
|
+
{% highlight sh %}
|
118
|
+
$ buildr package test=all
|
119
|
+
{% endhighlight %}
|
120
|
+
|
121
|
+
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.
|
122
|
+
|
123
|
+
During development, if you want to re-run only tests that have failed during the last test execution, you can execute:
|
124
|
+
|
125
|
+
{% highlight sh %}
|
126
|
+
$ buildr test:failed
|
127
|
+
{% endhighlight %}
|
128
|
+
|
129
|
+
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,
|
130
|
+
|
131
|
+
{% highlight sh %}
|
132
|
+
$ buildr test=only bar:test
|
133
|
+
{% endhighlight %}
|
134
|
+
|
135
|
+
h2(#integration). Integration Tests
|
136
|
+
|
137
|
+
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.
|
138
|
+
|
139
|
+
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.
|
140
|
+
|
141
|
+
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:
|
142
|
+
|
143
|
+
{% highlight ruby %}
|
144
|
+
test.using :integration
|
145
|
+
{% endhighlight %}
|
146
|
+
|
147
|
+
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.
|
148
|
+
|
149
|
+
To run integration tests on the current project:
|
150
|
+
|
151
|
+
{% highlight sh %}
|
152
|
+
$ buildr integration
|
153
|
+
{% endhighlight %}
|
154
|
+
|
155
|
+
You can also run specific tests cases, for example:
|
156
|
+
|
157
|
+
{% highlight sh %}
|
158
|
+
$ buildr integration:ClientTest
|
159
|
+
{% endhighlight %}
|
160
|
+
|
161
|
+
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.
|
162
|
+
|
163
|
+
|
164
|
+
h2(#setup_teardown). Using Setup and Teardown
|
165
|
+
|
166
|
+
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.
|
167
|
+
|
168
|
+
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:
|
169
|
+
|
170
|
+
{% highlight ruby %}
|
171
|
+
integration.setup { server.start ; server.deploy }
|
172
|
+
integration.teardown { server.stop }
|
173
|
+
{% endhighlight %}
|
174
|
+
|
175
|
+
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.
|
176
|
+
|
177
|
+
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@.
|
178
|
+
|
179
|
+
|
180
|
+
h2(#checks). Testing Your Build
|
181
|
+
|
182
|
+
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?
|
183
|
+
|
184
|
+
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.
|
185
|
+
|
186
|
+
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:
|
187
|
+
|
188
|
+
{% highlight ruby %}
|
189
|
+
check package(:war), 'should exist' do
|
190
|
+
it.should exist
|
191
|
+
end
|
192
|
+
check package(:war), 'should contain a manifest' do
|
193
|
+
it.should contain('META-INF/MANIFEST.MF')
|
194
|
+
end
|
195
|
+
check package(:war).path('WEB-INF'), 'should contain files' do
|
196
|
+
it.should_not be_empty
|
197
|
+
end
|
198
|
+
check package(:war).path('WEB-INF/classes'), 'should contain classes' do
|
199
|
+
it.should contain('**/*.class')
|
200
|
+
end
|
201
|
+
check package(:war).entry('META-INF/MANIFEST'), 'should have license' do
|
202
|
+
it.should contain(/Copyright (C) 2007/)
|
203
|
+
end
|
204
|
+
check file('target/classes'), 'should contain class files' do
|
205
|
+
it.should contain('**/*.class')
|
206
|
+
end
|
207
|
+
check file('target/classes/killerapp/Code.class'), 'should exist' do
|
208
|
+
it.should exist
|
209
|
+
end
|
210
|
+
{% endhighlight %}
|
211
|
+
|
212
|
+
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.
|
213
|
+
|
214
|
+
You can also write the first expectation like this:
|
215
|
+
|
216
|
+
{% highlight ruby %}
|
217
|
+
check do
|
218
|
+
package(:jar).should exist
|
219
|
+
end
|
220
|
+
{% endhighlight %}
|
221
|
+
|
222
|
+
We recommend using the subject and description, they make your build easier to read and maintain, and produce better error messages.
|
223
|
+
|
224
|
+
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.
|
225
|
+
|
226
|
+
Buildr provides the following matchers:
|
227
|
+
|
228
|
+
|_. Method |_. Checks that ... |
|
229
|
+
| @exist@ | Given a file task checks that the file (or directory) exists. |
|
230
|
+
| @empty@ | Given a file task checks that the file (or directory) is empty. |
|
231
|
+
| @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. |
|
232
|
+
|
233
|
+
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.
|
234
|
+
|
235
|
+
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.
|
236
|
+
|
237
|
+
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.
|
238
|
+
|
239
|
+
|
240
|
+
h2(#bdd). Behaviour-Driven Development
|
241
|
+
|
242
|
+
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.
|
243
|
+
|
244
|
+
You can learn more about each BDD framework in the "Languages":languages.html section.
|
245
|
+
|
246
|
+
|
247
|
+
Next, let's talk about "customizing your environment and using profiles":settings_profiles.html
|