buildr 1.4.7 → 1.4.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +41 -0
- data/Rakefile +0 -6
- data/addon/buildr/bnd.rb +13 -3
- data/addon/buildr/checkstyle.rb +1 -1
- data/addon/buildr/git_auto_version.rb +33 -0
- data/addon/buildr/{gwt.rake → gwt.rb} +0 -0
- data/addon/buildr/jacoco.rb +194 -0
- data/buildr.buildfile +1 -1
- data/buildr.gemspec +23 -16
- data/doc/_layouts/default.html +0 -2
- data/doc/contributing.textile +47 -0
- data/doc/download.textile +24 -0
- data/doc/index.textile +43 -23
- data/doc/languages.textile +65 -6
- data/doc/more_stuff.textile +12 -0
- data/doc/packaging.textile +2 -0
- data/doc/settings_profiles.textile +1 -1
- data/lib/buildr.rb +0 -4
- data/lib/buildr/core/application.rb +41 -8
- data/lib/buildr/core/build.rb +102 -1
- data/lib/buildr/core/cc.rb +14 -8
- data/lib/buildr/core/generate.rb +148 -7
- data/lib/buildr/core/util.rb +3 -3
- data/lib/buildr/ide/eclipse.rb +114 -0
- data/lib/buildr/ide/idea.rb +95 -1
- data/lib/buildr/java/commands.rb +1 -1
- data/lib/buildr/java/rjb.rb +5 -4
- data/lib/buildr/packaging/artifact.rb +1 -1
- data/lib/buildr/packaging/ziptask.rb +2 -2
- data/lib/buildr/scala.rb +1 -1
- data/lib/buildr/scala/bdd.rb +9 -2
- data/lib/buildr/scala/compiler.rb +94 -4
- data/lib/buildr/scala/doc.rb +17 -5
- data/lib/buildr/scala/tests.rb +15 -4
- data/lib/buildr/version.rb +1 -1
- data/rakelib/all-in-one.rake +50 -47
- data/rakelib/checks.rake +4 -4
- data/rakelib/doc.rake +85 -88
- data/rakelib/metrics.rake +9 -9
- data/rakelib/package.rake +13 -34
- data/rakelib/release.rake +11 -12
- data/rakelib/rspec.rake +71 -76
- data/rakelib/stage.rake +25 -51
- data/spec/addon/bnd_spec.rb +61 -7
- data/spec/core/build_spec.rb +117 -0
- data/spec/core/cc_spec.rb +36 -22
- data/spec/core/common_spec.rb +3 -2
- data/spec/core/compile_spec.rb +3 -3
- data/spec/core/generate_from_eclipse_spec.rb +280 -0
- data/spec/java/bdd_spec.rb +2 -2
- data/spec/java/packaging_spec.rb +2 -1
- data/spec/packaging/archive_spec.rb +25 -2
- data/spec/packaging/artifact_spec.rb +2 -2
- data/spec/sandbox.rb +3 -2
- data/spec/scala/compiler_spec.rb +41 -0
- data/spec/scala/doc_spec.rb +22 -3
- data/spec/scala/scala.rb +2 -2
- data/spec/scala/tests_spec.rb +2 -2
- metadata +223 -194
- data/addon/buildr/jdepend.rb.orig +0 -178
- data/doc/installing.textile.orig +0 -282
- data/doc/more_stuff.textile.orig +0 -1004
- data/lib/buildr/ide/eclipse/java.rb +0 -49
- data/lib/buildr/ide/eclipse/plugin.rb +0 -67
- data/lib/buildr/ide/eclipse/scala.rb +0 -64
data/doc/more_stuff.textile.orig
DELETED
@@ -1,1004 +0,0 @@
|
|
1
|
-
---
|
2
|
-
layout: default
|
3
|
-
title: More Stuff
|
4
|
-
---
|
5
|
-
|
6
|
-
h2(#shell). Interactive Shells (REPLs)
|
7
|
-
|
8
|
-
Many languages (including Scala and Groovy) provide an interactive shell tool which allows developers to run arbitrary expressions and see the results immediately:
|
9
|
-
|
10
|
-
<pre>$ scala
|
11
|
-
Welcome to Scala version 2.7.4.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_03-p3).
|
12
|
-
Type in expressions to have them evaluated.
|
13
|
-
Type :help for more information.
|
14
|
-
|
15
|
-
scala> 6 * 7
|
16
|
-
res0: Int = 42
|
17
|
-
|
18
|
-
scala> </pre>
|
19
|
-
|
20
|
-
These tools are alternatively known as "REPLs" (Read, Eval, Print Loop), a term which originally comes from Lisp. This sort of interactive shell can be an invaluable asset when developing frameworks or other non-UI-oriented modules. A common use-case is running a quick, manual test to make sure that the framework is functioning properly. It is faster and easier to do this in a shell, and also averts the need for extra test cases to be developed just to check simple things during development.
|
21
|
-
|
22
|
-
Unfortunately, for such a tool to be useful in Java, Scala or Groovy development, it must have access to the @CLASSPATH@, not only the compiled project binaries, but also its full list of dependencies. While it is usually possible with such tools to specify the classpath upon startup (e.g. the @-cp@ switch for the Scala shell), this can get extremely tedious for project's with more dependencies, especially when some of these dependencies are defined using @transitive@ artifacts.
|
23
|
-
|
24
|
-
Buildr is capable of easing this workflow by providing full support for the configuration and launch of interactive shells, the relevant shell may be launched simply by invoking the @shell@ task:
|
25
|
-
|
26
|
-
{% highlight sh %}
|
27
|
-
$ buildr shell
|
28
|
-
{% endhighlight %}
|
29
|
-
|
30
|
-
The @shell@ task depends upon @compile@, meaning that any changed source files will be recompiled prior to the shell's launch. Tests will not be run, nor will test files be recompiled. From within the shell itself, you should have access to your project's compilation classpath (anything specified using @compile.with@) as well as the compiled sources for your project.
|
31
|
-
|
32
|
-
The project classpath is determined by checking the current working directory of your system shell (the path from which the @buildr shell@ command was invoked) and recursively finding the relevant project for that directory. Thus, if you have a parent project @foo@ which has sub-projects @bar@ and @baz@, you may invoke an interactive shell for the @baz@ project simply by @cd@-ing into its project directory (or any of its sub-directories) and invoking the @shell@ task. You may also invoke a shell against a specific project by giving its fully-qualified descriptor as a prefix to the @shell@ task:
|
33
|
-
|
34
|
-
{% highlight sh %}
|
35
|
-
$ buildr foo:bar:shell
|
36
|
-
{% endhighlight %}
|
37
|
-
|
38
|
-
h3. Supported Shells
|
39
|
-
|
40
|
-
By default, Buildr will open the interactive shell which corresponds to your project's language. Thus, if your project is using Groovy, it will invoke the @groovysh@ command, configured with the appropriate classpath. If your project is using Scala, then the @shell@ task will invoke the @scala@ command. Unfortunately, the Java language does not define an interactive shell of any kind, however for those projects using exclusively the Java language, Buildr will use the "BeanShell":http://www.beanshell.org/manual/quickstart.html#The_BeanShell_GUI console.
|
41
|
-
|
42
|
-
However, you may still wish to exploit the advantages of an interactive shell from some other JVM language even while working in Java. Alternatively, you may want to use some shell other than the default even when working in a language which has its own. There are two ways to acheive this aim. The quickest way is to explicitly specify the relevant shell at the call-site:
|
43
|
-
|
44
|
-
{% highlight sh %}
|
45
|
-
$ buildr foo:shell:jirb
|
46
|
-
{% endhighlight %}
|
47
|
-
|
48
|
-
This will open the JIRB shell (the JRuby REPL) for the @foo@ project. Whenever you are specifying a shell explicitly in this fashion, you *must* fully-qualify the project name:
|
49
|
-
|
50
|
-
{% highlight sh %}
|
51
|
-
$ buildr shell:jirb # wrong!!
|
52
|
-
{% endhighlight %}
|
53
|
-
|
54
|
-
The above will fail because of the way that Rake tasks are dispatched.
|
55
|
-
|
56
|
-
Obviously, this explicit specification is a little bit clunky. It would be much easier if we could simply say that we *always* want to use the JIRB shell for this particular project. This can be done by using the @shell.using@ directive within your project definition:
|
57
|
-
|
58
|
-
{% highlight ruby %}
|
59
|
-
define 'foo' do
|
60
|
-
shell.using :jirb
|
61
|
-
end
|
62
|
-
{% endhighlight %}
|
63
|
-
|
64
|
-
With this project definition, we can now invoke the @shell@ task and JIRB will be launched, regardless of the default for our project's language:
|
65
|
-
|
66
|
-
{% highlight sh %}
|
67
|
-
$ buildr shell
|
68
|
-
{% endhighlight %}
|
69
|
-
|
70
|
-
Buildr supports several different shell providers, and the framework is flexible enough that additional support can be added almost trivially. The following table gives the complete list of supported shells, their corresponding @shell.using@ descriptor and the language for which they are the default (if applicable):
|
71
|
-
|
72
|
-
|_. Shell Name |_. Descriptor |_. Language |
|
73
|
-
| BeanShell Console | @:bsh@ | Java |
|
74
|
-
| Clojure REPL | @:clj@ | *N/A* |
|
75
|
-
| GroovySH | @:groovysh@ | Groovy |
|
76
|
-
| JRuby IRB | @:jirb@ | *N/A* |
|
77
|
-
| Scala Interpreter | @:scala@ | Scala |
|
78
|
-
|
79
|
-
Note that some of these shells impose certain requirements to enable use. The Groovy shell requires the @GROOVY_HOME@ environment variable to point to the Groovy install path. The Clojure REPL makes a similar requirement of @CLOJURE_HOME@. The JRuby and Scala shells will use @JRUBY_HOME@ and @SCALA_HOME@ respectively if they are defined. However, if these environment variables are not defined, the relevant JAR files will be automatically downloaded from the appropriate Maven2 repository.
|
80
|
-
|
81
|
-
h3. Verbosity and Tracing
|
82
|
-
|
83
|
-
By default, Buildr is moderately verbose, meaning that it attempts to give you enough context into what's happening during the build.
|
84
|
-
|
85
|
-
It's possible to silence Buildr if you're inconvenienced by its default verbosity by issuing,
|
86
|
-
|
87
|
-
{% highlight sh %}
|
88
|
-
$ buildr --silent
|
89
|
-
{% endhighlight %}
|
90
|
-
|
91
|
-
On the other hand, if you want Buildr to give you more context in order to trace what's happening, you can use the @-t@ options:
|
92
|
-
|
93
|
-
{% highlight sh %}
|
94
|
-
$ buildr -t
|
95
|
-
{% endhighlight %}
|
96
|
-
|
97
|
-
Using @-t@ will also display backtraces if and when they occur.
|
98
|
-
|
99
|
-
Many components can be individually configured to display more output if you're debugging a specific area of your build. For instance, you could use @--trace=javac,groovyc@ to enable tracing of the Java and Groovy compilers:
|
100
|
-
|
101
|
-
{% highlight sh %}
|
102
|
-
$ buildr --trace=javac,groovyc
|
103
|
-
{% endhighlight %}
|
104
|
-
|
105
|
-
If you don't know which tracing category you need to enable or if you want a full firehose worth of traces, you can enable all traces:
|
106
|
-
|
107
|
-
{% highlight sh %}
|
108
|
-
$ buildr --trace=all
|
109
|
-
{% endhighlight %}
|
110
|
-
|
111
|
-
h3(#javarebel). JavaRebel Integration
|
112
|
-
|
113
|
-
"JavaRebel":http://www.zeroturnaround.com/javarebel is a live bytecode reloading solution by Zero Turnaround. It's a lot like the hot code reload feature found in many Java IDE debuggers (like Eclipse and IntelliJ), but capable of handling things like member addition or removal and new class definition. The tool itself is commercial and works with any JVM language, but they do offer a free license for use with Scala classes only.
|
114
|
-
|
115
|
-
If available, Buildr will use JavaRebel when configuring the launch for each interactive shell. Shells launched with JavaRebel integration will automatically receive recompiled changes on the fly without any need to restart the shell. There are some limitations to this which are specific to the shell in question, but for the most part, things Just Work.
|
116
|
-
|
117
|
-
JavaRebel auto-magical integration is done by searching for a valid JavaRebel install path in the following list of environment variables (in order):
|
118
|
-
|
119
|
-
* @REBEL_HOME@
|
120
|
-
* @JAVA_REBEL@
|
121
|
-
* @JAVAREBEL@
|
122
|
-
* @JAVAREBEL_HOME@
|
123
|
-
|
124
|
-
These environment variables may point to either the JavaRebel install directory (e.g. @~/javarebel-2.0.1@), or the JAR file itself (e.g. @~/javarebel-2.0.1/javarebel.jar@). If the path is valid, Buildr will automatically append the appropriate JVM switches to the launch configurations of each shell:
|
125
|
-
|
126
|
-
<pre>$ buildr shell
|
127
|
-
(in ~/foo, development)
|
128
|
-
Compiling foo into ~/foo/target/classes
|
129
|
-
Running java scala.tools.nsc.MainGenericRunner
|
130
|
-
|
131
|
-
#############################################################
|
132
|
-
|
133
|
-
ZeroTurnaround JavaRebel 2.0.1 (200905251513)
|
134
|
-
(c) Copyright Webmedia, Ltd, 2007-2009. All rights reserved.
|
135
|
-
|
136
|
-
This product is licensed to Daniel Spiewak
|
137
|
-
for personal use only.
|
138
|
-
|
139
|
-
#############################################################
|
140
|
-
|
141
|
-
Welcome to Scala version 2.7.4.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_03-p3).
|
142
|
-
Type in expressions to have them evaluated.
|
143
|
-
Type :help for more information.
|
144
|
-
|
145
|
-
scala> </pre>
|
146
|
-
|
147
|
-
Note that Buildr does *not* check to make sure that you have a valid JavaRebel license, so you may end up launching with JavaRebel configured but without the ability to use it (in which case, JavaRebel will print a notification).
|
148
|
-
|
149
|
-
h2(#run). Running Your Application
|
150
|
-
|
151
|
-
The @run@ task lets you easily run programs from your buildfile, such as launching your own application.
|
152
|
-
|
153
|
-
In its simplest form, you simply define the main class of your Java application,
|
154
|
-
|
155
|
-
{% highlight ruby %}
|
156
|
-
define 'my-project' do
|
157
|
-
compile.with COMMONS_IO, HTTPCLIENT
|
158
|
-
run.using :main => "org.example.Main"
|
159
|
-
end
|
160
|
-
{% endhighlight %}
|
161
|
-
|
162
|
-
And then run,
|
163
|
-
|
164
|
-
{% highlight ruby %}
|
165
|
-
~/my-project$ buildr run
|
166
|
-
{% endhighlight %}
|
167
|
-
|
168
|
-
which would launch your application using the project's compile classpath.
|
169
|
-
|
170
|
-
It's also possible to pass arguments to the JVM using the @:java_args@ option:
|
171
|
-
|
172
|
-
{% highlight ruby %}
|
173
|
-
run.using :main => "org.example.Main",
|
174
|
-
:java_args => ["-server"]
|
175
|
-
{% endhighlight %}
|
176
|
-
|
177
|
-
If your application requires arguments, you can pass in an array of values for the @:main@ option, or provide a set of system properties using @:properties@.
|
178
|
-
|
179
|
-
{% highlight ruby %}
|
180
|
-
run.using :main => ["org.example.Main", "-t", "input.txt"],
|
181
|
-
:properties => { :debug => "true" }
|
182
|
-
{% endhighlight %}
|
183
|
-
|
184
|
-
The @run@ task is a local task, which means that Buildr will automatically pick the @run@ task matching the project in the current directory. Executing the following command:
|
185
|
-
|
186
|
-
{% highlight ruby %}
|
187
|
-
~/my-project/subproject$ buildr run
|
188
|
-
{% endhighlight %}
|
189
|
-
|
190
|
-
will run the @my-project:subproject:run@ task, assuming @my-project@ is your top-level project.
|
191
|
-
|
192
|
-
Here is a summary of @run.using@ options,
|
193
|
-
|
194
|
-
|_. Option |_. Description ... |
|
195
|
-
| @:main@ | The java main class, e.g. "com.example.Main". Can also be an array if the main class requires arguments. |
|
196
|
-
| @:properties@ | A hash of system properties to be passed to java. |
|
197
|
-
| @:java_args@ | An array of additional parameters to pass to java |
|
198
|
-
| @:classpath@ | An array of additional classpath elements (i.e. artifacts, files, etc.). By default, the @run@ task automatically uses the @compile.dependencies@, @test.dependencies@ and @test.compile.target@ of your project. |
|
199
|
-
|
200
|
-
p(note). The @run@ task also detects and uses JavaRebel if it's available. See the "JavaRebel":#javarebel section for details.
|
201
|
-
|
202
|
-
h2(#gems). Using Gems
|
203
|
-
|
204
|
-
The purpose of the buildfile is to define your projects, and the various tasks and functions used for building them. Some of these are specific to your projects, others are more general in nature, and you may want to share them across projects.
|
205
|
-
|
206
|
-
There are several mechanisms for developing extensions and build features across projects which we cover in more details in the section "Extending Buildr":extending.html. Here we will talk about using extensions that are distributed in the form of RubyGems.
|
207
|
-
|
208
|
-
"RubyGems":http://rubygems.rubyforge.org provides the @gem@ command line tool that you can use to search, install, upgrade, package and distribute gems. It installs all gems into a local repository that is shared across your builds and all other Ruby applications you may have running. You can install a gem from a local file, or download and install it from any number of remote repositories.
|
209
|
-
|
210
|
-
RubyGems is preconfigured to use the "RubyForge":http://rubyforge.org repository. You'll find a large number of open source Ruby libraries there, including Buildr itself and all its dependencies. RubyForge provides a free account that you can use to host your projects and distribute your gems (you can use RubyForge strictly for distribution, as we do with Buildr).
|
211
|
-
|
212
|
-
You can also set up your own private repository and use it instead or in addition to RubyForge. Use the @gem sources@ command to add repositories, and the @gem server@ command to run a remote repository. You can see all available options by running @gem help@.
|
213
|
-
|
214
|
-
If your build depends on other gems, you will want to specify these dependencies as part of your build and check that configuration into source control. That way you can have a specific environment that will guarantee repeatable builds, whether you're building a particular version, moving between branches, or joining an existing project. Buildr will take care of installing all the necessary dependencies, which you can then manage with the @gem@ command.
|
215
|
-
|
216
|
-
Use the @build.yaml@ file to specify these dependencies (see "Build Settings":settings_profiles.html#build for more information), for example:
|
217
|
-
|
218
|
-
{% highlight yaml %}
|
219
|
-
# This project requires the following gems
|
220
|
-
gems:
|
221
|
-
# Suppose we want to notify developers when testcases fail.
|
222
|
-
- buildr-twitter-notifier-addon >=1
|
223
|
-
# we test with ruby mock objects
|
224
|
-
- mocha
|
225
|
-
- ci_reporter
|
226
|
-
{% endhighlight %}
|
227
|
-
|
228
|
-
Gems contain executable code, and for that reason Buildr will not install gems without your permission. When you run a build that includes any dependencies that are not already installed on your machine, Buildr will ask for permission before installing them. On Unix-based operating systems, you will also need sudo privileges and will be asked for your password before proceeding.
|
229
|
-
|
230
|
-
Since this step requires your input, it will only happen when running Buildr interactively from the command line. In all other cases, Buildr will fail and report the missing dependencies. If you have an automated build environment, make sure to run the build once manually to install all the necessary dependencies.
|
231
|
-
|
232
|
-
When installing a gem for the first time, Buildr will automatically look for the latest available version. You can specify a particular version number, or a set of version numbers known to work with that build. You can use equality operations to specify a range of versions, for example, @1.2.3@ to install only version 1.2.3, and @=> 1.2.3@ to install version 1.2.3 or later.
|
233
|
-
|
234
|
-
You can also specify a range up to one version bump, for example, @~> 1.2.3@ is the same as @>= 1.2.3 < 1.3.0@, and @~> 1.2@ is the same as @>= 1.2.0 < 2.0.0@. If necessary, you can exclude a particular version number, for example, @~> 1.2.3 != 1.2.7@.
|
235
|
-
|
236
|
-
Buildr will install the latest version that matches the version requirement. To keep up with newer versions, execute the @gem update@ command periodically. You can also use @gem outdated@ to determine which new versions are available.
|
237
|
-
|
238
|
-
Most gems include documentation that you can access in several forms. You can use the @ri@ command line tool to find out more about a class, module or specific method. For example:
|
239
|
-
|
240
|
-
{% highlight sh %}
|
241
|
-
$ ri Buildr::Jetty
|
242
|
-
$ ri Buildr::Jetty.start
|
243
|
-
{% endhighlight %}
|
244
|
-
|
245
|
-
You can also access documentation from a Web browser by running @gem server@ and pointing your browser to "http://localhost:8808":http://localhost:8808. Note that after installing a new gem, you will need to restart the gem server to see its documentation.
|
246
|
-
|
247
|
-
|
248
|
-
h2(#java). Using Java Libraries
|
249
|
-
|
250
|
-
Buildr runs along side a JVM, using either RJB or JRuby. The Java module allows you to access Java classes and create Java objects.
|
251
|
-
|
252
|
-
Java classes are accessed as static methods on the @Java@ module, for example:
|
253
|
-
|
254
|
-
{% highlight ruby %}
|
255
|
-
str = Java.java.lang.String.new('hai!')
|
256
|
-
str.toUpperCase
|
257
|
-
=> 'HAI!'
|
258
|
-
Java.java.lang.String.isInstance(str)
|
259
|
-
=> true
|
260
|
-
Java.com.sun.tools.javac.Main.compile(args)
|
261
|
-
{% endhighlight %}
|
262
|
-
|
263
|
-
The @classpath@ attribute allows Buildr to add JARs and directories to the classpath, for example, we use it to load Ant and various Ant tasks, code generators, test frameworks, and so forth.
|
264
|
-
|
265
|
-
When using an artifact specification, Buildr will automatically download and install the artifact before adding it to the classpath.
|
266
|
-
|
267
|
-
For example, Ant is loaded as follows:
|
268
|
-
|
269
|
-
{% highlight ruby %}
|
270
|
-
Java.classpath << 'org.apache.ant:ant:jar:1.7.0'
|
271
|
-
{% endhighlight %}
|
272
|
-
|
273
|
-
Artifacts can only be downloaded after the Buildfile has loaded, giving it a chance to specify which remote repositories to use, so adding to classpath does not by itself load any libraries. You must call @Java.load@ before accessing any Java classes to give Buildr a chance to load the libraries specified in the classpath.
|
274
|
-
|
275
|
-
When building an extension, make sure to follow these rules:
|
276
|
-
|
277
|
-
# Add to the @classpath@ when the extension is loaded (i.e. in module or class definition), so the first call to @Java.load@ anywhere in the code will include the libraries you specify.
|
278
|
-
# Call @Java.load@ once before accessing any Java classes, allowing Buildr to set up the classpath.
|
279
|
-
# Only call @Java.load@ when invoked, otherwise you may end up loading the JVM with a partial classpath, or before all remote repositories are listed.
|
280
|
-
# Check on a clean build with empty local repository.
|
281
|
-
|
282
|
-
|
283
|
-
h2(#buildr-server). BuildrServer
|
284
|
-
|
285
|
-
Buildr provides an addon that allows you start a "dRuby":http://www.ruby-doc.org/stdlib/libdoc/drb/rdoc/index.html server hosting a buildfile, so that you can later invoke tasks on it without having to load the complete buildr runtime again.
|
286
|
-
|
287
|
-
Usage:
|
288
|
-
|
289
|
-
{% highlight sh %}
|
290
|
-
buildr -r buildr/drb drb:start
|
291
|
-
{% endhighlight %}
|
292
|
-
|
293
|
-
To stop the BuildrServer simply use Ctrl+C or kill the process.
|
294
|
-
|
295
|
-
Once the server has been started you can invoke tasks using a simple script:
|
296
|
-
|
297
|
-
{% highlight ruby %}
|
298
|
-
#!/usr/bin/env ruby
|
299
|
-
require 'rubygems'
|
300
|
-
require 'buildr/drb'
|
301
|
-
Buildr::DRbApplication.run
|
302
|
-
{% endhighlight %}
|
303
|
-
|
304
|
-
Save this script as @dbuildr@, make it executable and use it to invoke tasks.
|
305
|
-
|
306
|
-
<notextile>
|
307
|
-
{% highlight sh %}
|
308
|
-
$ dbuildr clean compile
|
309
|
-
{% endhighlight %}
|
310
|
-
</notextile>
|
311
|
-
|
312
|
-
The @dbuildr@ command will start the BuildrServer if there isn't one already running. Subsequent calls to dbuildr will act as the client and invoke the tasks you provide to the server. If the buildfile has been modified it will be reloaded on the BuildrServer.
|
313
|
-
|
314
|
-
h2(#notifications). Notifications: Growl, Libnotify, Qube
|
315
|
-
|
316
|
-
Buildr support sending notifications when the build completes or fails, such as displaying the outcome message in an overlaid window on top of other applications.
|
317
|
-
|
318
|
-
For OS X users, Buildr supports "Growl":http://growl.info/ out of the box by using the Ruby Cocoa bindings.
|
319
|
-
|
320
|
-
For Debian-based Linux users, Buildr supports notifications via the "notify-send":http://manpages.ubuntu.com/manpages/gutsy/man1/notify-send.1.html command which is part of the "libnotify-bin":"http://packages.debian.org/search?keywords=libnotify-bin" package. Just make sure `notify-send` is installed and on your path is on your `PATH`.
|
321
|
-
|
322
|
-
For other platforms or if you want to notify the user differently, Buildr offers two extension points:
|
323
|
-
|
324
|
-
* @Buildr.application.on_completion@
|
325
|
-
* @Buildr.application.on_failure@
|
326
|
-
|
327
|
-
Here is an example using these extension points to send notifications using "Qube":http://launchpad.net/qube:
|
328
|
-
|
329
|
-
{% highlight ruby %}
|
330
|
-
# Send notifications using Qube
|
331
|
-
notify = lambda do |type, title, message|
|
332
|
-
param = case type
|
333
|
-
when 'completed'; '-i'
|
334
|
-
when 'failed'; '-e'
|
335
|
-
else '-i'
|
336
|
-
end
|
337
|
-
system "qube #{param} #{title.inspect} #{message.inspect}"
|
338
|
-
end
|
339
|
-
|
340
|
-
Buildr.application.on_completion do |title, message|
|
341
|
-
notify['completed', title, message]
|
342
|
-
end
|
343
|
-
Buildr.application.on_failure do |title, message, ex|
|
344
|
-
notify['failed', title, message]
|
345
|
-
end
|
346
|
-
{% endhighlight %}
|
347
|
-
|
348
|
-
You can place this code inside @buildr.rb@ in the @.buildr@ directory under your home directory.
|
349
|
-
|
350
|
-
h2(#eclipse). Eclipse
|
351
|
-
|
352
|
-
If you're using Eclipse, you can generate @.classpath@ and @.project@ from your Buildfile and use them to create a project in your workspace:
|
353
|
-
|
354
|
-
{% highlight sh %}
|
355
|
-
$ buildr eclipse
|
356
|
-
{% endhighlight %}
|
357
|
-
|
358
|
-
The @eclipse@ task will generate a @.classpath@ and @.project@ file for each of projects (and sub-project) that compiles source code. It will not generate files for other projects, for examples, projects you use strictly for packaging a distribution, or creating command line scripts, etc.
|
359
|
-
|
360
|
-
If you add a new project, change the dependencies, or make any other change to your Buildfile, just run the @eclipse@ task again to re-generate the Eclipse project files. To have your libraries' source code available in Eclipse, run the @artifacts:sources@ task.
|
361
|
-
|
362
|
-
You may explicitly specify the nature of your project, for example if you are developing an Eclipse plugin:
|
363
|
-
|
364
|
-
{% highlight ruby %}
|
365
|
-
define 'my-plugin' do
|
366
|
-
eclipse.natures :plugin
|
367
|
-
end
|
368
|
-
{% endhighlight %}
|
369
|
-
|
370
|
-
The currently supported natures are @:java@, @:scala@ and @:plugin@. Buildr will attempts to auto-detect your project type and apply the most relevant settings by default. If it doesn't or you need something special, you may also explicitly set the nature, container and builders of your project by doing:
|
371
|
-
|
372
|
-
{% highlight ruby %}
|
373
|
-
define 'custom-plugin' do
|
374
|
-
eclipse.natures 'org.eclipse.pde.PluginNature'
|
375
|
-
eclipse.classpath_containers 'org.eclipse.pde.core.requiredPlugins'
|
376
|
-
eclipse.builders ['org.eclipse.pde.ManifestBuilder', 'org.eclipse.pde.SchemaBuilder']
|
377
|
-
end
|
378
|
-
{% endhighlight %}
|
379
|
-
|
380
|
-
One more thing; these settings are inherited hierarchically so you may set them on a parent project if you want to share them across different projects.
|
381
|
-
|
382
|
-
h2(#idea). IntelliJ IDEA
|
383
|
-
|
384
|
-
If you use IntelliJ IDEA, you can generate project files by issuing:
|
385
|
-
|
386
|
-
{% highlight sh %}
|
387
|
-
$ buildr idea
|
388
|
-
{% endhighlight %}
|
389
|
-
|
390
|
-
This task will generate a @.iml@ file for every project (or subproject) and a @.ipr@ that you can directly open for the root project.
|
391
|
-
|
392
|
-
The generated project files can be removed by issuing:
|
393
|
-
|
394
|
-
{% highlight sh %}
|
395
|
-
$ buildr idea:clean
|
396
|
-
{% endhighlight %}
|
397
|
-
|
398
|
-
The idea task generates the project files based on the settings of each project and idea extension specific settings. The main and test source trees are added to the @.iml@ file for each project as are the respective resource directories. The target and report directories are excluded from the project. If the project files exist on the file system the extension will replace specific component sections in the xml with the generated component configurations.
|
399
|
-
|
400
|
-
Dependencies come in two forms. Dependencies on other projects and dependencies on external jars. Dependencies on other projects are added as module dependencies in the @.iml@ while jars are added as regular file dependencies. Dependencies are exported from the @.iml@ file if they are compile dependencies. If a artifact that matches dependency but has a classifier of 'sources' is present then it is configured as the source for the dependency. Note: Use "buildr artifacts:sources" to download the source for dependencies.
|
401
|
-
|
402
|
-
h3. Idea Specific Directives
|
403
|
-
|
404
|
-
The extension specific settings of sub-projects inherit the parent projects settings unless overwritten.
|
405
|
-
|
406
|
-
h4. Project file naming
|
407
|
-
|
408
|
-
The extension will use the last element of the projects name when generating the @.ipr@ and @.iml@ files. i.e. A project named "foo" will generate "foo.iml" and "foo.ipr" while a project named "foo:bar" will generate "bar/bar.iml" and no ipr. (The @.ipr@ project files are only generated for the base project). The name can be modified by setting the "ipr.suffix" or "iml.suffix" settings which specifies the suffix appended to the file names. The user can also override the name completely by setting "ipr.id" or "iml.id".
|
409
|
-
|
410
|
-
h5. Example: Setting id
|
411
|
-
|
412
|
-
{% highlight ruby %}
|
413
|
-
define "foo" do
|
414
|
-
ipr.id = "beep"
|
415
|
-
define "bar" do
|
416
|
-
iml.id = "baz"
|
417
|
-
end
|
418
|
-
end
|
419
|
-
{% endhighlight %}
|
420
|
-
|
421
|
-
Will generate:
|
422
|
-
|
423
|
-
<pre>
|
424
|
-
beep.ipr
|
425
|
-
foo.iml
|
426
|
-
bar/baz.iml
|
427
|
-
</pre>
|
428
|
-
|
429
|
-
h5. Example: Setting suffix
|
430
|
-
|
431
|
-
{% highlight ruby %}
|
432
|
-
define "foo" do
|
433
|
-
ipr.suffix = "-suffix1"
|
434
|
-
iml.suffix = "-suffix2"
|
435
|
-
define "bar"
|
436
|
-
end
|
437
|
-
{% endhighlight %}
|
438
|
-
|
439
|
-
Will generate:
|
440
|
-
|
441
|
-
<pre>
|
442
|
-
foo-suffix1.ipr
|
443
|
-
foo-suffix2.iml
|
444
|
-
bar/bar-suffix2.iml
|
445
|
-
</pre>
|
446
|
-
|
447
|
-
h4. Disabling project file generation
|
448
|
-
|
449
|
-
The extension will not generate an iml file for a project if the "project.no_iml" method is invoked. Generation of ipr files can be disabled by invoking the method "project.no_ipr".
|
450
|
-
|
451
|
-
h5. Example
|
452
|
-
|
453
|
-
{% highlight ruby %}
|
454
|
-
define "foo" do
|
455
|
-
project.no_ipr
|
456
|
-
define "bar" do
|
457
|
-
project.no_iml
|
458
|
-
end
|
459
|
-
end
|
460
|
-
{% endhighlight %}
|
461
|
-
|
462
|
-
Will generate:
|
463
|
-
|
464
|
-
<pre>
|
465
|
-
foo.iml
|
466
|
-
</pre>
|
467
|
-
|
468
|
-
h4. Disabling generation of content section in .iml file
|
469
|
-
|
470
|
-
The extension will not generate a content section in an iml file if the "iml.skip_content!" method is invoked. This can be useful if a project is just exporting dependencies and has no associated source code. This may also be of use in scenarios where the build is repackaging an existing jar with more meta-data or the project is just a container for other projects.
|
471
|
-
|
472
|
-
h5. Example
|
473
|
-
|
474
|
-
{% highlight ruby %}
|
475
|
-
define "foo" do
|
476
|
-
iml.skip_content!
|
477
|
-
end
|
478
|
-
{% endhighlight %}
|
479
|
-
|
480
|
-
h4. VCS Integration
|
481
|
-
|
482
|
-
The extension will attempt to guess the VCS type of the project by looking for a @.svn@ or @.git@ directory in the base projects directory. If either of these are set it will configure the component as appropriate. Otherwise the user will need to manually specify the project to one of either 'Git' or 'svn' using the ipr.vcs setting.
|
483
|
-
|
484
|
-
h5. Example
|
485
|
-
|
486
|
-
{% highlight ruby %}
|
487
|
-
define "foo" do
|
488
|
-
ipr.vcs = 'Git'
|
489
|
-
end
|
490
|
-
{% endhighlight %}
|
491
|
-
|
492
|
-
h4. Adding main, test or exclude paths to the .iml file
|
493
|
-
|
494
|
-
The extension allows you to add source paths, test source paths or add paths to the excluded set by modifying the "iml.main_source_directories", "iml.test_source_directories" or "iml.excluded_directories" settings respectively. This is only needed when the defaults inherited from project.compile or project.test are not sufficient.
|
495
|
-
|
496
|
-
h5. Example
|
497
|
-
|
498
|
-
{% highlight ruby %}
|
499
|
-
define "foo" do
|
500
|
-
# Add path for generated resources to .iml file
|
501
|
-
iml.main_source_directories << _("generated/main/resources")
|
502
|
-
|
503
|
-
# Add path for generated test resources to .iml file
|
504
|
-
iml.test_source_directories << _("generated/test/resources")
|
505
|
-
|
506
|
-
# Exclude the temp directory created during testing
|
507
|
-
iml.excluded_directories << _("tmp")
|
508
|
-
|
509
|
-
...
|
510
|
-
end
|
511
|
-
{% endhighlight %}
|
512
|
-
|
513
|
-
h4. Adding main or test dependencies to the .iml file
|
514
|
-
|
515
|
-
The extension allows you to add main or test dependencies by modifying the "iml.main_dependencies" or "iml.test_dependencies" settings respectively. This is only needed when the defaults inherited from project.compile or project.test are not sufficient. Note: These dependencies are not included on compile path when running buildr.
|
516
|
-
|
517
|
-
h5. Example
|
518
|
-
|
519
|
-
{% highlight ruby %}
|
520
|
-
define "foo" do
|
521
|
-
# Add idea specific jar dependency to .iml file
|
522
|
-
iml.main_dependencies << 'group:id:jar:1.0'
|
523
|
-
|
524
|
-
# Add idea specific test jar dependency to .iml file
|
525
|
-
iml.test_dependencies << 'group:id:jar:1.0'
|
526
|
-
...
|
527
|
-
end
|
528
|
-
{% endhighlight %}
|
529
|
-
|
530
|
-
h4. Dependency generation
|
531
|
-
|
532
|
-
A file dependency that exists in the local maven 2 repository is stored in the IML file relative to the @$MAVEN_REPOSITORY$@ environment variable (that defaults to @~/.m2/repository@). The user can override the environment variable by setting the "iml.local_repository_env_override" setting. If the dependency does not exist in to maven repository or the "iml.local_repository_env_override" setting is set to nil, then the path stored in the IML is relative to the IML file.
|
533
|
-
|
534
|
-
h5. Example: Setting local_repository_env_override
|
535
|
-
|
536
|
-
{% highlight ruby %}
|
537
|
-
define "foo" do
|
538
|
-
iml.local_repository_env_override = nil
|
539
|
-
compile.with 'group:id:jar:1.0'
|
540
|
-
end
|
541
|
-
{% endhighlight %}
|
542
|
-
|
543
|
-
Will generate a dependency with a path like:
|
544
|
-
|
545
|
-
<pre>
|
546
|
-
jar:///home/peter/.m2/repository/group/id/1.0/id-1.0.jar!/
|
547
|
-
</pre>
|
548
|
-
|
549
|
-
rather than the default
|
550
|
-
|
551
|
-
<pre>
|
552
|
-
jar://$MAVEN_REPOSITORY$/group/id/1.0/id-1.0.jar!/
|
553
|
-
</pre>
|
554
|
-
|
555
|
-
h5. Example: A dependency outside the maven repository
|
556
|
-
|
557
|
-
{% highlight ruby %}
|
558
|
-
define "foo" do
|
559
|
-
compile.with _("foos-dep.jar")
|
560
|
-
end
|
561
|
-
{% endhighlight %}
|
562
|
-
|
563
|
-
Will generate a dependency with a path like:
|
564
|
-
|
565
|
-
<pre>
|
566
|
-
jar://$MODULE_DIR$/foo-dep.jar!/
|
567
|
-
</pre>
|
568
|
-
|
569
|
-
h4. Module Facets
|
570
|
-
|
571
|
-
Facets are IDEAs mechanism for adding support for languages, tools and frameworks other than core java. A facet can be added to a project so that it can be deployed as a web application or a hibernate application. A facet can also be used t provide support for other languages such as ruby and scala. The extension makes it possible to generate @.iml@ with the appropriate facets via the "iml.add_facet" method. It should be noted that facets are NOT inherited by sub-projects.
|
572
|
-
|
573
|
-
h5. Example
|
574
|
-
|
575
|
-
This example adds the web facet to a project.
|
576
|
-
|
577
|
-
{% highlight ruby %}
|
578
|
-
define "foo" do
|
579
|
-
iml.add_facet("Web","web") do |facet|
|
580
|
-
facet.configuration do |conf|
|
581
|
-
conf.descriptors do |desc|
|
582
|
-
desc.deploymentDescriptor :name => 'web.xml',
|
583
|
-
:url => "file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml",
|
584
|
-
:optional => "false", :version => "2.4"
|
585
|
-
end
|
586
|
-
conf.webroots do |webroots|
|
587
|
-
webroots.root :url => "file://$MODULE_DIR$/src/main/webapp", :relative => "/"
|
588
|
-
end
|
589
|
-
end
|
590
|
-
end
|
591
|
-
end
|
592
|
-
{% endhighlight %}
|
593
|
-
|
594
|
-
h4. Project Configurations
|
595
|
-
|
596
|
-
Configurations are IDEAs mechanism for running or debugging the project. Shared configurations are stored in the project file. The extension makes it possible to generate an @.ipr@ with specific configurations via the "ipr.add_configuration" method.
|
597
|
-
|
598
|
-
h5. Example
|
599
|
-
|
600
|
-
This example adds a configuration to invoke a GWT application.
|
601
|
-
|
602
|
-
{% highlight ruby %}
|
603
|
-
define "foo" do
|
604
|
-
...
|
605
|
-
ipr.add_configuration("Run Contacts.html", "GWT.ConfigurationType", "GWT Configuration") do |xml|
|
606
|
-
xml.module(:name => project.iml.id)
|
607
|
-
xml.option(:name => "RUN_PAGE", :value => "Contacts.html")
|
608
|
-
xml.option(:name => "compilerParameters", :value => "-draftCompile -localWorkers 2")
|
609
|
-
xml.option(:name => "compilerMaxHeapSize", :value => "512")
|
610
|
-
|
611
|
-
xml.RunnerSettings(:RunnerId => "Run")
|
612
|
-
xml.ConfigurationWrapper(:RunnerId => "Run")
|
613
|
-
xml.method()
|
614
|
-
end
|
615
|
-
end
|
616
|
-
{% endhighlight %}
|
617
|
-
|
618
|
-
h4. Project Artifacts
|
619
|
-
|
620
|
-
IDEA can build artifacts such as jars and wars. The artifact configuration is stored in the project file. The extension makes it possible to generate an @.ipr@ with specific artifacts via the "ipr.add_artifact" method.
|
621
|
-
|
622
|
-
h5. Example
|
623
|
-
|
624
|
-
This example adds a jar artifact to the project.
|
625
|
-
|
626
|
-
{% highlight ruby %}
|
627
|
-
define "foo" do
|
628
|
-
...
|
629
|
-
ipr.add_artifact("MyFancy.jar", "jar") do |xml|
|
630
|
-
xml.tag!('output-path', project._(:artifacts, "MyFancy.jar"))
|
631
|
-
xml.element :id => "module-output", :name => "foo"
|
632
|
-
end
|
633
|
-
end
|
634
|
-
{% endhighlight %}
|
635
|
-
|
636
|
-
h4. Custom Component Sections
|
637
|
-
|
638
|
-
If the extension does not provide capability to generate configuration for a particular IDEA plugin the user can provide their own configuration data via the "ipr.add_component" or "iml.add_component" methods.
|
639
|
-
|
640
|
-
h5. Example: Adding .ipr specific component
|
641
|
-
|
642
|
-
This example changes the compiler configuration for project.
|
643
|
-
|
644
|
-
{% highlight ruby %}
|
645
|
-
define "foo" do
|
646
|
-
ipr.add_component("CompilerConfiguration") do |component|
|
647
|
-
component.option :name => 'DEFAULT_COMPILER', :value => 'Javac'
|
648
|
-
component.option :name => 'DEPLOY_AFTER_MAKE', :value => '0'
|
649
|
-
component.resourceExtensions do |xml|
|
650
|
-
xml.entry :name => '.+\.nonexistent'
|
651
|
-
end
|
652
|
-
component.wildcardResourceExtensions do |xml|
|
653
|
-
xml.entry :name => '?*.nonexistent'
|
654
|
-
end
|
655
|
-
end
|
656
|
-
end
|
657
|
-
{% endhighlight %}
|
658
|
-
|
659
|
-
h5. Example: Adding .iml specific component
|
660
|
-
|
661
|
-
This example adds the web facet to a project. Note: This overrides the facets defined by the "iml.add_facet" method.
|
662
|
-
|
663
|
-
{% highlight ruby %}
|
664
|
-
define "foo" do
|
665
|
-
iml.add_component("FacetManager") do |component|
|
666
|
-
component.facet :type => 'web', :name => 'Web' do |facet|
|
667
|
-
facet.configuration do |conf|
|
668
|
-
conf.descriptors do |desc|
|
669
|
-
desc.deploymentDescriptor :name => 'web.xml',
|
670
|
-
:url => "file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml",
|
671
|
-
:optional => "false", :version => "2.4"
|
672
|
-
end
|
673
|
-
conf.webroots do |webroots|
|
674
|
-
webroots.root :url => "file://$MODULE_DIR$/src/main/webapp", :relative => "/"
|
675
|
-
end
|
676
|
-
end
|
677
|
-
end
|
678
|
-
end
|
679
|
-
end
|
680
|
-
{% endhighlight %}
|
681
|
-
|
682
|
-
h4. Templates
|
683
|
-
|
684
|
-
The underlying project files are xml the contain elements for a number of "components". The extension will load any existing project files and replace or add any component elements that are generated by the extension. The extension also allows the user to specify a template with either "ipr.template" or "iml.template" settings. If a template is specified it will be loaded and any component elements in these documents will be merged into the base document prior to merging in generated sections. Templates are useful if you want to enforce certain configuration options (i.e. project specific code style).
|
685
|
-
|
686
|
-
h5. Example
|
687
|
-
|
688
|
-
{% highlight ruby %}
|
689
|
-
define "foo" do
|
690
|
-
ipr.template = 'project.ipr.template'
|
691
|
-
iml.template = 'module.iml.template'
|
692
|
-
end
|
693
|
-
{% endhighlight %}
|
694
|
-
|
695
|
-
h4. Groups
|
696
|
-
|
697
|
-
IDEA provides the facility to organise modules into groups. By default the extension does not do this but it can be enabled by "iml.group" setting. If that setting is set to true then the @.iml@ file will be placed in a group based on the parent projects name. If the setting is a string then that is used as the name of the group.
|
698
|
-
|
699
|
-
h5. Example
|
700
|
-
|
701
|
-
{% highlight ruby %}
|
702
|
-
define "foo" do
|
703
|
-
iml.group = true
|
704
|
-
define 'bar' do
|
705
|
-
define 'baz'
|
706
|
-
end
|
707
|
-
define 'rab' do
|
708
|
-
iml.group = "MyGroup"
|
709
|
-
end
|
710
|
-
end
|
711
|
-
{% endhighlight %}
|
712
|
-
|
713
|
-
Will place the generated .imls in the following groups:
|
714
|
-
|
715
|
-
<pre>
|
716
|
-
foo.iml => ''
|
717
|
-
bar/bar.iml => 'foo'
|
718
|
-
bar/baz/baz.iml => 'foo/bar'
|
719
|
-
rab/rab.iml => 'MyGroup'
|
720
|
-
</pre>
|
721
|
-
|
722
|
-
h4. Add Extra .iml files to .ipr
|
723
|
-
|
724
|
-
The 'ipr.extra_modules' setting makes it possible to add extra modules to the generated iml file. The setting is an array of file names relative to the base project directory.
|
725
|
-
|
726
|
-
h5. Example
|
727
|
-
|
728
|
-
{% highlight ruby %}
|
729
|
-
define "foo" do
|
730
|
-
ipr.extra_modules << 'other.iml'
|
731
|
-
ipr.extra_modules << 'other_other.iml'
|
732
|
-
end
|
733
|
-
{% endhighlight %}
|
734
|
-
|
735
|
-
Will add the 'other.iml' and 'other_other.iml' files to the @.ipr@ project files.
|
736
|
-
|
737
|
-
h4. Buildr plugin for IDEA
|
738
|
-
|
739
|
-
Also, check out the "Buildr plugin for IDEA":http://www.digitalsanctum.com/buildr-plug-in/ (IDEA 7 and later). Once installed, open your project with IDEA. If IDEA finds that you have Buildr installed and finds a buildfile in the project's directory, it will show all the tasks available for that project. To run a task, double-click it. When the task completes, IDEA will show the results in the Buildr Output window.
|
740
|
-
|
741
|
-
h2(#cobertura_emma). Cobertura, Emma
|
742
|
-
|
743
|
-
You can use "Cobertura":http://cobertura.sourceforge.net/ or "Emma":http://emma.sourceforge.net/ to instrument your code, run the tests and create a test coverage report in either HTML or XML format.
|
744
|
-
|
745
|
-
There are two main tasks for each tool, both of which generate a test coverage report in the @reports/cobertura@ (respectively @reports/emma@) directory. For example:
|
746
|
-
|
747
|
-
{% highlight sh %}
|
748
|
-
$ buildr test cobertura:html
|
749
|
-
{% endhighlight %}
|
750
|
-
|
751
|
-
As you can guess, the other tasks are @cobertura:xml@, @emma:html@ and @emma:xml@.
|
752
|
-
|
753
|
-
If you want to generate a test coverage report only for a specific project, you can do so by using the project name as prefix to the tasks.
|
754
|
-
|
755
|
-
{% highlight sh %}
|
756
|
-
$ buildr subModule:cobertura:html
|
757
|
-
{% endhighlight %}
|
758
|
-
|
759
|
-
Each project can specify which classes to include or exclude from cobertura instrumentation by giving a class-name regexp to the @cobertura.include@ or @cobertura.exclude@ methods:
|
760
|
-
|
761
|
-
{% highlight ruby %}
|
762
|
-
define 'someModule' do
|
763
|
-
cobertura.include 'some.package.==*=='
|
764
|
-
cobertura.include /some.(foo|bar).==*==/
|
765
|
-
cobertura.exclude 'some.foo.util.SimpleUtil'
|
766
|
-
cobertura.exclude /==*==.Const(ants)?/i
|
767
|
-
end
|
768
|
-
{% endhighlight %}
|
769
|
-
|
770
|
-
Emma has @include@ and @exclude@ methods too, but they take glob patterns instead of regexps.
|
771
|
-
|
772
|
-
Cobertura also provides a @cobertura:check@ task. This task is intended to be used as a dependency for other tasks (such as @deploy@) which might wish to fail if coverage is unacceptable. The respective thresholds for task failure may be defined using the @cobertura.check@ configuration namespace. For example:
|
773
|
-
|
774
|
-
{% highlight ruby %}
|
775
|
-
define 'someModule' do
|
776
|
-
cobertura.check.branch_rate = 75
|
777
|
-
cobertura.check.line_rate = 100
|
778
|
-
cobertura.check.total_line_rate = 98
|
779
|
-
|
780
|
-
task(:deploy).enhance 'cobertura:check'
|
781
|
-
end
|
782
|
-
{% endhighlight %}
|
783
|
-
|
784
|
-
The @cobertura:check@ task supports all of the configuration parameters allowed by the @cobertura-check@ Ant task (as "documented here":http://cobertura.sourceforge.net/anttaskreference.html). Configuration parameters are "Ruby-ized" (as demonstrated in the example above).
|
785
|
-
|
786
|
-
We want Buildr to load fast, and not everyone cares for these tasks, so we don't include them by default. If you want to use one of them, you need to require it explicitly. The proper way to do it in Ruby:
|
787
|
-
|
788
|
-
{% highlight ruby %}
|
789
|
-
require 'buildr/java/cobertura'
|
790
|
-
require 'buildr/java/emma'
|
791
|
-
{% endhighlight %}
|
792
|
-
|
793
|
-
You may want to add those to the Buildfile. Alternatively, you can use these tasks for all your projects without modifying the Buildfile. One convenient method is to add these lines to the @buildr.rb@ file in the @.buildr@ directory under your home directory.
|
794
|
-
|
795
|
-
Another option is to require it from the command line (@--require@ or @-r@), for example:
|
796
|
-
|
797
|
-
{% highlight sh %}
|
798
|
-
$ buildr -rbuildr/java/cobertura cobertura:html
|
799
|
-
{% endhighlight %}
|
800
|
-
|
801
|
-
h2(#checkstyle). Checkstyle
|
802
|
-
|
803
|
-
Checkstyle is integrated into Buildr through an extension. The extension adds the "checkstyle:xml" task that generates an xml report listing checkstyle violations and may add a "checkstyle:html" task if an appropriate xsl is present. A typical project that uses the extension may look something like;
|
804
|
-
|
805
|
-
{% highlight ruby %}
|
806
|
-
require 'buildr/checkstyle'
|
807
|
-
|
808
|
-
define "foo" do
|
809
|
-
project.version = "1.0.0"
|
810
|
-
|
811
|
-
define "bar" do ... end
|
812
|
-
|
813
|
-
checkstyle.config_directory = _('etc/checkstyle')
|
814
|
-
checkstyle.source_paths << project('bar')._(:source, :main, :java)
|
815
|
-
checkstyle.extra_dependencies << :javax_servlet
|
816
|
-
|
817
|
-
end
|
818
|
-
{% endhighlight %}
|
819
|
-
|
820
|
-
By default checkstyle will look for all configuration files in the src/main/etc/checkstyle directory but this can be overriden by the setting the "checkstyle.config_directory" parameter. The "checkstyle:xml" task will be defined if the checkstyle rules file is found. The rules file is typically named "checks.xml" but can be overridden by setting the "checkstyle.configuration_file" parameter. If a suppressions file or import control file is included in the directory, these will also be used by the extension. These names of these files will default to "suppressions.xml" and "import-control.xml" but these can be overriden by the parameters "checkstyle.suppressions_file" and "checkstyle.import_control_file".
|
821
|
-
|
822
|
-
The extension will include the source and test directories of the project aswell as the compile and test dependencies when invoking the checkstyle tool. These can be added to by the parameters "checkstyle.source_paths" and "checkstyle.extra_dependencies" as appropriate.
|
823
|
-
|
824
|
-
If the xsl file named "checkstyle-report.xsl" is present in the configuration directory then a "checkstyle:html" task will be defined. The name of the xsl file can be overridden by the parameter "checkstyle.style_file".
|
825
|
-
|
826
|
-
<<<<<<< HEAD
|
827
|
-
=======
|
828
|
-
h2(#findbugs). FindBugs
|
829
|
-
|
830
|
-
FindBugs is integrated into Buildr through an extension. The extension adds the "findbugs:xml" task that generates an xml report listing findbugs violations and may add a "findbugs:html" task if an appropriate xsl is present. A typical project that uses the extension may look something like;
|
831
|
-
|
832
|
-
{% highlight ruby %}
|
833
|
-
require 'buildr/findbugs'
|
834
|
-
|
835
|
-
define "foo" do
|
836
|
-
project.version = "1.0.0"
|
837
|
-
|
838
|
-
define "bar" do ... end
|
839
|
-
|
840
|
-
findbugs.config_directory = _('etc/findbugs')
|
841
|
-
findbugs.source_paths << project('bar')._(:source, :main, :java)
|
842
|
-
findbugs.analyze_paths << project('bar').compile.target
|
843
|
-
findbugs.extra_dependencies << project('bar').compile.dependencies
|
844
|
-
|
845
|
-
end
|
846
|
-
{% endhighlight %}
|
847
|
-
|
848
|
-
By default findbugs will look for all configuration files in the src/main/etc/findbugs directory but this can be overriden by the setting the "findbugs.config_directory" parameter. The "findbugs:xml" task will past FindBugs a filter xml if a file named "filter.xml" is present in the configuration directory. This can be overridden by setting the "findbugs.filter_file" parameter.
|
849
|
-
|
850
|
-
The extension will include the source and test directories of the project aswell as the compile and test dependencies when invoking the findbugs tool. These can be added to by the parameters "findbugs.source_paths" and "findbugs.extra_dependencies" as appropriate. The actual analysis is run across compiled artifacts ad this will default to the target directory of the project but this can be overriden by the "findbugs.analyze_paths" parameter.
|
851
|
-
|
852
|
-
If the xsl file named "findbugs-report.xsl" is present in the configuration directory then a "findbugs:html" task will be defined. The name of the xsl file can be overridden by the parameter "findbugs.style_file".
|
853
|
-
|
854
|
-
>>>>>>> 28deb000947f13d5df722228ed2bc24fdcb303d3
|
855
|
-
h2(#javancss). JavaNCSS
|
856
|
-
|
857
|
-
JavaNCSS is integrated into Buildr through an extension. The extension adds the "javancss:xml" task that generates an xml report and may add a "javancss:html" task if an appropriate xsl is present. A typical project that uses the extension may look something like;
|
858
|
-
|
859
|
-
{% highlight ruby %}
|
860
|
-
require 'buildr/javancss'
|
861
|
-
|
862
|
-
define "foo" do
|
863
|
-
project.version = "1.0.0"
|
864
|
-
|
865
|
-
define "bar" do ... end
|
866
|
-
|
867
|
-
javancss.enabled = true
|
868
|
-
javancss.config_directory = _('etc/javancss')
|
869
|
-
javancss.source_paths << project('bar')._(:source, :main, :java)
|
870
|
-
|
871
|
-
end
|
872
|
-
{% endhighlight %}
|
873
|
-
|
874
|
-
The extension will include the source and test directories of the project when invoking the javancss tool. These can be added to by the parameters "javancss.source_paths".
|
875
|
-
|
876
|
-
By default javancss will look for all configuration files in the src/main/etc/javancss directory but this can be overriden by the setting the "javancss.config_directory" parameter. The "javancss:xml" task will be defined if the "javancss.enabled" property is set to true. If the xsl file named "javancss2html.xsl" is present in the configuration directory then a "javancss:html" task will be defined. The name of the xsl file can be overridden by the parameter "javancss.style_file".
|
877
|
-
|
878
|
-
h2(#jdepend). JDepend
|
879
|
-
|
880
|
-
"JDepend":http://clarkware.com/software/JDepend.html is integrated into Buildr through an extension. The extension adds the "jdepend:xml" task that generates an xml report, "jdepend:swing" that shows a Swing UI, and may add a "jdepend:html" task if an appropriate xsl is present. A typical project that uses the extension may look something like;
|
881
|
-
|
882
|
-
{% highlight ruby %}
|
883
|
-
require 'buildr/jdepend'
|
884
|
-
|
885
|
-
define "foo" do
|
886
|
-
project.version = "1.0.0"
|
887
|
-
|
888
|
-
define "bar" do ... end
|
889
|
-
|
890
|
-
jdepend.enabled = true
|
891
|
-
jdepend.config_directory = _('etc/jdepend')
|
892
|
-
jdepend.target_paths << project('bar').compile.target
|
893
|
-
|
894
|
-
end
|
895
|
-
{% endhighlight %}
|
896
|
-
|
897
|
-
The extension will include the compiled source and test directories of the project when invoking the JDepend tool. These can be added to by the parameters "jdepend.target_paths".
|
898
|
-
|
899
|
-
By default JDepend will look for all configuration files in the src/main/etc/jdepend directory but this can be overriden by the setting the "jdepend.config_directory" parameter. The "jdepend:xml" and "jdepend:swing" task will be defined if the "jdepend.enabled" property is set to true. If a "jdepend.properties" is included in the configuration directory then jdepend will load it during the analysis. If the xsl file named "jdepend.xsl" is present in the configuration directory then a "jdepend:html" task will be defined. The name of the xsl file can be overridden by the parameter "jdepend.style_file".
|
900
|
-
|
901
|
-
h2(#pmd). PMD
|
902
|
-
|
903
|
-
PMD is integrated into Buildr through an extension. The extension adds the "pmd:rule:xml" and "pmd:rule:html" tasks. A typical project that uses the extension may look something like;
|
904
|
-
|
905
|
-
|
906
|
-
{% highlight ruby %}
|
907
|
-
require 'buildr/javancss'
|
908
|
-
|
909
|
-
define "foo" do
|
910
|
-
project.version = "1.0.0"
|
911
|
-
|
912
|
-
define "bar" do ... end
|
913
|
-
|
914
|
-
pmd.enabled = true
|
915
|
-
pmd.rule_set_paths = _('etc/pmd') + "/"
|
916
|
-
pmd.source_paths << project('bar')._(:source, :main, :java)
|
917
|
-
pmd.rule_set_files = ['basic','imports','unusedcode','logging-java','finalizers']
|
918
|
-
|
919
|
-
end
|
920
|
-
{% endhighlight %}
|
921
|
-
|
922
|
-
The "pmd:rule:xml" task will be defined if the "pmd.enabled" property is set to true.
|
923
|
-
|
924
|
-
The extension will include the source and test directories of the project when invoking the pmd tool. These can be added to by the parameters "pmd.source_paths".
|
925
|
-
|
926
|
-
By default the pmd rule files 'basic','imports' and 'unusedcode' will be evaluated but this can be overriden by the "pmd.rule_set_files" parameter. The rule sets will be loaded from the classpath and this can be added to by modifying the "pmd.rule_set_paths" parameter.
|
927
|
-
|
928
|
-
h2(#jaxb_xjc). JAXB Xjc Compiler
|
929
|
-
|
930
|
-
Buildr includes an extension that provides the ability to invoke jaxb xjc binding compiler. A typical project that uses the extension may look something like;
|
931
|
-
|
932
|
-
{% highlight ruby %}
|
933
|
-
require 'buildr/jaxb_xjc'
|
934
|
-
|
935
|
-
define "foo" do
|
936
|
-
project.version = "1.0.0"
|
937
|
-
compile.from compile_jaxb(_('src/schemas/wildfire-1.3.xsd'),
|
938
|
-
"-quiet",
|
939
|
-
:package => "org.foo.api")
|
940
|
-
package :jar
|
941
|
-
end
|
942
|
-
{% endhighlight %}
|
943
|
-
|
944
|
-
The method compile_jaxb accepts either an array of files or a single file as the first parameter. It then accepts 0 or more arguments that are passed to the underlying XJC compiler. The arguments are documented on the "jaxb site":https://jaxb.dev.java.net/nonav/2.2.1/docs/xjc.html. If the last argument is an options hash then the extension handles the options hash specially. The supported options include:
|
945
|
-
|
946
|
-
* <tt>:directory</tt>: The directory to which source is generated. Defaults to <tt>_(:target, :generated, :jaxb)</tt>
|
947
|
-
* <tt>:keep_content</tt>: By default the generated directory will be deleted. If <tt>true</tt> is specified for this parameter the directory will not be deleted.
|
948
|
-
* <tt>:package</tt>: The package in which the source is generated.
|
949
|
-
|
950
|
-
h2(#anything_ruby). Anything Ruby Can Do
|
951
|
-
|
952
|
-
Buildr is Ruby code. That's an implementation detail for some, but a useful features for others. You can use Ruby to keep your build scripts simple and DRY, tackle ad hoc tasks and write reusable features without the complexity of "plugins".
|
953
|
-
|
954
|
-
We already showed you one example where Ruby could help. You can use Ruby to manage dependency by setting constants and reusing them, grouping related dependencies into arrays and structures.
|
955
|
-
|
956
|
-
You can use Ruby to perform ad hoc tasks. For example, Buildr doesn't have any pre-canned task for setting file permissions. But Ruby has a method for that, so it's just a matter of writing a task:
|
957
|
-
|
958
|
-
{% highlight ruby %}
|
959
|
-
bins = file('target/bin'=>FileList[_('src/main/dist/bin/==*==')]) do |task|
|
960
|
-
mkpath task.name
|
961
|
-
cp task.prerequisites, task.name
|
962
|
-
chmod 0755, FileList[task.name + '/==*==.sh'], :verbose=>false
|
963
|
-
end
|
964
|
-
{% endhighlight %}
|
965
|
-
|
966
|
-
You can use functions to keep your code simple. For example, in the ODE project we create two binary distributions, both of which contain a common set of files, and one additional file unique to each distribution. We use a method to define the common distribution:
|
967
|
-
|
968
|
-
{% highlight ruby %}
|
969
|
-
def distro(project, id)
|
970
|
-
project.package(:zip, :id=>id).path("#{id}-#{version}").tap do |zip|
|
971
|
-
zip.include meta_inf + ['RELEASE_NOTES', 'README'].map { |f| path_to(f) }
|
972
|
-
zip.path('examples').include project.path_to('src/examples'), :as=>'.'
|
973
|
-
zip.merge project('ode:tools-bin').package(:zip)
|
974
|
-
zip.path('lib').include artifacts(COMMONS.logging, COMMONS.codec,
|
975
|
-
COMMONS.httpclient, COMMONS.pool, COMMONS.collections, JAXEN, SAXON,
|
976
|
-
LOG4J, WSDL4J, XALAN, XERCES)
|
977
|
-
project('ode').projects('utils', 'tools', 'bpel-compiler', 'bpel-api',
|
978
|
-
'bpel-obj', 'bpel-schemas').map(&:packages).flatten.each do |pkg|
|
979
|
-
zip.include(pkg.to_s, :as=>"#{pkg.id}.#{pkg.type}", :path=>'lib')
|
980
|
-
end
|
981
|
-
yield zip
|
982
|
-
end
|
983
|
-
end
|
984
|
-
{% endhighlight %}
|
985
|
-
|
986
|
-
And then use it in the project definition:
|
987
|
-
|
988
|
-
{% highlight ruby %}
|
989
|
-
define 'distro-axis2' do
|
990
|
-
parent.distro(self, "#{parent.id}-war") { |zip|
|
991
|
-
zip.include project('ode:axis2-war').package(:war), :as=>'ode.war' }
|
992
|
-
end
|
993
|
-
{% endhighlight %}
|
994
|
-
|
995
|
-
Ruby's functional style and blocks make some task extremely easy. For example, let's say we wanted to count how many source files we have, and total number of lines:
|
996
|
-
|
997
|
-
{% highlight ruby %}
|
998
|
-
sources = projects.map { |prj| prj.compile.sources.
|
999
|
-
map { |src| FileList["#{src}/**/*.java"] } }.flatten
|
1000
|
-
puts "There are #{source.size} source files"
|
1001
|
-
lines = sources.inject(0) { |lines, src| lines += File.readlines(src).size }
|
1002
|
-
puts "That contain #{lines} lines"
|
1003
|
-
{% endhighlight %}
|
1004
|
-
|