assaf-buildr 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/CHANGELOG +887 -0
  2. data/DISCLAIMER +7 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.rdoc +146 -0
  6. data/Rakefile +62 -0
  7. data/_buildr +38 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +236 -0
  10. data/addon/buildr/emma.rb +238 -0
  11. data/addon/buildr/hibernate.rb +142 -0
  12. data/addon/buildr/javacc.rb +85 -0
  13. data/addon/buildr/jdepend.rb +60 -0
  14. data/addon/buildr/jetty.rb +248 -0
  15. data/addon/buildr/jibx.rb +86 -0
  16. data/addon/buildr/nailgun.rb +817 -0
  17. data/addon/buildr/openjpa.rb +90 -0
  18. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  21. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  25. data/addon/buildr/xmlbeans.rb +93 -0
  26. data/bin/buildr +28 -0
  27. data/buildr.buildfile +53 -0
  28. data/buildr.gemspec +58 -0
  29. data/doc/css/default.css +228 -0
  30. data/doc/css/print.css +100 -0
  31. data/doc/css/syntax.css +52 -0
  32. data/doc/images/apache-incubator-logo.png +0 -0
  33. data/doc/images/buildr-hires.png +0 -0
  34. data/doc/images/buildr.png +0 -0
  35. data/doc/images/favicon.png +0 -0
  36. data/doc/images/growl-icon.tiff +0 -0
  37. data/doc/images/note.png +0 -0
  38. data/doc/images/project-structure.png +0 -0
  39. data/doc/images/tip.png +0 -0
  40. data/doc/images/zbuildr.tif +0 -0
  41. data/doc/pages/artifacts.textile +207 -0
  42. data/doc/pages/building.textile +240 -0
  43. data/doc/pages/contributing.textile +208 -0
  44. data/doc/pages/download.textile +62 -0
  45. data/doc/pages/extending.textile +175 -0
  46. data/doc/pages/getting_started.textile +273 -0
  47. data/doc/pages/index.textile +42 -0
  48. data/doc/pages/languages.textile +407 -0
  49. data/doc/pages/mailing_lists.textile +17 -0
  50. data/doc/pages/more_stuff.textile +286 -0
  51. data/doc/pages/packaging.textile +427 -0
  52. data/doc/pages/projects.textile +274 -0
  53. data/doc/pages/recipes.textile +103 -0
  54. data/doc/pages/settings_profiles.textile +274 -0
  55. data/doc/pages/testing.textile +212 -0
  56. data/doc/pages/troubleshooting.textile +103 -0
  57. data/doc/pages/whats_new.textile +323 -0
  58. data/doc/print.haml +51 -0
  59. data/doc/print.toc.yaml +29 -0
  60. data/doc/scripts/buildr-git.rb +412 -0
  61. data/doc/scripts/install-jruby.sh +44 -0
  62. data/doc/scripts/install-linux.sh +64 -0
  63. data/doc/scripts/install-osx.sh +52 -0
  64. data/doc/site.haml +56 -0
  65. data/doc/site.toc.yaml +47 -0
  66. data/etc/KEYS +151 -0
  67. data/etc/git-svn-authors +16 -0
  68. data/lib/buildr.rb +35 -0
  69. data/lib/buildr/core.rb +27 -0
  70. data/lib/buildr/core/application.rb +489 -0
  71. data/lib/buildr/core/application_cli.rb +139 -0
  72. data/lib/buildr/core/build.rb +311 -0
  73. data/lib/buildr/core/checks.rb +382 -0
  74. data/lib/buildr/core/common.rb +154 -0
  75. data/lib/buildr/core/compile.rb +596 -0
  76. data/lib/buildr/core/environment.rb +120 -0
  77. data/lib/buildr/core/filter.rb +362 -0
  78. data/lib/buildr/core/generate.rb +195 -0
  79. data/lib/buildr/core/help.rb +118 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +892 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +558 -0
  84. data/lib/buildr/core/util.rb +289 -0
  85. data/lib/buildr/groovy.rb +18 -0
  86. data/lib/buildr/groovy/bdd.rb +105 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/ide.rb +19 -0
  89. data/lib/buildr/ide/eclipse.rb +212 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +189 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +210 -0
  94. data/lib/buildr/java.rb +23 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +449 -0
  97. data/lib/buildr/java/commands.rb +211 -0
  98. data/lib/buildr/java/compiler.rb +348 -0
  99. data/lib/buildr/java/deprecated.rb +141 -0
  100. data/lib/buildr/java/jruby.rb +117 -0
  101. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  102. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  103. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  104. data/lib/buildr/java/packaging.rb +713 -0
  105. data/lib/buildr/java/pom.rb +178 -0
  106. data/lib/buildr/java/rjb.rb +155 -0
  107. data/lib/buildr/java/test_result.rb +308 -0
  108. data/lib/buildr/java/tests.rb +324 -0
  109. data/lib/buildr/java/version_requirement.rb +172 -0
  110. data/lib/buildr/packaging.rb +21 -0
  111. data/lib/buildr/packaging/artifact.rb +730 -0
  112. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  113. data/lib/buildr/packaging/artifact_search.rb +140 -0
  114. data/lib/buildr/packaging/gems.rb +102 -0
  115. data/lib/buildr/packaging/package.rb +233 -0
  116. data/lib/buildr/packaging/tar.rb +104 -0
  117. data/lib/buildr/packaging/zip.rb +722 -0
  118. data/lib/buildr/resources/buildr.icns +0 -0
  119. data/lib/buildr/scala.rb +19 -0
  120. data/lib/buildr/scala/compiler.rb +109 -0
  121. data/lib/buildr/scala/tests.rb +203 -0
  122. data/rakelib/apache.rake +191 -0
  123. data/rakelib/changelog.rake +57 -0
  124. data/rakelib/doc.rake +103 -0
  125. data/rakelib/package.rake +73 -0
  126. data/rakelib/release.rake +65 -0
  127. data/rakelib/rspec.rake +83 -0
  128. data/rakelib/rubyforge.rake +53 -0
  129. data/rakelib/scm.rake +49 -0
  130. data/rakelib/setup.rake +86 -0
  131. data/rakelib/stage.rake +48 -0
  132. data/spec/addon/cobertura_spec.rb +77 -0
  133. data/spec/addon/emma_spec.rb +120 -0
  134. data/spec/addon/test_coverage_spec.rb +255 -0
  135. data/spec/core/application_spec.rb +412 -0
  136. data/spec/core/artifact_namespace_spec.rb +646 -0
  137. data/spec/core/build_spec.rb +415 -0
  138. data/spec/core/checks_spec.rb +537 -0
  139. data/spec/core/common_spec.rb +664 -0
  140. data/spec/core/compile_spec.rb +566 -0
  141. data/spec/core/generate_spec.rb +33 -0
  142. data/spec/core/project_spec.rb +754 -0
  143. data/spec/core/test_spec.rb +1091 -0
  144. data/spec/core/transport_spec.rb +500 -0
  145. data/spec/groovy/bdd_spec.rb +80 -0
  146. data/spec/groovy/compiler_spec.rb +239 -0
  147. data/spec/ide/eclipse_spec.rb +243 -0
  148. data/spec/java/ant.rb +28 -0
  149. data/spec/java/bdd_spec.rb +358 -0
  150. data/spec/java/compiler_spec.rb +446 -0
  151. data/spec/java/java_spec.rb +88 -0
  152. data/spec/java/packaging_spec.rb +1103 -0
  153. data/spec/java/tests_spec.rb +466 -0
  154. data/spec/packaging/archive_spec.rb +503 -0
  155. data/spec/packaging/artifact_spec.rb +754 -0
  156. data/spec/packaging/packaging_helper.rb +63 -0
  157. data/spec/packaging/packaging_spec.rb +589 -0
  158. data/spec/sandbox.rb +137 -0
  159. data/spec/scala/compiler_spec.rb +228 -0
  160. data/spec/scala/tests_spec.rb +215 -0
  161. data/spec/spec_helpers.rb +304 -0
  162. data/spec/version_requirement_spec.rb +123 -0
  163. metadata +369 -0
Binary file
Binary file
Binary file
@@ -0,0 +1,207 @@
1
+ h1. Artifacts
2
+
3
+ In Buildr, almost everything is a file or a file task. You compile source files that come from the file system using dependencies found on the file system, generating even more files. But how do you get these dependencies to start with, and how do you share them with others?
4
+
5
+ Artifacts. We designed Buildr to work as a drop-in replacement for Maven 2.0, and share artifacts through the same local and remote repositories. Artifact tasks know how to download a file from one of the remote repositories, and install it in the local repository, where Buildr can find it. Packages know how to create files and upload them to remote repositories.
6
+
7
+ We'll get into all of that in a second, but first, let's introduce the artifact specification. It's a simple string that takes one of two forms:
8
+
9
+ {{{
10
+ group:id:type:version
11
+ group:id:type:classifier:version
12
+ }}}
13
+
14
+ For example, @'org.apache.axis2:axis2:jar:1.2'@ refers to an artifact with group identifier org.apache.axis2, artifact identifier axis2, a JAR file with version 1.2. Classifiers are typically used to distinguish between similar file types, for example, a source distribution and a binary distribution that otherwise have the same identifier and are both ZIP files.
15
+
16
+
17
+ h2. Specifying Artifacts
18
+
19
+ If your Buildfile spells out @'org.apache.axis2:axis2:jar:1.2'@ more than once, you're doing something wrong. Repeating the same string over and over will make your code harder to maintain. You'll know that when you upgrade to a new version in one place, forget to do it in another, and end up with a mismatch.
20
+
21
+ You can use Ruby's syntax to do simple string substitution, for example:
22
+
23
+ {{{!ruby
24
+ AXIS_VERSION = '1.2'
25
+
26
+ compile.with "org.apache.axis2:axis2:jar:#{AXIS_VERSION}"
27
+ }}}
28
+
29
+ Better yet, you can define all your artifacts at the top of the Buildfile and use constants to reference them in your project definition. For example:
30
+
31
+ {{{!ruby
32
+ AXIS2 = 'org.apache.axis2:axis2:jar:1.2'
33
+
34
+ compile.with AXIS2
35
+ }}}
36
+
37
+ Note that we're not using a separate constant for the version number. In our experience, it's unnecessary. The version number intentionally appears at the end of the string, where it stands out easily.
38
+
39
+ If you have a set of artifacts that belong to the same group and version, and that's quite common, you can use the @group@ shortcut:
40
+
41
+ {{{!ruby
42
+ AXIOM = group('axiom-api', 'axiom-impl', 'axiom-dom',
43
+ :under=>'org.apache.ws.commons.axiom', :version=>'1.2.4')
44
+ }}}
45
+
46
+ p(note). Buildr projects also define a @group@ attribute which can lead to some confusion. If you want to define an artifact group within a project definition, you should use the explicit qualifier @Buildr::group@.
47
+
48
+ If you have several artifacts you always use together, consider placing them in an array. Methods that accept lists of artifacts also accept arrays. For example:
49
+
50
+ {{{!ruby
51
+ OPENJPA = ['org.apache.openjpa:openjpa-all:jar:0.9.7',
52
+ 'net.sourceforge.serp:serp:jar:1.12.0']
53
+ AXIS_OF_WS = [AXIS2, AXIOM]
54
+
55
+ compile.with OPENJPA, AXIS_OF_WS
56
+ }}}
57
+
58
+ Another way to group related artifacts together and access them individually is using the @struct@ shortcut. For example:
59
+
60
+ {{{!ruby
61
+ JAVAX = struct(
62
+ :activation =>'javax.activation:activation:jar:1.1',
63
+ :persistence =>'javax.persistence:persistence-api:jar:1.0',
64
+ :stream =>'stax:stax-api:jar:1.0.1',
65
+ )
66
+
67
+ compile.with JAVAX.persistence, OPENJPA
68
+ }}}
69
+
70
+ In our experience, using constants in this manner makes your Buildfile much easier to write and maintain.
71
+
72
+ And, of course, you can always place your artifact specifications in a separate file and require it into your Buildfile. For example, if you're working on several different projects that all share the same artifacts:
73
+
74
+ {{{!ruby
75
+ require '../shared/artifacts'
76
+ }}}
77
+
78
+ When you use @require@, Ruby always looks for a filename with the @.rb@ extension, so in this case it expects to find @artifacts.rb@ in the @shared@ directory.
79
+
80
+ One last thing. You can also treat artifact specifications as hashes. For example:
81
+
82
+ {{{!ruby
83
+ AXIS = { :group=>'org.apache.axis2', :id=>'axis2', :version=>'1.2' }
84
+ compile.with AXIS
85
+ puts compile.dependencies.first.to_hash
86
+ => { :group=>'org.apache.axis2', :id=>'axis2',
87
+ :version=>'1.2', :type=>:jar }
88
+ }}}
89
+
90
+
91
+ h2. Specifying Repositories
92
+
93
+ Buildr can download artifacts for you, but only if you tell it where to find them. You need to specify at least one remote repository, from which to download these artifacts.
94
+
95
+ When you call @repositories.remote@, you get an array of URLs for the various remote repositories. Initially, it's an empty array, to which you can add new repositories. For example:
96
+
97
+ {{{!ruby
98
+ repositories.remote << 'http://www.ibiblio.org/maven2/'
99
+ }}}
100
+
101
+ If you need to use a proxy server to access remote repositories, you can set the environment variable @HTTP_PROXY@ to the proxy server URL. You can also work without a proxy for certain hosts by specifying the @NO_PROXY@ environment variable. For example:
102
+
103
+ {{{!sh
104
+ $ export HTTP_PROXY = 'http://myproxy:8080'
105
+ $ export NO_PROXY = '*.mycompany.com,localhost,special:800'
106
+ }}}
107
+
108
+ Alternatively you can use the Buildr options @proxy.http@ and @proxy.exclude@:
109
+
110
+ {{{!ruby
111
+ options.proxy.http = 'http://myproxy:8080'
112
+ options.proxy.exclude << '*.mycompany.com'
113
+ options.proxy.exclude << 'localhost'
114
+ }}}
115
+
116
+ All the artifacts download into the local repository. Since all your projects share the same local repository, you only need to download each artifact once. Buildr was designed to be used alongside Maven 2.0, for example, when migrating projects from Maven 2.0 over to Buildr. By default it will share the same local repository, expecting the repository to be the @.m2/repository@ directory inside your home directory.
117
+
118
+ You can choose to relocate the local repository by giving it a different path, for example:
119
+
120
+ {{{!ruby
121
+ repositories.local = '/usr/local/maven/repository'
122
+ }}}
123
+
124
+ That's one change you don't want to commit into the Buildfile, so the best place to do it is in your home directory's @buildr.rb@ file.
125
+
126
+ Buildr downloads artifacts when it needs to use them, for example, to compile a project. You don't need to download artifacts directly. Except when you do, for example, if you want to download all the latest artifacts and then go off-line. It's as simple as:
127
+
128
+ {{{!sh
129
+ $ buildr artifacts
130
+ }}}
131
+
132
+
133
+ h2. Downloading Artifacts
134
+
135
+ Within your buildfile you can download artifacts directly by invoking them, for example:
136
+
137
+ {{{!ruby
138
+ artifact('org.apache.openjpa:openjpa-all:jar:0.9.7').invoke
139
+ artifacts(OPENJPA).each(&:invoke)
140
+ }}}
141
+
142
+ When you let Buildr download artifacts for you, or by invoking the artifact task yourself, it scans through the remote repositories assuming each repository follows the Maven 2 structure. Starting from the root repository URL, it will look for each artifact using the path @group/id/version/id-version.type@ (or ...@/id-version-classifier.type@). The group identifier becomes a path by turning periods (@.@) into slashes (@/@). So to find @org.apache.axis2:axis2:jar:1.2@, we're going to look for @org/apache/axis2/axis2/1.2/axis2-1.2.jar@.
143
+
144
+ You'll find a lot of open source Java libraries in public repositories that support this structure (for example, the "Ibiblio Maven":http://www.ibiblio.org/maven2/ repository). And, of course, every remote repository you setup for your projects.
145
+
146
+ But there are exceptions to the rule. Say we want to download the Dojo widget library and use it in our project. It's available from the Dojo Web site, but that site doesn't follow the Maven repository conventions, so our feeble attempt to use existing remote repositories will fail.
147
+
148
+ We can still treat Dojo as an artifact, by telling Buildr where to download it from:
149
+
150
+ {{{!ruby
151
+ DOJO = '0.2.2'
152
+
153
+ url = "http://download.dojotoolkit.org/release-#{DOJO}/dojo-#{DOJO}-widget.zip"
154
+ download(artifact("dojo:dojo:zip:widget:#{DOJO}")=>url)
155
+ }}}
156
+
157
+ Explaining how it works is tricky, skip if you don't care for the details. On the other hand, it will give you a better understanding of Buildr/Rake, so if not now, come back and read it later.
158
+
159
+ We use the @artifact@ method to create an @Artifact@ task that references the Dojo widget in our local repository. The @Artifact@ task is a file task with some additional behavior added by Buildr. When you call @compile.with@, that's exactly what it does internally, turning each of your artifact specifications into an @Artifact@ task.
160
+
161
+ But the @Artifact@ task doesn't know how to download the Dojo widget, only how to handle conventional repositories. So we're going to create a download task as well. We use the @download@ method to create a file task that downloads the file from a remote URL. (Of course, it will only download the file if it doesn't already exist.)
162
+
163
+ But which task gets used when? We could have defined these tasks separately and used some glue code to make one use the other. Instead, we call @download@ with the results of @artifact@. Essentially, we're telling @download@ to use the same file path as @artifact@. So now we have two file tasks that point to the very same file. We wired them together.
164
+
165
+ You can't have more than one task pointing to the same file. Rake's rule of the road. What Rake does is merge the tasks together, creating a single file task for @artifact@, and then enhancing it with another action from @download@. One task, two actions. Statistically, we've doubled the odds that at least one of these actions will manage to download the Dojo widget and install it in the local repository.
166
+
167
+ Since we ordered the calls to @artifact@ first and @download@ second, we know the actions will execute in that order. But @artifact@ is slightly devilish: when its action runs, it adds another action to the end of the list. So the @artifact@ action runs first, adds an action at the end, the @download@ action runs second, and downloads the Dojo widget for us. The second @artifact@ action runs last, but checks that the file already exist and doesn't try to download it again.
168
+
169
+ Magic.
170
+
171
+
172
+ h2. Install and Upload
173
+
174
+ Generally you use artifacts that download from remote repositories into the local repository, or artifacts packaged by the project itself (see "Packaging":packaging.html), which are then installed into the local repository and uploaded to the release server.
175
+
176
+ Some artifacts do not fall into either category. In this example we're going to download a ZIP file, extract a JAR file from it, and use that JAR file as an artifact. We would then expect to install this JAR in the local repository and upload it to the release server, where it can be shared with other projects.
177
+
178
+ So let's start by creating a task that downloads the ZIP, and another one to extract it and create the JAR file:
179
+
180
+ {{{!ruby
181
+ app_zip = download('target/app.zip'=>url)
182
+ bean_jar = file('target/app/bean.jar'=>unzip('target/app'=>app_zip))
183
+ }}}
184
+
185
+ When you call @artifact@, it returns an @Artifact@ task that points to the artifact file in the local repository, downloading the file if it doesn't already exist. You can override this behavior by enhancing the task and creating the file yourself (you may also want to create a POM file). Or much simpler, call the @from@ method on the artifact and tell it where to find the source file.
186
+
187
+ So the next step is to specify the artifact and tell it to use the extracted JAR file:
188
+
189
+ {{{!ruby
190
+ bean = artifact('example.com:beans:jar:1.0').from(bean_jar)
191
+ }}}
192
+
193
+ The artifact still points to the local repository, but when we invoke the task it copies the source file over to the local repository, instead of attempting a download.
194
+
195
+ Use the @install@ method if you want the artifact and its POM installed in the local repository when you run the @install@ task. Likewise, use the @upload@ method if you want the artifact uploaded to the release server when you run the @upload@ task. You do not need to do this on artifacts downloaded from a remote server, or created with the @package@ method, the later are automatically added to the list of installed/uploaded artifacts.
196
+
197
+ Our example ends by including the artifact in the @install@ and @upload@ tasks:
198
+
199
+ {{{!ruby
200
+ install bean
201
+ upload bean
202
+ }}}
203
+
204
+ p(tip). Calling the @install@ (and likewise @upload@) method on an artifact run @buildr install@. If you need to download and install an artifact, invoke the task directly with @install(<artifact>).invoke@.
205
+
206
+
207
+ Next we're going to "package some artifacts":packaging.html.
@@ -0,0 +1,240 @@
1
+ h1. Building
2
+
3
+ To remove any confusion, Buildr's build task is actually called @build@. It's also the default task that executes when you run @buildr@ without any task name.
4
+
5
+ The @build@ task runs two other tasks: @compile@ and its associated tasks (that would be, @resources@) and @test@ and its associated tasks (@test:compile@, @test:setup@ and friends). We'll talk about @compile@ more in this section, and @test@ later on. We'll also show you how to run @build@ without testing, not something we recommend, but a necessary feature.
6
+
7
+ Why @build@ and not @compile@? Some projects do more than just compiling. Other projects don't compile at all, but perform other build tasks, for example, creating a database schema or command line scripts. So we want you to get in the practice of running the @build@ task, and help you by making it the default task.
8
+
9
+
10
+ h2. Compiling
11
+
12
+ Each project has its own @compile@ task you can invoke directly, by running @buildr compile@ or as part of another build task. (Yes, that @build@).
13
+
14
+ The @compile@ task looks for source files in well known directories, determines which compiler to use, and sets the target directory accordingly. For example, if it finds any Java source files in the @src/main/java@ directory, it selects the Javac compiler and generates bytecode in the @target/classes@ directories. If it finds Scala source files in the @src/main/scala@ directory it selects the Scalac compiler, and so forth.
15
+
16
+ A single project cannot use multiple compilers at the same time, hence you may prefer creating subprojects by programming language. Some compilers like Groovy's are joint-compilers, this means they can handle several languages. When the Groovy compiler is selected for a project, .groovy and .java files are compiled by groovyc.
17
+
18
+ Most often, that's just good enough and the only change you need to make is adding compile dependencies. You can use @compile.dependencies@ to get the array of dependency file tasks. For Java, each of these tasks points to a JAR or a directory containing Java classes, and the entire set of dependencies is passed to Javac as the classpath.
19
+
20
+ Buildr uses file tasks to handle dependencies, but here we're talking about the Rake dependency mechanism. It's a double entendre. It invokes these tasks before running the compiler. Some of these tasks will download JARs from remote repositories, others will create them by compiling and packaging from a different project. Using file task ensures all the dependencies exist before the compiler can use them.
21
+
22
+ An easier way to specify dependencies is by calling the @compile.with@ method. It takes a list of arguments and adds them to the dependency list. The @compile.with@ method is easier to use, it accepts several type of dependencies. You can use file names, file tasks, projects, artifacts specifications and even pass arrays of dependencies.
23
+
24
+ Most dependencies fall into the last three categories. When you pass a project to @compile.with@, it picks up all the packages created by that project. In doing so, it establishes an order of dependency between the two projects (see "Defining the Project":projects.html#defining_the_project). For example, if you make a change in project _teh-api_ and build _teh-impl_, Buildr will detect that change, recompile and package _teh-api_ before compiling _teh-impl_. You can also select a specific package using the @package@ or @packages@ methods (see "Packaging":packaging.html).
25
+
26
+ When you pass an artifact specification to @compile.with@, it creates an @Artifact@ task that will download that artifact from one of the remote repositories, install it in the local repository, and use it in your project. Rake's dependency mechanism is used here to make sure the artifact is downloaded once, when needed. Check the "Artifacts":artifacts.html section for more information about artifact specification and repositories.
27
+
28
+ For now let's just show a simple example:
29
+
30
+ {{{!ruby
31
+ compile.with 'org.apache.axis2:axis2:jar:1.2',
32
+ 'org.apache.derby:derby:jar:10.1.2.1', projects('teh-api', 'teh-impl')
33
+ }}}
34
+
35
+ Passing arrays to @compile.with@ is just a convenient for handling multiple dependencies, we'll show more examples of that when we talk about "Artifacts":#artifacts.
36
+
37
+ Likewise, the @compile@ task has an array of file tasks that point at the source directories you want to compile from. You can access that array by calling @compile.sources@. You can use @compile.from@ to add new source directories by passing a file name or a file task.
38
+
39
+ For example, let's run the APT tool on our annotated source code before compiling it:
40
+
41
+ {{{!ruby
42
+ compile.from apt
43
+ }}}
44
+
45
+ When you call @apt@ on a project, it returns a file task that points to the @target/generated/apt@ directory. This file task executes by running APT, using the same list of source directories, dependencies and compiler options. It then generates new source files in the target directory. Calling @compile.from@ with that file task includes those additional source files in the list of compiled sources.
46
+
47
+ Here's another example:
48
+
49
+ {{{!ruby
50
+ jjtree = jjtree(_('src/main/jjtree'), :in_package=>'com.acme')
51
+ compile.from javacc(jjtree, :in_package=>'com.acme'), jjtree
52
+ }}}
53
+
54
+ This time, the variable @jjtree@ is a file task that reads a JJTree source file from the @src/main/jjtree@ directory, and generates additional source files in the @target/generated/jjtree@ directory. The second line creates another file task that takes those source files, runs JavaCC on them, and generates yet more source files in @target/generated/javacc@. Finally, we include both sets of source files in addition to those already in @src/main/java@, and compile the lot.
55
+
56
+ The interesting thing about these two examples is how you're wiring file tasks together to create more complicated tasks, piping the output of one task into the inputs of another. Wiring tasks this way is the most common way to handle complex builds, and uses Rake's dependency mechanism to only run tasks when it detects a change to one of the source files.
57
+
58
+ You can also control the target directory. Use @compile.target@ to get the target directory file task. If you need to change the target directory, call the @compile.into@ method with the new path.
59
+
60
+ We use method pairs to give you finer control over the compiler, but also a way to easily configure it. Methods like @dependencies@ and @sources@ give you a live array you can manipulate, or iterate over. On the other hand, methods like @with@ and @from@ accept a wider set of arguments and clean them up for you. They also all return the same task you're calling, so you can chain methods together.
61
+
62
+ For example:
63
+
64
+ {{{!ruby
65
+ compile.from('srcs').with('org.apache.axis2:axis2:jar:1.2').
66
+ into('classes').using(:target=>'1.4')
67
+ }}}
68
+
69
+ Buildr uses the method pair and method chaining idiom in many places to make your life easier without sacrificing flexibility.
70
+
71
+ Occasionally, you'll need to post-process the generated bytecode. Since you only want to do that after compiling, and let the compiler decide when to do that – only when changes require re-compiling – you'll want to extend the @compile@ task. You can do that by calling @compile@ with a block.
72
+
73
+ For example, to run the OpenJPA bytecode enhancer after compiling the source files:
74
+
75
+ {{{!ruby
76
+ compile { open_jpa_enhance }
77
+ }}}
78
+
79
+ You can change various compile options by calling, you guessed, @compile.options@. For example, to set the compiler to VM compatibility with Java 1.5 and turn on all Lint messages:
80
+
81
+ {{{!ruby
82
+ compile.options.target = '1.5'
83
+ compile.options.lint = 'all'
84
+ }}}
85
+
86
+ Or, if you want to chain methods together:
87
+
88
+ {{{!ruby
89
+ compile.using :target=>'1.5', :lint=>'all'
90
+ }}}
91
+
92
+
93
+ Sub-projects inherit compile options from their parent project, so you only need to change these settings once in the top project. You can do so, even if the top project itself doesn't compile anything.
94
+
95
+ The options available to you depend on which compiler you are using for this particular project, obviously the options are not the same for Java and Flash. Two options are designed to work consistently across compilers.
96
+
97
+ Buildr turns the @warning@ option on by default, but turns it off when you run @buildr --silent@. It also sets the @debug@ option on, but turns it off when making a release. You can also control the @debug@ option from the command line, for example:
98
+
99
+ {{{!ruby
100
+ # When calling buildr
101
+ $ buildr compile debug=off
102
+
103
+ # Once until we change the variable
104
+ $ export DEBUG=off
105
+ $ buildr compile
106
+ }}}
107
+
108
+ The default source and target directories, compiler settings and other options you can use depend on the specific language. You can find more information in the "Languages":languages.html section.
109
+
110
+
111
+ h2. Resources
112
+
113
+
114
+ The @compile@ task comes bundled with a @resources@ task. It copies files from the @src/main/resources@ directory into @target/resources@. Best used for copying files that you want to included in the generated code, like configuration files, i18n messages, images, etc.
115
+
116
+ The @resources@ task uses a filter that can change files as it copies them from source to destination. The most common use is by mapping values using a hash. For example, to substitute "${version}" for the project's version number and "${copyright}" for "Acme Inc (C) 2007" :
117
+
118
+ {{{!ruby
119
+ resources.filter.using 'version'=>version,
120
+ 'copyright'=>'Acme Inc (C) 2007'
121
+ }}}
122
+
123
+ You can also use "profiles":settings_profiles.html#profiles to supply a name/value map that all @resources@ task should default to, by adding a @filter@ element to each of the profiles. The following examples shows a @profiles.yaml@ file that applies the same filter in development and test environments:
124
+
125
+ {{{!yaml
126
+ filter: &alpha1
127
+ version: experimental
128
+ copyright: Acme Inc (C) 2007
129
+
130
+ development:
131
+ filter: *alpha1
132
+ test:
133
+ filter: *alpha1
134
+ }}}
135
+
136
+ You can specify a different format by passing it as the first argument. Supported formats include:
137
+
138
+ |_. Format |_. Usage |
139
+ | @:ant@ | Map from <code>@key@</code> to value. |
140
+ | @:maven@ | Map from @${key}@ to value (default). |
141
+ | @:ruby@ | Map from @#{key}@ to value. |
142
+ | @Regexp@ | Map using the matched value of the regular expression (e.g. @/=(.*?)=/@). |
143
+
144
+ For example, using the @:ruby@ format instead of the default @:maven@ format:
145
+
146
+ {{{!ruby
147
+ resources.filter.using :ruby, 'version'=>version,
148
+ 'copyright'=>'Acme Inc (C) 2007'
149
+ }}}
150
+
151
+ For more complicated mapping you can also pass a method or a proc. The filter will call it once for each file with the file name and content.
152
+
153
+ If you need to copy resource files from other directories, add these source directories by calling the @from@ method, for example:
154
+
155
+ {{{!ruby
156
+ resources.from _('src/etc')
157
+ }}}
158
+
159
+ You can select to copy only specific files using common file matching patterns. For example, to include only HTML files:
160
+
161
+ {{{!ruby
162
+ resources.include '*.html'
163
+ }}}
164
+
165
+ To include all files, except for files in the @scratch@ directory:
166
+
167
+ {{{!ruby
168
+ resources.exclude 'scratch/*'
169
+ }}}
170
+
171
+ The filter always excludes the @CVS@ and @.svn@ directories, and all files ending with @.bak@ or @~@, so no need to worry about these.
172
+
173
+ A file pattern can match any file name or part of a file name using an asterisk (@*@). Double asterisk (@**@) matches directories recursively, for example, @'src/main/java/**/*.java'@. You can match any character using a question mark (@?@), or a set of characters using square brackets (@[]@), similar to regular expressions, for example, @'[Rr]eadme'@. You can also match from a set of names using curly braces (@{}@), for example, @'*.{html,css}'@.
174
+
175
+ You can use filters elsewhere. The @filter@ method creates a filter, the @into@ method sets the target directory, and @using@ specifies the mapping. Last, you call @run@ on the filter to activate it.
176
+
177
+ For example:
178
+
179
+ {{{!ruby
180
+ filter('src/specs').into('target/specs').
181
+ using('version'=>version, 'created'=>Time.now).run
182
+ }}}
183
+
184
+ The @resources@ task is, in fact, just a wrapper around such a filter that automatically adds the @src/main/resources@ directory as one of the source directories.
185
+
186
+
187
+ h2. More On Building
188
+
189
+ The @build@ task runs the @compile@ (and @resources@) tasks as prerequisites, followed by any actions you add to it, and completes by running the @test@ task. The @build@ task itself is a prerequisite to other tasks, for example, @package@ and @upload@.
190
+
191
+ You can extend the @build@ task in two ways. You can add more prerequisites that will execute before the task itself, or you can add actions that will execute as part of the task. Which one you choose is up to you, we'll show you how they differ in a second. If you call @build@ with a list of tasks, it adds these tasks as prerequisites. Call @build@ with a block, and it adds that block as an action. Again, a common idiom you'll see elsewhere in Buildr and Rake.
192
+
193
+ Let's look at a simple example. Say we want to generate a Derby database from an SQL file and include it in the ZIP package:
194
+
195
+ {{{!ruby
196
+ db = Derby.create(_('target/derby/db')=>_('src/main/sql/derby.sql'))
197
+ package(:zip).include db
198
+ }}}
199
+
200
+ There's nothing fundamentally wrong with this code, if that's what you intend to do. But in practice, you don't always run the @package@ task during development, so you won't notice if something is wrong with this task when you build. For example, if it fails to generate the SQL file. In addition, the @package@ task runs after @build@, so you can't use the database in your test cases.
201
+
202
+ So let's refactor it. We're going to use the variable @db@ to reference the file task that creates the database, and make it a prerequisite of the @build@ task. And use that same variable again to include the database in the ZIP package:
203
+
204
+ {{{!ruby
205
+ db = Derby.create(_('target/derby/db')=>_('src/main/sql/derby.sql'))
206
+ build db
207
+ package(:zip).include db
208
+ }}}
209
+
210
+ Much better. We're using the same task twice, but since we're using Rake here, it will only execute once. In fact, it will only execute if we don't already have a Derby database, or if it detects a change to the SQL file and needs to recreate the database.
211
+
212
+ p(tip). @Derby.create@ is not part of Buildr, you can get "derby.rake":http://svn.apache.org/repos/asf/incubator/ode/trunk/tasks/derby.rake here.
213
+
214
+ Here's another example. We want to copy some files over as part of the build, and apply a filter to them. This time, we're going to extend the @build@ task:
215
+
216
+ {{{!ruby
217
+ build do
218
+ filter('src/specs').into('target/specs').
219
+ using('version'=>version, 'created'=>Time.now).run
220
+ end
221
+ }}}
222
+
223
+ The @build@ task is recursive, so running @buildr build@ picks the current project and runs its @build@ task, which in turn runs the @build@ task on each of its sub-projects. One @build@ task to rule them all.
224
+
225
+
226
+ h2. Cleaning
227
+
228
+ The @build@ task has an evil twin, the @clean@ task. It's the task you use to remove all the files created during the build, especially when you mess things up and want to start all over.
229
+
230
+ It basically erases the target directories, the one called @target@, and if you get creative and change the target directory for tasks like @compile@, it will also erase those. If you decide to generate files outside the target directory and want to cleanup after yourself, just extend the @clean@ task.
231
+
232
+ For example:
233
+
234
+ {{{!ruby
235
+ clean { rm_rf _('staged') }
236
+ }}}
237
+
238
+ The @rm_rf@ method deletes the directory and all files in it. It's named after UNIX's infamous @rm -rf@. Use it wisely. This is also a good time to introduce you to @FileUtils@, a standard Ruby library that contains convenient methods for creating and deleting directories, copying and moving files, even comparing two files. They're all free of charge when you use Buildr.
239
+
240
+ Now let's "talk about the artifacts":artifacts.html we mentioned before.