buildr 1.3.5-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGELOG +998 -0
  2. data/LICENSE +176 -0
  3. data/NOTICE +26 -0
  4. data/README.rdoc +134 -0
  5. data/Rakefile +45 -0
  6. data/_buildr +29 -0
  7. data/_jbuildr +29 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +22 -0
  10. data/addon/buildr/drb.rb +281 -0
  11. data/addon/buildr/emma.rb +22 -0
  12. data/addon/buildr/hibernate.rb +142 -0
  13. data/addon/buildr/javacc.rb +85 -0
  14. data/addon/buildr/jdepend.rb +60 -0
  15. data/addon/buildr/jetty.rb +248 -0
  16. data/addon/buildr/jibx.rb +86 -0
  17. data/addon/buildr/nailgun.rb +221 -0
  18. data/addon/buildr/openjpa.rb +90 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  21. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  25. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  26. data/addon/buildr/xmlbeans.rb +93 -0
  27. data/bin/buildr +19 -0
  28. data/buildr.buildfile +58 -0
  29. data/buildr.gemspec +65 -0
  30. data/doc/_config.yml +1 -0
  31. data/doc/_layouts/default.html +88 -0
  32. data/doc/_layouts/preface.html +22 -0
  33. data/doc/artifacts.textile +211 -0
  34. data/doc/building.textile +244 -0
  35. data/doc/contributing.textile +252 -0
  36. data/doc/css/default.css +236 -0
  37. data/doc/css/print.css +101 -0
  38. data/doc/css/syntax.css +23 -0
  39. data/doc/download.textile +79 -0
  40. data/doc/extending.textile +186 -0
  41. data/doc/images/1442160941-frontcover.jpg +0 -0
  42. data/doc/images/asf-logo.gif +0 -0
  43. data/doc/images/asf-logo.png +0 -0
  44. data/doc/images/buildr-hires.png +0 -0
  45. data/doc/images/buildr.png +0 -0
  46. data/doc/images/favicon.png +0 -0
  47. data/doc/images/growl-icon.tiff +0 -0
  48. data/doc/images/note.png +0 -0
  49. data/doc/images/project-structure.png +0 -0
  50. data/doc/images/tip.png +0 -0
  51. data/doc/images/zbuildr.png +0 -0
  52. data/doc/images/zbuildr.tif +0 -0
  53. data/doc/index.textile +69 -0
  54. data/doc/installing.textile +266 -0
  55. data/doc/languages.textile +459 -0
  56. data/doc/mailing_lists.textile +25 -0
  57. data/doc/more_stuff.textile +457 -0
  58. data/doc/packaging.textile +430 -0
  59. data/doc/preface.textile +54 -0
  60. data/doc/projects.textile +271 -0
  61. data/doc/quick_start.textile +210 -0
  62. data/doc/scripts/buildr-git.rb +512 -0
  63. data/doc/scripts/gitflow.rb +296 -0
  64. data/doc/scripts/install-jruby.sh +44 -0
  65. data/doc/scripts/install-linux.sh +72 -0
  66. data/doc/scripts/install-osx.sh +52 -0
  67. data/doc/settings_profiles.textile +280 -0
  68. data/doc/testing.textile +222 -0
  69. data/etc/KEYS +151 -0
  70. data/lib/buildr.rb +36 -0
  71. data/lib/buildr/core.rb +35 -0
  72. data/lib/buildr/core/application.rb +656 -0
  73. data/lib/buildr/core/build.rb +452 -0
  74. data/lib/buildr/core/checks.rb +254 -0
  75. data/lib/buildr/core/common.rb +150 -0
  76. data/lib/buildr/core/compile.rb +608 -0
  77. data/lib/buildr/core/environment.rb +129 -0
  78. data/lib/buildr/core/filter.rb +362 -0
  79. data/lib/buildr/core/generate.rb +195 -0
  80. data/lib/buildr/core/help.rb +119 -0
  81. data/lib/buildr/core/osx.rb +46 -0
  82. data/lib/buildr/core/progressbar.rb +156 -0
  83. data/lib/buildr/core/project.rb +866 -0
  84. data/lib/buildr/core/shell.rb +198 -0
  85. data/lib/buildr/core/test.rb +723 -0
  86. data/lib/buildr/core/transports.rb +559 -0
  87. data/lib/buildr/core/util.rb +449 -0
  88. data/lib/buildr/groovy.rb +19 -0
  89. data/lib/buildr/groovy/bdd.rb +106 -0
  90. data/lib/buildr/groovy/compiler.rb +138 -0
  91. data/lib/buildr/groovy/shell.rb +48 -0
  92. data/lib/buildr/ide.rb +19 -0
  93. data/lib/buildr/ide/eclipse.rb +334 -0
  94. data/lib/buildr/ide/eclipse/java.rb +53 -0
  95. data/lib/buildr/ide/eclipse/plugin.rb +68 -0
  96. data/lib/buildr/ide/eclipse/scala.rb +66 -0
  97. data/lib/buildr/ide/idea.ipr.template +300 -0
  98. data/lib/buildr/ide/idea.rb +190 -0
  99. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  100. data/lib/buildr/ide/idea7x.rb +212 -0
  101. data/lib/buildr/java.rb +23 -0
  102. data/lib/buildr/java/ant.rb +94 -0
  103. data/lib/buildr/java/bdd.rb +459 -0
  104. data/lib/buildr/java/cobertura.rb +274 -0
  105. data/lib/buildr/java/commands.rb +213 -0
  106. data/lib/buildr/java/compiler.rb +349 -0
  107. data/lib/buildr/java/deprecated.rb +141 -0
  108. data/lib/buildr/java/emma.rb +244 -0
  109. data/lib/buildr/java/jruby.rb +117 -0
  110. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  111. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  112. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +137 -0
  113. data/lib/buildr/java/packaging.rb +716 -0
  114. data/lib/buildr/java/pom.rb +174 -0
  115. data/lib/buildr/java/rjb.rb +155 -0
  116. data/lib/buildr/java/test_result.rb +353 -0
  117. data/lib/buildr/java/tests.rb +333 -0
  118. data/lib/buildr/java/version_requirement.rb +172 -0
  119. data/lib/buildr/packaging.rb +24 -0
  120. data/lib/buildr/packaging/archive.rb +488 -0
  121. data/lib/buildr/packaging/artifact.rb +749 -0
  122. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  123. data/lib/buildr/packaging/artifact_search.rb +140 -0
  124. data/lib/buildr/packaging/gems.rb +102 -0
  125. data/lib/buildr/packaging/package.rb +238 -0
  126. data/lib/buildr/packaging/tar.rb +186 -0
  127. data/lib/buildr/packaging/version_requirement.rb +172 -0
  128. data/lib/buildr/packaging/zip.rb +73 -0
  129. data/lib/buildr/packaging/ziptask.rb +316 -0
  130. data/lib/buildr/resources/buildr.icns +0 -0
  131. data/lib/buildr/scala.rb +25 -0
  132. data/lib/buildr/scala/bdd.rb +109 -0
  133. data/lib/buildr/scala/compiler.rb +195 -0
  134. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  135. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  136. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  137. data/lib/buildr/scala/shell.rb +55 -0
  138. data/lib/buildr/scala/tests.rb +157 -0
  139. data/lib/buildr/shell.rb +180 -0
  140. data/rakelib/checks.rake +57 -0
  141. data/rakelib/doc.rake +92 -0
  142. data/rakelib/jekylltask.rb +120 -0
  143. data/rakelib/package.rake +73 -0
  144. data/rakelib/release.rake +149 -0
  145. data/rakelib/rspec.rake +73 -0
  146. data/rakelib/setup.rake +54 -0
  147. data/rakelib/stage.rake +213 -0
  148. data/rakelib/stage.rake~ +213 -0
  149. data/spec/addon/drb_spec.rb +328 -0
  150. data/spec/core/application_spec.rb +502 -0
  151. data/spec/core/build_spec.rb +677 -0
  152. data/spec/core/checks_spec.rb +519 -0
  153. data/spec/core/common_spec.rb +670 -0
  154. data/spec/core/compile_spec.rb +583 -0
  155. data/spec/core/extension_spec.rb +93 -0
  156. data/spec/core/generate_spec.rb +33 -0
  157. data/spec/core/project_spec.rb +762 -0
  158. data/spec/core/test_spec.rb +1098 -0
  159. data/spec/core/transport_spec.rb +537 -0
  160. data/spec/core/util_spec.rb +67 -0
  161. data/spec/groovy/bdd_spec.rb +80 -0
  162. data/spec/groovy/compiler_spec.rb +240 -0
  163. data/spec/ide/eclipse_spec.rb +501 -0
  164. data/spec/ide/idea7x_spec.rb +84 -0
  165. data/spec/java/ant_spec.rb +33 -0
  166. data/spec/java/bdd_spec.rb +382 -0
  167. data/spec/java/cobertura_spec.rb +85 -0
  168. data/spec/java/compiler_spec.rb +446 -0
  169. data/spec/java/emma_spec.rb +119 -0
  170. data/spec/java/java_spec.rb +124 -0
  171. data/spec/java/packaging_spec.rb +1134 -0
  172. data/spec/java/test_coverage_helper.rb +257 -0
  173. data/spec/java/tests_spec.rb +493 -0
  174. data/spec/packaging/archive_spec.rb +527 -0
  175. data/spec/packaging/artifact_namespace_spec.rb +654 -0
  176. data/spec/packaging/artifact_spec.rb +795 -0
  177. data/spec/packaging/packaging_helper.rb +63 -0
  178. data/spec/packaging/packaging_spec.rb +684 -0
  179. data/spec/sandbox.rb +142 -0
  180. data/spec/scala/bdd_spec.rb +119 -0
  181. data/spec/scala/compiler_spec.rb +284 -0
  182. data/spec/scala/scala.rb +38 -0
  183. data/spec/scala/tests_spec.rb +261 -0
  184. data/spec/spec_helpers.rb +340 -0
  185. data/spec/version_requirement_spec.rb +129 -0
  186. metadata +383 -0
@@ -0,0 +1,271 @@
1
+ ---
2
+ layout: default
3
+ title: Projects
4
+ ---
5
+
6
+
7
+ h2(#starting). Starting Out
8
+
9
+ In Java, most projects are built the same way: compile source code, run test cases, package the code, release it. Rinse, repeat.
10
+
11
+ Feed it a project definition, and Buildr will set up all these tasks for you. The only thing you need to do is specify the parts that are specific to your project, like the classpath dependencies, whether you're packaging a JAR or a WAR, etc.
12
+
13
+ The remainder of this guide deals with what it takes to build a project. But first, let's pick up a sample project to work with. We'll call it _killer-app_:
14
+
15
+ {% highlight ruby %}
16
+ require 'buildr'
17
+
18
+ VERSION_NUMBER = '1.0'
19
+
20
+ AXIS2 = 'org.apache.axis2:axis2:jar:1.2'
21
+ AXIOM = group('axiom-api', 'axiom-impl', 'axiom-dom',
22
+ :under=>'org.apache.ws.commons.axiom', :version=>'1.2.4')
23
+ AXIS_OF_WS = [AXIOM, AXIS2]
24
+ OPENJPA = ['org.apache.openjpa:openjpa:jar:1.2.0',
25
+ 'net.sourceforge.serp:serp:jar:1.12.0']
26
+
27
+ repositories.remote << 'http://www.ibiblio.org/maven2/'
28
+
29
+ desc 'Code. Build. ??? Profit!'
30
+ define 'killer-app' do
31
+
32
+ project.version = VERSION_NUMBER
33
+ project.group = 'acme'
34
+ manifest['Copyright'] = 'Acme Inc (C) 2007'
35
+ compile.options.target = '1.5'
36
+
37
+ desc 'Abstract classes and interfaces'
38
+ define 'teh-api' do
39
+ package :jar
40
+ end
41
+
42
+ desc 'All those implementation details'
43
+ define 'teh-impl' do
44
+ compile.with AXIS_OF_WS, OPENJPA
45
+ compile { open_jpa_enhance }
46
+ package :jar
47
+ end
48
+
49
+ desc 'What our users see'
50
+ define 'la-web' do
51
+ test.with AXIS_OF_WS
52
+ package(:war).with :libs=>projects('teh-api', 'teh-impl')
53
+ end
54
+
55
+ javadoc projects
56
+ package :javadoc
57
+
58
+ end
59
+ {% endhighlight %}
60
+
61
+ A project definition requires four pieces of information: the project name, group identifier, version number and base directory. The project name ... do we need to explain why its necessary? The group identifier and version number are used for packaging and deployment, we'll talk more about that in the "Packaging":packaging.html section. The base directory lets you find files inside the project.
62
+
63
+ Everything else depends on what that particular project is building. And it all goes inside the project definition block, the piece of code that comes between @define <name> .. do@ and @end@.
64
+
65
+
66
+ h2(#dir_structure). The Directory Structure
67
+
68
+ Buildr follows a convention we picked from years of working with Apache projects.
69
+
70
+ Java projects are laid out so the source files are in the @src/main/java@ directory and compile into the @target/classes@ directory. Resource files go in the @src/main/resources@ directory, and copied over to @target/resources@. Likewise, tests come from @src/test/java@ and @src/test/resources@, and end life in @target/test/classes@ and @target/test/resources@, respectively.
71
+
72
+ WAR packages pick up additional files from the aptly named @src/main/webapp@. And most stuff, including generated source files are parked under the @target@ directory. Test cases and such may generate reports in the, you guessed it, @reports@ directory.
73
+
74
+ Other languages will use different directories, but following the same general conventions. For example, Scala code compiles from the @src/main/scala@ directory, RSpec tests are found in the @src/test/rspec@ directory, and Flash will compile to @target/flash@. Throughout this document we will show examples using mostly Java, but you can imagine how this pattern applies to other languages.
75
+
76
+ When projects grow big, you split them into smaller projects by nesting projects inside each other. Each sub-project has a sub-directory under the parent project and follows the same internal directory structure. You can, of course, change all of that to suite your needs, but if you follow these conventions, Buildr will figure all the paths for you.
77
+
78
+ Going back to the example above, the directory structure will look something like this:
79
+
80
+ p=. !images/project-structure.png!
81
+
82
+ Notice the @buildfile@ at the top. That's your project build script, the one Buildr runs.
83
+
84
+ When you run the @buildr@ command, it picks up the @buildfile@ (which here we'll just call _Buildfile_) from the current directory, or if not there, from the closest parent directory. So you can run @buildr@ from any directory inside your project, and it will always pick up the same Buildfile. That also happens to be the base directory for the top project. If you have any sub-projects, Buildr assumes they reflect sub-directories under their parent.
85
+
86
+ And yes, you can have two top projects in the same Buildfile. For example, you can use that to have one project that groups all the application modules (JARs, WARs, etc) and another project that groups all the distribution packages (binary, sources, javadocs).
87
+
88
+ When you start with a new project you won't see the @target@ or @reports@ directories. Buildr creates these when it needs to. Just know that they're there.
89
+
90
+
91
+ h2(#naming). Naming And Finding Projects
92
+
93
+ Each project has a given name, the first argument you pass when calling @define@. The project name is just a string, but we advise to stay clear of colon (@:@) and slashes (@/@ and @\@), which could conflict with other task and file names. Also, avoid using common Buildr task names, don't pick @compile@ or @build@ for your project name.
94
+
95
+ Since each project knows its parent project, child projects and siblings, you can reference them from within the project using just the given name. In other cases, you'll need to use the full name. The full name is just @parent:child@. So if you wanted to refer to _teh-impl_, you could do so with either @project('killer-app:teh-impl')@ or @project('killer-app').project('teh-impl')@.
96
+
97
+ The @project@ method is convenient when you have a dependency from one project to another, e.g. using the other project in the classpath, or accessing one of its source files. Call it with a project name and it will return that object or raise an error. You can also call it with no arguments and it will return the project itself. It's syntactic sugar that's useful when accessing project properties.
98
+
99
+ The @projects@ method takes a list of names and returns a list of projects. If you call it with no arguments on a project, it returns all its sub-projects. If you call it with no argument in any other context, it returns all the projects defined so far.
100
+
101
+ Let's illustrate this with a few examples:
102
+
103
+ {% highlight ruby %}
104
+ puts projects.inspect
105
+ => [project("killer-app"), project("killer-app:teh-api") ... ]
106
+
107
+ puts project('killer-app').projects.inspect
108
+ => [project("killer-app:teh-api"), project("killer-app:teh-impl") ... ]
109
+
110
+ puts project('teh-api')
111
+ => No such project teh-api
112
+
113
+ puts project('killer-app:teh-api').inspect
114
+ => project("killer-app:teh-api")
115
+
116
+ puts project('killer-app').project('teh-api').inspect
117
+ => project("killer-app:teh-api")
118
+ {% endhighlight %}
119
+
120
+ To see a list of all projects defined in your Buildfile run @buildr help:projects@.
121
+
122
+
123
+ h2(#tasks). Running Project Tasks
124
+
125
+ Most times, you run tasks like @build@ or @package@ that operate on the current project and recursively on its sub-projects. The "current project" is the one that uses the current working directory. So if you're in the @la-web/src@ directory looking at source files, _la-web_ is the current project. For example:
126
+
127
+ {% highlight sh %}
128
+ # build killer-app and all its sub-projects
129
+ $ buildr build
130
+
131
+ # switch to and test only teh-impl
132
+ $ cd teh-impl
133
+ $ buildr test
134
+
135
+ # switch to and package only la-web
136
+ $ cd ../la-web
137
+ $ buildr package
138
+ {% endhighlight %}
139
+
140
+ You can use the project's full name to invoke one of its tasks directly, and it doesn't matter which directory you're in. For example:
141
+
142
+ {% highlight sh %}
143
+ # build killer-app and all its sub-projects
144
+ $ buildr killer-app:build
145
+
146
+ # test only teh-impl
147
+ $ buildr killer-app:teh-impl:test
148
+
149
+ # package only la-web
150
+ $ buildr killer-app:la-web:package
151
+ {% endhighlight %}
152
+
153
+ Buildr provides the following tasks that you can run on the current project, or on a specific project by prefixing them with the project's full name:
154
+
155
+ {% highlight text %}
156
+ clean # Clean files generated during a build
157
+ compile # Compile all projects
158
+ build # Build the project
159
+ upload # Upload packages created by the project
160
+ install # Install packages created by the project
161
+ javadoc # Create the Javadocs for this project
162
+ package # Create packages
163
+ test # Run all test cases
164
+ uninstall # Remove previously installed packages
165
+ {% endhighlight %}
166
+
167
+ To see a list of all the tasks provided by Buildr run @buildr help:tasks@.
168
+
169
+
170
+ h2(#properties). Setting Project Properties
171
+
172
+ We mentioned the group identifier, version number and base directory. These are project properties. There are a few more properties we'll cover later on.
173
+
174
+ There are two ways to set project properties. You can pass them as a hash when you call @define@, or use accessors to set them on the project directly. For example:
175
+
176
+ {% highlight ruby %}
177
+ define 'silly', :version=>'1.0' do
178
+ project.group = 'acme'
179
+ end
180
+
181
+ puts project('silly').version
182
+ => 1.0
183
+ puts project('silly').group
184
+ => acme
185
+ {% endhighlight %}
186
+
187
+ Project properties are inherited. You can specify them once in the parent project, and they'll have the same value in all its sub-projects. In the example, we only specify the version number once, for use in all sub-projects.
188
+
189
+
190
+ h2(#paths). Resolving Paths
191
+
192
+ You can run @buildr@ from any directory in your project. To keep tasks consistent and happy, it switches over to the Buildfile directory and executes all the tasks from there, before returning back to your working directory. Your tasks can all rely on relative paths that start from the same directory as the Buildfile.
193
+
194
+ But in practice, you'll want to use the @path_to@ method. This method calculates a path relative to the project, a better way if you ever need to refactor your code, say turn a ad hoc task into a function you reuse.
195
+
196
+ The @path_to@ method takes an array of strings and concatenates them into a path. Absolute paths are returned as they are, relative paths are expanded relative to the project's base directory. Slashes, if you don't already know, work very well on both Windows, Linux and OS X. And as a shortcut, you can use @_@.
197
+
198
+ For example:
199
+
200
+ {% highlight ruby %}
201
+ # Relative to the current project
202
+ path_to('src', 'main', 'java')
203
+
204
+ # Exactly the same thing
205
+ _('src/main/java')
206
+
207
+ # Relative to the teh-impl project
208
+ project('teh-impl')._('src/main/java')
209
+ {% endhighlight %}
210
+
211
+
212
+ h2(#defining). Defining The Project
213
+
214
+ The project definition itself gives you a lot of pre-canned tasks to start with, but that's not enough to build a project. You need to specify what gets built and how, which dependencies to use, the packages you want to create and so forth. You can configure existing tasks, extend them to do additional work, and create new tasks. All that magic happens inside the project definition block.
215
+
216
+ Since the project definition executes each time you run Buildr, you don't want to perform any work directly inside the project definition block. Rather, you want to use it to specify how different build task work when you invoke them. Here's an example to illustrate the point:
217
+
218
+ {% highlight ruby %}
219
+ define 'silly' do
220
+ puts 'Running buildr'
221
+
222
+ build do
223
+ puts 'Building silly'
224
+ end
225
+ end
226
+ {% endhighlight %}
227
+
228
+ Each time you run Buildr, it will execute the project definition and print out "Running buildr". We also extend the @build@ task, and whenever we run it, it will print "Building silly". Incidentally, @build@ is the default task, so if you run Buildr with no arguments, it will print both messages while executing the build. If you run Buildr with a different task, say @clean@, it will only print the first message.
229
+
230
+ The @define@ method gathers the project definition, but does not execute it immediately. It executes the project definition the first time you reference that project, directly or indirectly, for example, by calling @project@ with that project's name, or calling @projects@ to return a list of all projects. Executing a project definition will also execute all its sub-projects' definitions. And, of course, all project definitions are executed once the Buildfile loads, so Buildr can determine how to execute each of the build tasks.
231
+
232
+ If this sounds a bit complex, don't worry. In reality, it does the right thing. A simple rule to remember is that each project definition is executed before you need it, lazy evaluation of sort. The reason we do that? So you can write projects that depend on each other without worrying about their order.
233
+
234
+ In our example, the _la-web_ project depends on packages created by the _teh-api_ and _teh-impl_ projects, the later requiring _teh-api_ to compile. That example is simple enough that we ended up specifying the projects in order of dependency. But you don't always want to do that. For large projects, you may want to group sub-projects by logical units, or sort them alphabetically for easier editing.
235
+
236
+ One project can reference another ahead of its definition. If Buildr detects a cyclic dependency, it will let you know.
237
+
238
+ In this example we define one project in terms of another, using the same dependencies, so we only need to specify them once:
239
+
240
+ {% highlight ruby %}
241
+ define 'bar' do
242
+ compile.with project('foo').compile.dependencies
243
+ end
244
+
245
+ define 'foo' do
246
+ compile.with ..lots of stuff..
247
+ end
248
+ {% endhighlight %}
249
+
250
+ One last thing to remember. Actually three, but they all go hand in hand.
251
+
252
+ *Self is project* Each of these project definition blocks executes in the context of that project, just as if it was a method defined on the project. So when you call the @compile@ method, you're essentially calling that method on the current project: @compile@, @self.compile@ and @project.compile@ are all the same.
253
+
254
+ *Blocks are closures* The project definition is also a closure, which can reference variables from enclosing scopes. You can use that, for example, to define constants, variables and even functions in your Buildfile, and reference them from your project definition. As you'll see later on, in the "Artifacts":artifacts.html section, it will save you a lot of work.
255
+
256
+ *Projects are namespaces* While executing the project definition, Buildr switches the namespace to the project name. If you define the task "do-this" inside the _teh-impl_ project, the actual task name is "killer-app:teh-impl:do-this". Likewise, the @compile@ task is actually "killer-app:teh-impl:compile".
257
+
258
+ From outside the project you can reference a task by its full name, either @task('foo:do')@ or @project('foo').task('do')@. If you need to reference a task defined outside the project from within the project, prefix it with "rake:", for example, @task('rake:globally-defined')@.
259
+
260
+
261
+ h2(#your_own_tasks). Writing Your Own Tasks
262
+
263
+ Of all the features Buildr provide, it doesn't have a task for making coffee. Yet. If you need to write your own tasks, you get all the power of Rake: you can use regular tasks, file tasks, task rules and even write your own custom task classes. Check out the "Rake documentation":http://docs.rubyrake.org/ for more information.
264
+
265
+ We mentioned projects as namespaces before. When you call @task@ on a project, it finds or defines the task using the project namespace. So given a project object, @task('do-this')@ will return it's "do-this" task. If you lookup the source code for the @compile@ method, you'll find that it's little more than a shortcut for @task('compile')@.
266
+
267
+ Another shortcut is the @file@ method. When you call @file@ on a project, Buildr uses the @path_to@ method to expand relative paths using the project's base directory. If you call @file('src')@ on _teh-impl_, it will return you a file task that points at the @teh-impl/src@ directory.
268
+
269
+ In the current implementation projects are also created as tasks, although you don't invoke these tasks directly. That's the reason for not using a project name that conflicts with an existing task name. If you do that, you'll find quick enough, as the task will execute each time you run Buildr.
270
+
271
+ So now that you know everything about projects and tasks, let's go and "build some code":building.html.
@@ -0,0 +1,210 @@
1
+ ---
2
+ layout: default
3
+ title: Quick Start
4
+ ---
5
+
6
+ This quick start guide is meant to be a _very_ simple introduction to Buildr and its most basic concepts. However, despite its basic level, we will still cover most of the concepts you will ever need to be productive with Buildr. We will leave out some important things (like "sub-projects":projects.html), and we will over-simplify some other concepts (such as "artifacts":artifacts.html). Nevertheless, most Buildr projects never need to go beyond the techniques contained within these pages.
7
+
8
+ *No knowledge of Ruby is assumed.* Buildr is designed to be a very intuitive, very easy-to-use tool. You can create buildfiles which describe incredibly intricate projects, write custom tasks which do things far beyond Ant, and still never need to pick up more than a smattering of Ruby syntax. With that said, if you do know Ruby, Buildr's DSL will seem very natural and welcoming. We do assume that you have already "downloaded and installed":installing.html Buildr and are ready to put the tool to good use.
9
+
10
+
11
+ h2(#first-project). Your First Project
12
+
13
+ Much like Maven, Buildr is oriented around projects and tasks. You define your project in a concise, declarative fashion and most common tasks (such as compilation and testing) will be made available to you "at no extra charge". Most of the project definition is contained within the _buildfile_ -- or _Buildfile_, if you're really in love with the Make convention -- a single file sitting at the root of your project. A project definition does not need to be any more complicated than the following:
14
+
15
+ {% highlight ruby %}
16
+ define 'killer-app'
17
+ {% endhighlight %}
18
+
19
+ h3. Compiling
20
+
21
+ Of course, this isn't really giving Buildr much information. What it can't learn from the buildfile, Buildr will figure out by inspecting your directory structure. Java sources are expected to exist within the @src/main/java/@ directory. If Buildr finds these sources, it will automatically configure the compilation to source that directory, depositing the results in the @target/classes/@ directory (all under the project directory of course). We can run this compilation using the following command:
22
+
23
+ {% highlight sh %}
24
+ $ buildr compile
25
+ {% endhighlight %}
26
+
27
+ Information about the classpath and dependencies is described "later on":#dependencies.
28
+
29
+ p(tip). By default, Buildr projects assume the Java language and the @src/main/java/@ source directory. You can also have projects in the Scala or Groovy language (both languages support joint compilation with Java). To use Scala, place your @.scala@ files in the @src/main/scala/@ directory and include the following invocation at the head of your buildfile: @require 'buildr/scala'@ Similarly, Groovy expects sources in the @src/main/groovy/@ directory and necessitates @require 'buildr/groovy'@ (see "languages":languages.html for more information).
30
+
31
+ The @compile@ task will also detect _any_ files which exist under the @src/main/resources/@ directory. These resources are copied verbatim to the @target/resources/@ directory as part of the compilation task. Buildr also performs some basic change detection to minimize compilation. If your source files haven't changed since the last compile, then they will not be recompiled.
32
+
33
+ h3. Packaging
34
+
35
+ At some point, we're going to want to wrap up our classes and produce a single JAR file for distribution. Buildr can certainly help us with this, but we are going to need to provide it with a little bit more information. Specifically, we need to say the type of package to produce (e.g. @:jar@, @:war@, etc) as well as the current version of our project. This information is placed within the buildfile:
36
+
37
+ {% highlight ruby %}
38
+ define 'killer-app' do
39
+ project.version = '0.1.0'
40
+ package :jar
41
+ end
42
+ {% endhighlight %}
43
+
44
+ The @project.version@ attribute can be any value you like. Even non-numeric versions are perfectly acceptable (e.g. @'ikj-0.3.1-E'@). This version -- coupled with the packaging information -- will be used to generate a JAR file: @killer-app-0.1.0.jar@. As would be expected, this file is placed within the @target/@ directory when the following command is run:
45
+
46
+ {% highlight sh %}
47
+ $ buildr package
48
+ {% endhighlight %}
49
+
50
+ The @package@ task depends upon the @compile@ task, so if a rebuild is necessary prior to the creation of the JAR, Buildr will see to it.
51
+
52
+ We can also chain tasks together in a single invocation. For example, we may want to clean all of the old compilation results prior to recompiling and generating a packaged result:
53
+
54
+ {% highlight sh %}
55
+ $ buildr clean package
56
+ {% endhighlight %}
57
+
58
+ The @clean@ task simply removes the @target/@ directory, effectively wiping out any compilation results like class files or resources.
59
+
60
+ h3. Directory Structure
61
+
62
+ As you may have noticed, Buildr does have some default notions about what a project should look like and how it should be organized. We think that these defaults are quite nice and make for a more navigable project. However, we do understand that not all projects are exactly alike. Buildr's "layouts":extending.html#layouts make it possible for any project to easily change these defaults. For example, this would allow you to easily migrate a project that had been based on a different directory structure, such as the @src/@ and @bin/@ convention often used by Ant.
63
+
64
+
65
+ h2(#dependencies). Dependencies
66
+
67
+ So far, we have seen how Buildr can automatically infer what amounts to dozens of lines of @build.xml@ contents, all based on a buildfile and a directory structure. However, the best is yet to come. Buildr also provides Maven-style dependency management (but without the long loading times!). In other words, you specify each dependent library using a string descriptor and Buildr figures out how to download and configure your classpath (the library descriptors are just a Ruby array, therefore they are separated by commas (@,@)). You must specify at least one remote repository so that Buildr knows from where to download these libraries. For example, we can configure our project to reference the "Apache Commons CLI":http://commons.apache.org/cli/ library and download libraries from the Ibiblio repository:
68
+
69
+ {% highlight ruby %}
70
+ repositories.remote << 'http://www.ibiblio.org/maven2'
71
+
72
+ define 'killer-app' do
73
+ project.version = '0.1.0'
74
+ compile.with 'commons-cli:commons-cli:jar:1.2'
75
+ package :jar
76
+ end
77
+ {% endhighlight %}
78
+
79
+ This sort of dependency declaration should look quite familiar if you are at all familiar with Maven. The general format for an artifact descriptor is _groupId:artifactId:packageType:version_. Any Maven artifacts included in this fashion will be retrieved from the "list of remote repositories":artifacts.html#repositories (in this case, Ibiblio) and installed in your local repository at @~/.m2/repository/@.
80
+
81
+ p(tip). You can search the global repository of artifacts at sites like "MvnBrowser":http://www.mvnbrowser.com. Simply enter the name of the library you are looking for, and the search should pull up the groupId, artifactId and a list of available versions.
82
+
83
+ Unfortunately, not all libraries are quite as simple as Commons CLI. Many libraries (such as Apache Wicket) have dependencies of their own. While we may be able to _compile_ against Apache Wicket without these extra libraries on our classpath, we cannot actually _run_ our application without its transitive dependencies. To avoid tracking down each of these dependencies and adding them manually, we can simply use the @transitive@ directive (this is how Maven behaves by default):
84
+
85
+ {% highlight ruby %}
86
+ repositories.remote << 'http://www.ibiblio.org/maven2'
87
+
88
+ define 'killer-app' do
89
+ project.version = '0.1.0'
90
+ compile.with transitive('org.apache.wicket:wicket:jar:1.4-rc6')
91
+ package :jar
92
+ end
93
+ {% endhighlight %}
94
+
95
+ The @compile.with@ property accepts a full array of comma-separated artifacts, making it possible to specify any number of dependencies as necessary. Of course, such a long list of verbose string descriptors could get very tiresome and messy. For this reason, it is conventional to assign each dependency to a constant (e.g. @WICKET@) which is declared just above the project in the buildfile and passed to @compile.with@ in a clean, easy-to-read style:
96
+
97
+ {% highlight ruby %}
98
+ repositories.remote << 'http://www.ibiblio.org/maven2'
99
+
100
+ WICKET = transitive('org.apache.wicket:wicket:jar:1.4-rc6')
101
+ SLF4J = 'org.slf4j:slf4j-jdk14:jar:1.5.8'
102
+
103
+ define 'killer-app' do
104
+ project.version = '0.1.0'
105
+ compile.with WICKET, SLF4J
106
+ package :jar
107
+ end
108
+ {% endhighlight %}
109
+
110
+ Unfortunate as it may seem, not all libraries are available in Maven repositories. While most of the major libraries (e.g. Hibernate, Spring, etc) are kept updated by intrepid volunteers, some of the more obscure frameworks are left out in the cold. An example of one such framework is "DBPool":http://www.snaq.net/java/DBPool, a very fast connection pool designed to integrate with JDBC. However, like most Java libraries, DBPool does provide a zip archive which contains the JAR file, as well as some documentation and perhaps a license or two.
111
+
112
+ Almost magically, we can instruct Buildr to get the DBPool artifact from this URL. Buildr will treat this download just like any other artifact, retrieving it when requried by the @compile@ task. However, unlike a normal Maven artifact, Buildr will do some extra processing once the download is complete. It will actually dig into the downloaded archive, detect and extract the JAR file, installing it into the local repository just like any other artifact:
113
+
114
+ {% highlight ruby %}
115
+ DBPOOL = 'net.snaq:dbpool:jar:4.8.3'
116
+ download artifact(DBPOOL) => 'http://www.snaq.net/java/DBPool/DBPool_v4.8.3.zip'
117
+
118
+ define 'killer-app' do
119
+ project.version '0.1.0'
120
+ compile.with DBPool
121
+ package :jar
122
+ end
123
+ {% endhighlight %}
124
+
125
+ This is one area where Buildr's dependency management vastly excedes Maven's. With Maven, you would have to install the DBPool dependency manually. Buildr's auto-magical download and extraction keeps the dependency definitions centralized within the buildfile, available to your entire team and automatically resolved as needed by the compilation tasks.
126
+
127
+
128
+ h2(#testing). Testing
129
+
130
+ Buildr supports auto-magical integration with a number of mainstream testing frameworks. For Java, this includes the ubiquitus JUnit4, as well as TestNG and a number of others. Scala supports Specs and ScalaTest, while Groovy supports EasyB. Configuration is as simple as placing your test sources in the appropriate directory. In the case of JUnit or TestNG, this would be @src/test/java/@. Once these tests are in place, we can run them using the @test@ task:
131
+
132
+ {% highlight sh %}
133
+ $ buildr test
134
+ {% endhighlight %}
135
+
136
+ When the @test@ task runs, it will ensure that your main sources are compiled, as well as the tests themselves. In the case of JUnit4, test classes are auto-detected based on which base class they extend (@TestCase@). These tests will be invoked using the special test classpath. This classpath includes all of the dependencies passed to @compile.with@ along with the dependencies required for testing. Thus, Buildr will actually go out and download JUnit 4.5 (if necessary) and place that JAR on the classpath in order to run your tests. It is also possible to add artifacts specifically required for testing. So, if your tests make use of the Commons Collections library, but your main sources do not, you can include that dependency only for the tests by using the @test.with@ property. This functions identically to @compile.with@:
137
+
138
+ {% highlight ruby %}
139
+ define 'killer-app' do
140
+ project.version = '0.1.0'
141
+ compile.with 'commons-cli:commons-cli:jar:1.2'
142
+ test.with 'commons-collections:commons-collections:jar:3.2'
143
+ package :jar
144
+ end
145
+ {% endhighlight %}
146
+
147
+ Of course, not everyone _likes_ JUnit4. As mentioned previously, Buildr supports a number of test frameworks. It is possible to use TestNG instead of JUnit4 by setting the @test.using@ property to @:testng@:
148
+
149
+ {% highlight ruby %}
150
+ define 'killer-app' do
151
+ project.version = '0.1.0'
152
+ compile.with 'commons-cli:commons-cli:jar:1.2'
153
+ test.with 'commons-collections:commons-collections:jar:3.2'
154
+ test.using :testng
155
+ package :jar
156
+ end
157
+ {% endhighlight %}
158
+
159
+ Note that only one test framework per-project may be used. This may seem like an obvious restriction given that both frameworks introduced so far have used the same directory, but other frameworks such as Specs and EasyB do not follow the same convention. In cases of ambiguity (for example, when tests are present in both @src/test/java/@ _and_ @src/spec/scala/@), only one test framework will be chosen, but this choice is not well-defined. When in doubt, explicitly specify the test framework with the @test.using@ property. This overrides Buildr's auto-detection and ensures sane behavior.
160
+
161
+ Other test frameworks are documented "here":testing.html and "here":languages.html.
162
+
163
+
164
+ h2(#custom-tasks). Custom Tasks
165
+
166
+ If there is one area in which Buildr excels, it is defining custom tasks. This is something which is notoriously difficult in both Ant and Maven, often requiring separate Java plugins and mountains of code simply to perform basic tasks. For example, let's imagine that we wanted to define a @run@ task which would compile and run our "killer-app" project. This is a simple matter of invoking the @java@ command against our main class:
167
+
168
+ {% highlight ruby %}
169
+ define 'killer-app' do
170
+ project.version = '0.1.0'
171
+ package :jar
172
+
173
+ task :run => :compile do
174
+ system 'java -cp target/classes org.apache.killer.Main'
175
+ end
176
+ end
177
+ {% endhighlight %}
178
+
179
+ This code defines a new task, @run@, which depends upon the @compile@ task. This task only performs a single operation: it invokes the @system@ method, passing the relevant command as a string. Note that the @system@ method documentation may be found "here":http://www.ruby-doc.org/core/classes/Kernel.html#M005971. Tasks use real Ruby (actually, the entire buildfile is real Ruby too), so if you are familiar with that language, then you should be right at home writing custom tasks in Buildr. We can invoke this task in the following way:
180
+
181
+ {% highlight sh %}
182
+ $ buildr killer-app:run
183
+ {% endhighlight %}
184
+
185
+ This works, but it's clumsy. The reason we had to give the "@killer-app:@" prefix is because we defined the @run@ task _within_ our project, rather than outside of the @define@ block. However, if we define @run@ outside of the project, then we don't really have access to the @compile@ task (which is project-specific). The solution here is a bit of magic known as @local_task@. This is how tasks like @compile@ and @test@, which are technically project-specific (think: instance methods) can be invoked without the fully-qualified project name:
186
+
187
+ {% highlight ruby %}
188
+ local_task :run
189
+
190
+ define 'killer-app' do
191
+ project.version '0.1.0'
192
+
193
+ package :jar
194
+
195
+ task :run => :compile do
196
+ system 'java -cp target/classes org.apache.killer.Main'
197
+ end
198
+ end
199
+ {% endhighlight %}
200
+
201
+ Now, we can invoke @run@ exactly the way we want, with a minimum of wasted characters:
202
+
203
+ {% highlight sh %}
204
+ $ buildr run
205
+ {% endhighlight %}
206
+
207
+
208
+ h2(#summary). Summary
209
+
210
+ As long as this guide was, we have barely even scratched the surface of Buildr's true power. This was meant only to get you up and running as quickly as possible, exploiting some of Buildr's unique features to ease your build process. For more comprehensive documentation, start reading about "projects in Buildr":projects.html and work your way from there.