buildr 1.2.10 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. data/CHANGELOG +566 -268
  2. data/DISCLAIMER +7 -1
  3. data/KEYS +151 -0
  4. data/NOTICE +23 -8
  5. data/README +122 -22
  6. data/Rakefile +49 -229
  7. data/{lib → addon}/buildr/antlr.rb +23 -10
  8. data/addon/buildr/cobertura.rb +232 -0
  9. data/{lib → addon}/buildr/hibernate.rb +20 -4
  10. data/{lib → addon}/buildr/javacc.rb +27 -12
  11. data/addon/buildr/jdepend.rb +60 -0
  12. data/{lib → addon}/buildr/jetty.rb +34 -18
  13. data/addon/buildr/nailgun.rb +892 -0
  14. data/{lib → addon}/buildr/openjpa.rb +23 -6
  15. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  16. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  17. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  18. data/{lib/buildr/jetty → addon/buildr/org/apache/buildr}/JettyWrapper.java +19 -0
  19. data/{lib → addon}/buildr/xmlbeans.rb +39 -14
  20. data/bin/buildr +21 -7
  21. data/buildr.gemspec +50 -0
  22. data/doc/css/default.css +225 -0
  23. data/doc/css/print.css +95 -0
  24. data/doc/css/syntax.css +43 -0
  25. data/doc/images/apache-incubator-logo.png +0 -0
  26. data/doc/images/buildr-hires.png +0 -0
  27. data/doc/images/buildr.png +0 -0
  28. data/doc/images/note.png +0 -0
  29. data/doc/images/tip.png +0 -0
  30. data/doc/images/zbuildr.tif +0 -0
  31. data/doc/pages/artifacts.textile +317 -0
  32. data/doc/pages/building.textile +501 -0
  33. data/doc/pages/contributing.textile +178 -0
  34. data/doc/pages/download.textile +25 -0
  35. data/doc/pages/extending.textile +229 -0
  36. data/doc/pages/getting_started.textile +337 -0
  37. data/doc/pages/index.textile +63 -0
  38. data/doc/pages/mailing_lists.textile +17 -0
  39. data/doc/pages/more_stuff.textile +367 -0
  40. data/doc/pages/packaging.textile +592 -0
  41. data/doc/pages/projects.textile +449 -0
  42. data/doc/pages/recipes.textile +127 -0
  43. data/doc/pages/settings_profiles.textile +339 -0
  44. data/doc/pages/testing.textile +475 -0
  45. data/doc/pages/troubleshooting.textile +121 -0
  46. data/doc/pages/whats_new.textile +389 -0
  47. data/doc/print.haml +52 -0
  48. data/doc/print.toc.yaml +28 -0
  49. data/doc/scripts/buildr-git.rb +411 -0
  50. data/doc/scripts/install-jruby.sh +44 -0
  51. data/doc/scripts/install-linux.sh +64 -0
  52. data/doc/scripts/install-osx.sh +52 -0
  53. data/doc/site.haml +55 -0
  54. data/doc/site.toc.yaml +44 -0
  55. data/lib/buildr.rb +28 -45
  56. data/lib/buildr/core.rb +27 -0
  57. data/lib/buildr/core/application.rb +373 -0
  58. data/lib/buildr/core/application_cli.rb +134 -0
  59. data/lib/{core → buildr/core}/build.rb +91 -77
  60. data/lib/{core → buildr/core}/checks.rb +116 -95
  61. data/lib/buildr/core/common.rb +155 -0
  62. data/lib/buildr/core/compile.rb +594 -0
  63. data/lib/buildr/core/environment.rb +120 -0
  64. data/lib/buildr/core/filter.rb +258 -0
  65. data/lib/{core → buildr/core}/generate.rb +22 -5
  66. data/lib/buildr/core/help.rb +118 -0
  67. data/lib/buildr/core/progressbar.rb +156 -0
  68. data/lib/{core → buildr/core}/project.rb +468 -213
  69. data/lib/buildr/core/test.rb +690 -0
  70. data/lib/{core → buildr/core}/transports.rb +107 -127
  71. data/lib/buildr/core/util.rb +235 -0
  72. data/lib/buildr/ide.rb +19 -0
  73. data/lib/{java → buildr/ide}/eclipse.rb +86 -60
  74. data/lib/{java → buildr/ide}/idea.ipr.template +16 -0
  75. data/lib/buildr/ide/idea.rb +194 -0
  76. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  77. data/lib/buildr/ide/idea7x.rb +210 -0
  78. data/lib/buildr/java.rb +26 -0
  79. data/lib/buildr/java/ant.rb +71 -0
  80. data/lib/buildr/java/bdd_frameworks.rb +267 -0
  81. data/lib/buildr/java/commands.rb +210 -0
  82. data/lib/buildr/java/compilers.rb +432 -0
  83. data/lib/buildr/java/deprecated.rb +141 -0
  84. data/lib/buildr/java/groovyc.rb +137 -0
  85. data/lib/buildr/java/jruby.rb +99 -0
  86. data/lib/buildr/java/org/apache/buildr/BuildrNail$Main.class +0 -0
  87. data/lib/buildr/java/org/apache/buildr/BuildrNail.class +0 -0
  88. data/lib/buildr/java/org/apache/buildr/BuildrNail.java +41 -0
  89. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  90. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +116 -0
  91. data/lib/buildr/java/packaging.rb +706 -0
  92. data/lib/{java → buildr/java}/pom.rb +20 -4
  93. data/lib/buildr/java/rjb.rb +142 -0
  94. data/lib/buildr/java/test_frameworks.rb +290 -0
  95. data/lib/buildr/java/version_requirement.rb +172 -0
  96. data/lib/buildr/packaging.rb +21 -0
  97. data/lib/{java → buildr/packaging}/artifact.rb +170 -179
  98. data/lib/buildr/packaging/artifact_namespace.rb +957 -0
  99. data/lib/buildr/packaging/artifact_search.rb +140 -0
  100. data/lib/buildr/packaging/gems.rb +102 -0
  101. data/lib/buildr/packaging/package.rb +233 -0
  102. data/lib/{tasks → buildr/packaging}/tar.rb +18 -1
  103. data/lib/{tasks → buildr/packaging}/zip.rb +153 -105
  104. data/rakelib/apache.rake +126 -0
  105. data/rakelib/changelog.rake +56 -0
  106. data/rakelib/doc.rake +103 -0
  107. data/rakelib/package.rake +44 -0
  108. data/rakelib/release.rake +53 -0
  109. data/rakelib/rspec.rake +81 -0
  110. data/rakelib/rubyforge.rake +45 -0
  111. data/rakelib/scm.rake +49 -0
  112. data/rakelib/setup.rake +59 -0
  113. data/rakelib/stage.rake +45 -0
  114. data/spec/application_spec.rb +316 -0
  115. data/spec/archive_spec.rb +494 -0
  116. data/spec/artifact_namespace_spec.rb +635 -0
  117. data/spec/artifact_spec.rb +738 -0
  118. data/spec/build_spec.rb +193 -0
  119. data/spec/checks_spec.rb +537 -0
  120. data/spec/common_spec.rb +579 -0
  121. data/spec/compile_spec.rb +561 -0
  122. data/spec/groovy_compilers_spec.rb +239 -0
  123. data/spec/java_bdd_frameworks_spec.rb +238 -0
  124. data/spec/java_compilers_spec.rb +446 -0
  125. data/spec/java_packaging_spec.rb +1042 -0
  126. data/spec/java_test_frameworks_spec.rb +414 -0
  127. data/spec/packaging_helper.rb +63 -0
  128. data/spec/packaging_spec.rb +589 -0
  129. data/spec/project_spec.rb +739 -0
  130. data/spec/sandbox.rb +116 -0
  131. data/spec/scala_compilers_spec.rb +239 -0
  132. data/spec/spec.opts +6 -0
  133. data/spec/spec_helpers.rb +283 -0
  134. data/spec/test_spec.rb +871 -0
  135. data/spec/transport_spec.rb +300 -0
  136. data/spec/version_requirement_spec.rb +115 -0
  137. metadata +188 -77
  138. data/lib/buildr/cobertura.rb +0 -89
  139. data/lib/buildr/jdepend.rb +0 -40
  140. data/lib/buildr/jetty/JettyWrapper$1.class +0 -0
  141. data/lib/buildr/jetty/JettyWrapper$BuildrHandler.class +0 -0
  142. data/lib/buildr/jetty/JettyWrapper.class +0 -0
  143. data/lib/buildr/scala.rb +0 -368
  144. data/lib/core/application.rb +0 -188
  145. data/lib/core/common.rb +0 -562
  146. data/lib/core/help.rb +0 -72
  147. data/lib/core/rake_ext.rb +0 -81
  148. data/lib/java/ant.rb +0 -71
  149. data/lib/java/compile.rb +0 -589
  150. data/lib/java/idea.rb +0 -159
  151. data/lib/java/java.rb +0 -432
  152. data/lib/java/packaging.rb +0 -581
  153. data/lib/java/test.rb +0 -795
  154. data/lib/tasks/concat.rb +0 -35
@@ -0,0 +1,501 @@
1
+ h1. Building
2
+
3
+ To remove any confusion, Buildr's build task is actually called @build@. It's
4
+ also the default task that executes when you run @buildr@ without any task
5
+ name.
6
+
7
+ The @build@ task runs two other tasks: @compile@ and its associated tasks (that
8
+ would be, @resources@) and @test@ and its associated tasks (@test:compile@,
9
+ @test:setup@ and friends). We'll talk about @compile@ more in this section,
10
+ and @test@ later on. We'll also show you how to run @build@ without testing,
11
+ not something we recommend, but a necessary feature.
12
+
13
+ Why @build@ and not @compile@? Some projects do more than just compiling.
14
+ Other projects don't compile at all, but perform other build tasks, for
15
+ example, creating a database schema or command line scripts. So we want you to
16
+ get in the practice of running the @build@ task, and help you by making it the
17
+ default task.
18
+
19
+
20
+ h2. Compiling
21
+
22
+ Each project has its own @compile@ task you can invoke directly, by running
23
+ @buildr compile@ or as part of another build task. (Yes, that @build@).
24
+
25
+ The @compile@ task looks for source files in well known directories, determines
26
+ which compiler to use, and sets the target directory accordingly. For example,
27
+ if it finds any Java source files in the @src/main/java@ directory, it selects
28
+ the Javac compiler and generates bytecode in the @target/classes@ directories.
29
+ If it finds Scala source files in the @src/main/scala@ directory it selects the
30
+ Scalac compiler, and so forth.
31
+ A single project cannot use multiple compilers at the same time, hence you may
32
+ prefer creating subprojects by programming language.
33
+ Some compilers like Groovy's are joint-compilers, this means they can handle
34
+ several languages. When the Groovy compiler is selected for a project, .groovy
35
+ and .java files are compiled by groovyc.
36
+
37
+ Most often, that's just good enough and the only change you need to make is
38
+ adding compile dependencies. You can use @compile.dependencies@ to get the
39
+ array of dependency file tasks. For Java, each of these tasks points to a JAR
40
+ or a directory containing Java classes, and the entire set of dependencies is
41
+ passed to Javac as the classpath.
42
+
43
+ Buildr uses file tasks to handle dependencies, but here we're talking about the
44
+ Rake dependency mechanism. It's a double entendre. It invokes these tasks
45
+ before running the compiler. Some of these tasks will download JARs from
46
+ remote repositories, others will create them by compiling and packaging from a
47
+ different project. Using file task ensures all the dependencies exist before
48
+ the compiler can use them.
49
+
50
+ An easier way to specify dependencies is by calling the @compile.with@ method.
51
+ It takes a list of arguments and adds them to the dependency list. The
52
+ @compile.with@ method is easier to use, it accepts several type of
53
+ dependencies. You can use file names, file tasks, projects, artifacts
54
+ specifications and even pass arrays of dependencies.
55
+
56
+ Most dependencies fall into the last three categories. When you pass a project
57
+ to @compile.with@, it picks up all the packages created by that project. In
58
+ doing so, it establishes an order of dependency between the two projects (see
59
+ "Defining the Project":projects.html#defining_the_project). For example, if
60
+ you make a change in project _teh-api_ and build _teh-impl_, Buildr will detect
61
+ that change, recompile and package _teh-api_ before compiling _teh-impl_. You
62
+ can also select a specific package using the @package@ or @packages@ methods
63
+ (see "Packaging":packaging.html).
64
+
65
+ When you pass an artifact specification to @compile.with@, it creates an
66
+ @Artifact@ task that will download that artifact from one of the remote
67
+ repositories, install it in the local repository, and use it in your project.
68
+ Rake's dependency mechanism is used here to make sure the artifact is
69
+ downloaded once, when needed. Check the "Artifacts":artifacts.html section for
70
+ more information about artifact specification and repositories.
71
+
72
+ For now let's just show a simple example:
73
+
74
+ {{{!ruby
75
+ compile.with 'org.apache.axis2:axis2:jar:1.2',
76
+ 'org.apache.derby:derby:jar:10.1.2.1', projects('teh-api', 'teh-impl')
77
+ }}}
78
+
79
+ Passing arrays to @compile.with@ is just a convenient for handling multiple
80
+ dependencies, we'll show more examples of that when we talk about
81
+ "Artifacts":#artifacts.
82
+
83
+ Likewise, the @compile@ task has an array of file tasks that point at the
84
+ source directories you want to compile from. You can access that array by
85
+ calling @compile.sources@. You can use @compile.from@ to add new source
86
+ directories by passing a file name or a file task.
87
+
88
+ For example, let's run the APT tool on our annotated source code before
89
+ compiling it:
90
+
91
+ {{{!ruby
92
+ compile.from apt
93
+ }}}
94
+
95
+ When you call @apt@ on a project, it returns a file task that points to the
96
+ @target/generated/apt@ directory. This file task executes by running APT,
97
+ using the same list of source directories, dependencies and compiler options.
98
+ It then generates new source files in the target directory. Calling
99
+ @compile.from@ with that file task includes those additional source files in
100
+ the list of compiled sources.
101
+
102
+ Here's another example:
103
+
104
+ {{{!ruby
105
+ jjtree = jjtree(_('src/main/jjtree'), :in_package=>'com.acme')
106
+ compile.from javacc(jjtree, :in_package=>'com.acme'), jjtree
107
+ }}}
108
+
109
+ This time, the variable @jjtree@ is a file task that reads a JJTree source file
110
+ from the @src/main/jjtree@ directory, and generates additional source files in
111
+ the @target/generated/jjtree@ directory. The second line creates another file
112
+ task that takes those source files, runs JavaCC on them, and generates yet more
113
+ source files in @target/generated/javacc@. Finally, we include both sets of
114
+ source files in addition to those already in @src/main/java@, and compile the
115
+ lot.
116
+
117
+ The interesting thing about these two examples is how you're wiring file tasks
118
+ together to create more complicated tasks, piping the output of one task into
119
+ the inputs of another. Wiring tasks this way is the most common way to handle
120
+ complex builds, and uses Rake's dependency mechanism to only run tasks when it
121
+ detects a change to one of the source files.
122
+
123
+ You can also control the target directory. Use @compile.target@ to get the
124
+ target directory file task. If you need to change the target directory, call
125
+ the @compile.into@ method with the new path.
126
+
127
+ We use method pairs to give you finer control over the compiler, but also a way
128
+ to easily configure it. Methods like @dependencies@ and @sources@ give you a
129
+ live array you can manipulate, or iterate over. On the other hand, methods
130
+ like @with@ and @from@ accept a wider set of arguments and clean them up for
131
+ you. They also all return the same task you're calling, so you can chain
132
+ methods together.
133
+
134
+ For example:
135
+
136
+ {{{!ruby
137
+ compile.from('srcs').with('org.apache.axis2:axis2:jar:1.2').
138
+ into('classes').using(:target=>'1.4')
139
+ }}}
140
+
141
+ Buildr uses the method pair and method chaining idiom in many places to make
142
+ your life easier without sacrificing flexibility.
143
+
144
+ Occasionally, you'll need to post-process the generated bytecode. Since you
145
+ only want to do that after compiling, and let the compiler decide when to do
146
+ that – only when changes require re-compiling – you'll want to extend the
147
+ @compile@ task. You can do that by calling @compile@ with a block.
148
+
149
+ For example, to run the OpenJPA bytecode enhancer after compiling the source
150
+ files:
151
+
152
+ {{{!ruby
153
+ compile { open_jpa_enhance }
154
+ }}}
155
+
156
+ You can change various compile options by calling, you guessed,
157
+ @compile.options@. For example, to set the compiler to VM compatibility with
158
+ Java 1.5 and turn on all Lint messages:
159
+
160
+ {{{!ruby
161
+ compile.options.target = '1.5'
162
+ compile.options.lint = 'all'
163
+ }}}
164
+
165
+ Or, if you want to chain methods together:
166
+
167
+ {{{!ruby
168
+ compile.using :target=>'1.5', :lint=>'all'
169
+ }}}
170
+
171
+ Sub-projects inherit compile options from their parent project, so you only
172
+ need to change these settings once in the top project. You can do so, even if
173
+ the top project itself doesn't compile anything.
174
+
175
+ The options available to you depend on which compiler you are using for this
176
+ particular project, obviously the options are not the same for Java and Flash.
177
+ Two options are designed to work consistently across compilers.
178
+
179
+ Buildr turns the @warning@ option on by default, but turns it off when you run
180
+ @buildr --silent@. It also sets the @debug@ option on, but turns it off when
181
+ making a release. You can also control the @debug@ option from the command
182
+ line, for example:
183
+
184
+ {{{!ruby
185
+ # When calling buildr
186
+ $ buildr compile debug=off
187
+
188
+ # Once until we change the variable
189
+ $ export DEBUG=off
190
+ $ buildr compile
191
+ }}}
192
+
193
+
194
+ h3. Compiling Java
195
+
196
+ The Java compiler looks for source files in the project's @src/main/java@
197
+ directory, and defaults to compiling them into the @target/classes@ directory.
198
+ It looks for test cases in the project's @src/test/java@ and defaults to
199
+ compile them into the @target/test/classes@ directory.
200
+
201
+ If you point the @compile@ task at any other source directory, it will use the
202
+ Java compiler if any of these directories contains files with the extension
203
+ @.java@.
204
+
205
+ When using the Java compiler, if you don't specify the packaging type, it
206
+ defaults to JAR. If you don't specify the test framework, it defaults to
207
+ JUnit.
208
+
209
+ The Java compiler supports the following options:
210
+
211
+ |_. Option |_. Usage |
212
+ | @:debug@ | Generates bytecode with debugging information. You can
213
+ also override this by setting the environment variable @debug@ to @off@. |
214
+ | @:deprecation@ | If true, shows deprecation messages. False by default. |
215
+ | @:lint@ | Defaults to false. Set this option to true to use all lint
216
+ options, or specify a specific lint option (e.g. @:lint=>'cast'@). |
217
+ | @:other@ | Array of options passed to the compiler (e.g.
218
+ @:other=>'-implicit:none'@). |
219
+ | @:source@ | Source code compatibility (e.g. '1.5'). |
220
+ | @:target@ | Bytecode compatibility (e.g. '1.4'). |
221
+ | @:warnings@ | Issue warnings when compiling. True when running in
222
+ verbose mode. |
223
+
224
+
225
+ h3. Compiling Scala
226
+
227
+ Before using the Scala compiler, you must first set the environment variable
228
+ @SCALA_HOME@.
229
+
230
+ The Scala compiler looks for source files in the project's @src/main/scala@
231
+ directory, and defaults to compiling them into the @target/classes@ directory.
232
+ It looks for test cases in the project's @src/test/scala@ and defaults to
233
+ compile them into the @target/test/classes@ directory.
234
+
235
+ If you point the @compile@ task at any other source directory, it will use the
236
+ Scala compiler if any of these directories contains files with the extension
237
+ @.scala@.
238
+
239
+ When using the Scala compiler, if you don't specify the packaging type, it
240
+ defaults to JAR.
241
+
242
+ The Scala compiler supports the following options:
243
+
244
+ |_. Option |_. Usage |
245
+ | @:debug@ | Generates bytecode with debugging information. You can
246
+ also override this by setting the environment variable @debug@ to @off@. |
247
+ | @:deprecation@ | If true, shows deprecation messages. False by default. |
248
+ | @:optimise@ | Generates faster bytecode by applying optimisations to the
249
+ program. |
250
+ | @:other@ | Array of options passed to the compiler (e.g.
251
+ @:other=>'-Xprint-types'@). |
252
+ | @:source@ | Source code compatibility (e.g. '1.5'). |
253
+ | @:target@ | Bytecode compatibility (e.g. '1.4'). |
254
+ | @:warnings@ | Issue warnings when compiling. True when running in verbose
255
+ mode. |
256
+
257
+ You may use @fsc@, the Fast Scala Compiler, which submits compilation jobs to a
258
+ compilation daemon, by setting the environment variable @USE_FSC@ to @yes@. Note
259
+ that @fsc@ _may_ cache class libraries -- don't forget to run @fsc -reset@ if you
260
+ upgrade a library.
261
+
262
+
263
+ h3. Compiling Groovy
264
+
265
+ Before using the Groovy compiler, you must first require it on your buildfile:
266
+
267
+ {{{!ruby
268
+ require 'buildr/java/groovyc'
269
+ }}}
270
+
271
+ Once loaded, the groovyc compiler will be automatically selected if any .groovy
272
+ source files are found under @src/main/groovy@ directory, compiling them by
273
+ default into the @target/classes@ directory.
274
+
275
+ If the project has java sources in @src/main/java@ they will get compiled using
276
+ the groovyc joint compiler.
277
+
278
+ Sources found in @src/test/groovy@ are compiled into the @target/test/classes@.
279
+
280
+ If you don't specify the packaging type, it defaults to JAR.
281
+
282
+ The Groovy compiler supports the following options:
283
+
284
+ |_. Option |_. Usage |
285
+ | @encoding@ | Encoding of source files. |
286
+ | @verbose@ | Asks the compiler for verbose output, true when running
287
+ in verbose mode. |
288
+ | @fork@ | Whether to execute groovyc using a spawned instance of
289
+ the JVM. Defaults to no. |
290
+ | @memoryInitialSize@ | The initial size of the memory for the underlying VM,
291
+ if using fork mode, ignored otherwise. Defaults to the standard VM memory
292
+ setting. (Examples: @83886080@, @81920k@, or @80m@) |
293
+ | @memoryMaximumSize@ | The maximum size of the memory for the underlying VM,
294
+ if using fork mode, ignored otherwise. Defaults to the standard VM memory
295
+ setting. (Examples: @83886080@, @81920k@, or @80m@) |
296
+ | @listfiles@ | Indicates whether the source files to be compiled will
297
+ be listed. Defaults to no. |
298
+ | @stacktrace@ | If true each compile error message will contain a
299
+ stacktrace. |
300
+ | @warnings@ | Issue warnings when compiling. True when running in
301
+ verbose mode. |
302
+ | @debug@ | Generates bytecode with debugging information. Set
303
+ from the debug environment variable/global option. |
304
+ | @deprecation@ | If true, shows deprecation messages. False by default. |
305
+ | @optimise@ | Generates faster bytecode by applying optimisations to
306
+ the program. |
307
+ | @source@ | Source code compatibility. |
308
+ | @target@ | Bytecode compatibility. |
309
+ | @javac@ | Hash of options passed to the ant javac task. |
310
+
311
+
312
+ h2. Resources
313
+
314
+ The @compile@ task comes bundled with a @resources@ task. It copies files from
315
+ the @src/main/resources@ directory into @target/resources@. Best used for
316
+ copying files that you want to included in the generated code, like
317
+ configuration files, i18n messages, images, etc.
318
+
319
+ The @resources@ task uses a filter that can change files as it copies them from
320
+ source to destination. The most common use is by mapping values using a hash.
321
+ For example, to substitute "${version}" for the project's version number and
322
+ "${copyright}" for "Acme Inc (C) 2007" :
323
+
324
+ {{{!ruby
325
+ resources.filter.using 'version'=>version,
326
+ 'copyright'=>'Acme Inc (C) 2007'
327
+ }}}
328
+
329
+
330
+ You can also use "profiles":settings_profiles.html#profiles to supply a
331
+ name/value map that all @resources@ task should default to, by adding a
332
+ @filter@ element to each of the profiles. The following examples shows a
333
+ @profiles.yaml@ file that applies the same filter in development and test
334
+ environments:
335
+
336
+ {{{!yaml
337
+ filter: &alpha1
338
+ version: experimental
339
+ copyright: Acme Inc (C) 2007
340
+
341
+ development:
342
+ filter: *alpha1
343
+ test:
344
+ filter: *alpha1
345
+ }}}
346
+
347
+ You can specify a different format by passing it as the first argument.
348
+ Supported formats include:
349
+
350
+ |_. Format |_. Usage |
351
+ | @:ant@ | Map from <code>@key@</code> to value. |
352
+ | @:maven@ | Map from @${key}@ to value (default). |
353
+ | @:ruby@ | Map from @#{key}@ to value. |
354
+ | @Regexp@ | Map using the matched value of the regular expression (e.g.
355
+ @/=(.*?)=/@). |
356
+
357
+ For example, using the @:ruby@ format instead of the default @:maven@ format:
358
+
359
+ {{{!ruby
360
+ resources.filter.using :ruby, 'version'=>version,
361
+ 'copyright'=>'Acme Inc (C) 2007'
362
+ }}}
363
+
364
+ For more complicated mapping you can also pass a method or a proc. The filter
365
+ will call it once for each file with the file name and content.
366
+
367
+ If you need to copy resource files from other directories, add these source
368
+ directories by calling the @from@ method, for example:
369
+
370
+ {{{!ruby
371
+ resources.from _('src/etc')
372
+ }}}
373
+
374
+ You can select to copy only specific files using common file matching patterns.
375
+ For example, to include only HTML files:
376
+
377
+ {{{!ruby
378
+ resources.include '*.html'
379
+ }}}
380
+
381
+ To include all files, except for files in the @scratch@ directory:
382
+
383
+ {{{!ruby
384
+ resources.exclude 'scratch/*'
385
+ }}}
386
+
387
+ The filter always excludes the @CVS@ and @.svn@ directories, and all files
388
+ ending with @.bak@ or @~@, so no need to worry about these.
389
+
390
+ A file pattern can match any file name or part of a file name using an asterisk
391
+ (@*@). Double asterisk (@**@) matches directories recursively, for example,
392
+ @'src/main/java/**/*.java'@. You can match any character using a question mark
393
+ (@?@), or a set of characters using square brackets (@[]@), similar to regular
394
+ expressions, for example, @'[Rr]eadme'@. You can also match from a set of names
395
+ using curly braces (@{}@), for example, @'*.{html,css}'@.
396
+
397
+ You can use filters elsewhere. The @filter@ method creates a filter, the
398
+ @into@ method sets the target directory, and @using@ specifies the mapping.
399
+ Last, you call @run@ on the filter to activate it.
400
+
401
+ For example:
402
+
403
+ {{{!ruby
404
+ filter('src/specs').into('target/specs').
405
+ using('version'=>version, 'created'=>Time.now).run
406
+ }}}
407
+
408
+ The @resources@ task is, in fact, just a wrapper around such a filter that
409
+ automatically adds the @src/main/resources@ directory as one of the source
410
+ directories.
411
+
412
+
413
+ h2. More On Building
414
+
415
+ The @build@ task runs the @compile@ (and @resources@) tasks as prerequisites,
416
+ followed by any actions you add to it, and completes by running the @test@
417
+ task. The @build@ task itself is a prerequisite to other tasks, for example,
418
+ @package@ and @upload@.
419
+
420
+ You can extend the @build@ task in two ways. You can add more prerequisites
421
+ that will execute before the task itself, or you can add actions that will
422
+ execute as part of the task. Which one you choose is up to you, we'll show you
423
+ how they differ in a second. If you call @build@ with a list of tasks, it adds
424
+ these tasks as prerequisites. Call @build@ with a block, and it adds that
425
+ block as an action. Again, a common idiom you'll see elsewhere in Buildr and
426
+ Rake.
427
+
428
+ Let's look at a simple example. Say we want to generate a Derby database from
429
+ an SQL file and include it in the ZIP package:
430
+
431
+ {{{!ruby
432
+ db = Derby.create(_('target/derby/db')=>_('src/main/sql/derby.sql'))
433
+ package(:zip).include db
434
+ }}}
435
+
436
+ There's nothing fundamentally wrong with this code, if that's what you intend
437
+ to do. But in practice, you don't always run the @package@ task during
438
+ development, so you won't notice if something is wrong with this task when you
439
+ build. For example, if it fails to generate the SQL file. In addition, the
440
+ @package@ task runs after @build@, so you can't use the database in your test
441
+ cases.
442
+
443
+ So let's refactor it. We're going to use the variable @db@ to reference the
444
+ file task that creates the database, and make it a prerequisite of the @build@
445
+ task. And use that same variable again to include the database in the ZIP
446
+ package:
447
+
448
+ {{{!ruby
449
+ db = Derby.create(_('target/derby/db')=>_('src/main/sql/derby.sql'))
450
+ build db
451
+ package(:zip).include db
452
+ }}}
453
+
454
+ Much better. We're using the same task twice, but since we're using Rake here,
455
+ it will only execute once. In fact, it will only execute if we don't already
456
+ have a Derby database, or if it detects a change to the SQL file and needs to
457
+ recreate the database.
458
+
459
+ p(tip). @Derby.create@ is not part of Buildr, you can get
460
+ "derby.rake":http://svn.apache.org/repos/asf/incubator/ode/trunk/tasks/derby.rake
461
+ here.
462
+
463
+ Here's another example. We want to copy some files over as part of the build,
464
+ and apply a filter to them. This time, we're going to extend the @build@ task:
465
+
466
+ {{{!ruby
467
+ build do
468
+ filter('src/specs').into('target/specs').
469
+ using('version'=>version, 'created'=>Time.now).run
470
+ end
471
+ }}}
472
+
473
+ The @build@ task is recursive, so running @buildr build@ picks the current
474
+ project and runs its @build@ task, which in turn runs the @build@ task on each
475
+ of its sub-projects. One @build@ task to rule them all.
476
+
477
+
478
+ h2. Cleaning
479
+
480
+ The @build@ task has an evil twin, the @clean@ task. It's the task you use to
481
+ remove all the files created during the build, especially when you mess things
482
+ up and want to start all over.
483
+
484
+ It basically erases the target directories, the one called @target@, and if you
485
+ get creative and change the target directory for tasks like @compile@, it will
486
+ also erase those. If you decide to generate files outside the target directory
487
+ and want to cleanup after yourself, just extend the @clean@ task.
488
+
489
+ For example:
490
+
491
+ {{{!ruby
492
+ clean { rm_rf _('staged') }
493
+ }}}
494
+
495
+ The @rm_rf@ method deletes the directory and all files in it. It's named after
496
+ UNIX's infamous @rm -rf@. Use it wisely. This is also a good time to
497
+ introduce you to @FileUtils@, a standard Ruby library that contains convenient
498
+ methods for creating and deleting directories, copying and moving files, even
499
+ comparing two files. They're all free of charge when you use Buildr.
500
+
501
+ Now let's "talk about the artifacts":artifacts.html we mentioned before.